Projects
Browse Source     Search     Timeline     Wiki

Changeset 23459

Show
Ignore:
Timestamp:
2007-12-07 13:15:23 (10 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5502233> SULeoCeto: ReportCrash can deadlock against itself if it crashes prior to main()

Location:
branches/SULeopard/launchd/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/SULeopard/launchd/src/Makefile.am

    r23408 r23459  
    33CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h                \ 
    44             launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c        \ 
    5              notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c 
     5             notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h 
    66 
    77protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h: $(srcdir)/protocol_job.defs 
     
    4949launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter 
    5050launchd_LDFLAGS = -lbsm 
    51 launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c 
     51launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c mach_excServer.c 
    5252 
    53 launchd_runtime.c:: notifyServer.h launchd_internal.h 
     53launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h 
    5454launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h 
    5555 
     
    5858notifyServer.c notifyServer.h: /usr/include/mach/notify.defs 
    5959        mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs 
     60 
     61mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs 
     62        mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs 
    6063 
    6164job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs 
  • branches/SULeopard/launchd/src/Makefile.in

    r23408 r23459  
    9797        launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c \ 
    9898        launchd_internalUser.c launchd_internalServer.c \ 
    99         job_replyUser.c launchd_runtime.c launchd_runtime_kill.c 
     99        job_replyUser.c launchd_runtime.c launchd_runtime_kill.c \ 
     100        mach_excServer.c 
    100101@LIBS_ONLY_FALSE@am_launchd_OBJECTS = launchd-launchd.$(OBJEXT) \ 
    101102@LIBS_ONLY_FALSE@       launchd-launchd_core_logic.$(OBJEXT) \ 
     
    107108@LIBS_ONLY_FALSE@       launchd-job_replyUser.$(OBJEXT) \ 
    108109@LIBS_ONLY_FALSE@       launchd-launchd_runtime.$(OBJEXT) \ 
    109 @LIBS_ONLY_FALSE@       launchd-launchd_runtime_kill.$(OBJEXT) 
     110@LIBS_ONLY_FALSE@       launchd-launchd_runtime_kill.$(OBJEXT) \ 
     111@LIBS_ONLY_FALSE@       launchd-mach_excServer.$(OBJEXT) 
    110112launchd_OBJECTS = $(am_launchd_OBJECTS) 
    111113launchd_LDADD = $(LDADD) 
     
    239241CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h                \ 
    240242             launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c        \ 
    241              notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c 
     243             notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h 
    242244 
    243245@LIBS_ONLY_TRUE@noinst_LIBRARIES = liblaunch.a liblaunch_profile.a 
     
    254256@LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter 
    255257@LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm 
    256 @LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c 
     258@LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c mach_excServer.c 
    257259@LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security 
    258260@LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 
     
    424426@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime_kill.Po@am__quote@ 
    425427@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_unix_ipc.Po@am__quote@ 
     428@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-mach_excServer.Po@am__quote@ 
    426429@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-notifyServer.Po@am__quote@ 
    427430@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-protocol_vprocServer.Po@am__quote@ 
     
    788791@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
    789792@am__fastdepCC_FALSE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-launchd_runtime_kill.obj `if test -f 'launchd_runtime_kill.c'; then $(CYGPATH_W) 'launchd_runtime_kill.c'; else $(CYGPATH_W) '$(srcdir)/launchd_runtime_kill.c'; fi` 
     793 
     794launchd-mach_excServer.o: mach_excServer.c 
     795@am__fastdepCC_TRUE@    $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.o -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c 
     796@am__fastdepCC_TRUE@    mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po 
     797@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='mach_excServer.c' object='launchd-mach_excServer.o' libtool=no @AMDEPBACKSLASH@ 
     798@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
     799@am__fastdepCC_FALSE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c 
     800 
     801launchd-mach_excServer.obj: mach_excServer.c 
     802@am__fastdepCC_TRUE@    $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.obj -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` 
     803@am__fastdepCC_TRUE@    mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po 
     804@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='mach_excServer.c' object='launchd-mach_excServer.obj' libtool=no @AMDEPBACKSLASH@ 
     805@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
     806@am__fastdepCC_FALSE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` 
    790807install-man1: $(man1_MANS) $(man_MANS) 
    791808        @$(NORMAL_INSTALL) 
     
    11491166@LIBS_ONLY_TRUE@        cp liblaunch_profile.a $(DESTDIR)/usr/local/lib/system/liblaunch_profile.a 
    11501167 
    1151 @LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h 
     1168@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h 
    11521169@LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h 
    11531170 
    11541171@LIBS_ONLY_FALSE@notifyServer.c notifyServer.h: /usr/include/mach/notify.defs 
    11551172@LIBS_ONLY_FALSE@       mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs 
     1173 
     1174@LIBS_ONLY_FALSE@mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs 
     1175@LIBS_ONLY_FALSE@       mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs 
    11561176 
    11571177@LIBS_ONLY_FALSE@job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs 
  • branches/SULeopard/launchd/src/launchd_core_logic.c

    r23437 r23459  
    334334        char *stdoutpath; 
    335335        char *stderrpath; 
     336        char *alt_exc_handler; 
    336337        struct machservice *lastlookup; 
    337338        unsigned int lastlookup_gennum; 
     
    361362                     wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, 
    362363                     per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, 
    363                      poll_for_vfs_changes:1; 
     364                     poll_for_vfs_changes:1, internal_exc_handler:1; 
    364365        const char label[0]; 
    365366}; 
     
    862863                free(j->stderrpath); 
    863864        } 
     865        if (j->alt_exc_handler) { 
     866                free(j->alt_exc_handler); 
     867        } 
    864868        if (j->seatbelt_profile) { 
    865869                free(j->seatbelt_profile); 
     
    13241328                } 
    13251329                break; 
     1330        case 'm': 
     1331        case 'M': 
     1332                if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { 
     1333                        j->internal_exc_handler = value; 
     1334                        found_key = true; 
     1335                } 
     1336                break; 
    13261337        case 'i': 
    13271338        case 'I': 
     
    13771388 
    13781389        switch (key[0]) { 
     1390        case 'm': 
     1391        case 'M': 
     1392                if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { 
     1393                        where2put = &j->alt_exc_handler; 
     1394                } 
     1395                break; 
    13791396        case 'p': 
    13801397        case 'P': 
     
    40034020job_setup_exception_port(job_t j, task_t target_task) 
    40044021{ 
     4022        struct machservice *ms; 
    40054023        thread_state_flavor_t f = 0; 
    4006  
    4007         if (!the_exception_server) { 
     4024        mach_port_t exc_port = the_exception_server; 
     4025 
     4026        if (j->alt_exc_handler) { 
     4027                ms = jobmgr_lookup_service(j->mgr, j->alt_exc_handler, true, 0); 
     4028                if (ms) { 
     4029                        exc_port = machservice_port(ms); 
     4030                } else { 
     4031                        job_log(j, LOG_WARNING, "Falling back to default Mach exception handler. Could not find: %s", j->alt_exc_handler); 
     4032                } 
     4033        } else if (j->internal_exc_handler) { 
     4034                exc_port = runtime_get_kernel_port(); 
     4035        } else if (!exc_port) { 
    40084036                return; 
    40094037        } 
     
    40164044 
    40174045        if (target_task) { 
    4018                 job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, the_exception_server, 
     4046                job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, exc_port, 
    40194047                                        EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); 
    4020         } else if (getpid() == 1) { 
     4048        } else if (getpid() == 1 && the_exception_server) { 
    40214049                mach_port_t mhp = mach_host_self(); 
    40224050                job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, 
  • branches/SULeopard/launchd/src/launchd_runtime.c

    r23456 r23459  
    6262#include "launchd_internal.h" 
    6363#include "notifyServer.h" 
     64#include "mach_excServer.h" 
    6465 
    6566/* We shouldn't be including these */ 
     
    8788static void log_kevent_struct(int level, struct kevent *kev, int indx); 
    8889 
     90static boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); 
    8991static void record_caller_creds(mach_msg_header_t *mh); 
    9092static void launchd_runtime2(mach_msg_size_t msg_size, mig_reply_error_t *bufRequest, mig_reply_error_t *bufReply); 
     
    115117}; 
    116118static sigset_t sigign_set; 
     119 
     120mach_port_t 
     121runtime_get_kernel_port(void) 
     122{ 
     123        return launchd_internal_port; 
     124} 
    117125 
    118126void 
     
    847855        if (launchd_internal_server_routine(Request)) { 
    848856                return launchd_internal_server(Request, Reply); 
    849         } 
    850  
    851         return notify_server(Request, Reply); 
     857        } else if (notify_server_routine(Request)) { 
     858                return notify_server(Request, Reply); 
     859        } else { 
     860                return mach_exc_server(Request, Reply); 
     861        } 
    852862} 
    853863 
     
    14511461        runtime_busy_cnt--; 
    14521462} 
     1463 
     1464kern_return_t 
     1465catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, 
     1466                exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt) 
     1467{ 
     1468        runtime_syslog(LOG_NOTICE, "%s(): thread: 0x%x task: 0x%x type: 0x%x code: %p codeCnt: 0x%x", 
     1469                        __func__, thread, task, exception, code, codeCnt); 
     1470 
     1471        launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); 
     1472        launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); 
     1473 
     1474        return 0; 
     1475} 
     1476 
     1477kern_return_t 
     1478catch_mach_exception_raise_state(mach_port_t exception_port, 
     1479                exception_type_t exception, const mach_exception_data_t code, mach_msg_type_number_t codeCnt, 
     1480                int *flavor, const thread_state_t old_state, mach_msg_type_number_t old_stateCnt, 
     1481                thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) 
     1482{ 
     1483        runtime_syslog(LOG_NOTICE, "%s(): type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", 
     1484                        __func__, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); 
     1485 
     1486        memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); 
     1487        *new_stateCnt = old_stateCnt; 
     1488 
     1489        return 0; 
     1490} 
     1491 
     1492kern_return_t 
     1493catch_mach_exception_raise_state_identity(mach_port_t exception_port, mach_port_t thread, mach_port_t task, 
     1494                exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt, 
     1495                int *flavor, thread_state_t old_state, mach_msg_type_number_t old_stateCnt, 
     1496                thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) 
     1497{ 
     1498        runtime_syslog(LOG_NOTICE, "%s(): thread: 0x%x task: 0x%x type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", 
     1499                        __func__, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); 
     1500 
     1501        memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); 
     1502        *new_stateCnt = old_stateCnt; 
     1503 
     1504        launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); 
     1505        launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); 
     1506 
     1507        return 0; 
     1508} 
  • branches/SULeopard/launchd/src/launchd_runtime.h

    r23432 r23459  
    5757typedef void (*timeout_callback)(void); 
    5858 
    59 boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); 
     59mach_port_t runtime_get_kernel_port(void); 
    6060 
    6161void runtime_add_ref(void); 
  • branches/SULeopard/launchd/src/liblaunch_private.h

    r23266 r23459  
    5656#define LAUNCH_JOBKEY_SERVICEIPC                "ServiceIPC" 
    5757#define LAUNCH_JOBKEY_BINARYORDERPREFERENCE     "BinaryOrderPreference" 
     58#define LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER      "MachExceptionHandler" 
    5859 
    5960#define LAUNCH_JOBKEY_MACH_KUNCSERVER   "kUNCServer"