Projects
Browse Source     Search     Timeline     Wiki

Changeset 23445

Show
Ignore:
Timestamp:
10/23/07 08:47:01 (14 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5510464> ER: Provide a way for launchd to NULL out a tasks exception report when launched

Location:
trunk/launchd/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/launchd/src/Makefile.am

    r23443 r23445  
    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 job_forwardUser.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 job_forwardUser.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 job_forward.h 
    5555 
     
    6161notifyServer.c notifyServer.h: /usr/include/mach/notify.defs 
    6262        mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs 
     63 
     64mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs 
     65        mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs 
    6366 
    6467job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs 
  • trunk/launchd/src/Makefile.in

    r23443 r23445  
    9898        launchd_internalUser.c launchd_internalServer.c \ 
    9999        job_replyUser.c launchd_runtime.c launchd_runtime_kill.c \ 
    100         job_forwardUser.c 
     100        job_forwardUser.c mach_excServer.c 
    101101@LIBS_ONLY_FALSE@am_launchd_OBJECTS = launchd-launchd.$(OBJEXT) \ 
    102102@LIBS_ONLY_FALSE@       launchd-launchd_core_logic.$(OBJEXT) \ 
     
    109109@LIBS_ONLY_FALSE@       launchd-launchd_runtime.$(OBJEXT) \ 
    110110@LIBS_ONLY_FALSE@       launchd-launchd_runtime_kill.$(OBJEXT) \ 
    111 @LIBS_ONLY_FALSE@       launchd-job_forwardUser.$(OBJEXT) 
     111@LIBS_ONLY_FALSE@       launchd-job_forwardUser.$(OBJEXT) \ 
     112@LIBS_ONLY_FALSE@       launchd-mach_excServer.$(OBJEXT) 
    112113launchd_OBJECTS = $(am_launchd_OBJECTS) 
    113114launchd_LDADD = $(LDADD) 
     
    241242CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h                \ 
    242243             launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c        \ 
    243              notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c 
     244             notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h 
    244245 
    245246@LIBS_ONLY_TRUE@noinst_LIBRARIES = liblaunch.a liblaunch_profile.a 
     
    256257@LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter 
    257258@LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm 
    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 job_forwardUser.c 
     259@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 job_forwardUser.c mach_excServer.c 
    259260@LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security 
    260261@LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 
     
    427428@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime_kill.Po@am__quote@ 
    428429@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_unix_ipc.Po@am__quote@ 
     430@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-mach_excServer.Po@am__quote@ 
    429431@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-notifyServer.Po@am__quote@ 
    430432@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-protocol_vprocServer.Po@am__quote@ 
     
    805807@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
    806808@am__fastdepCC_FALSE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-job_forwardUser.obj `if test -f 'job_forwardUser.c'; then $(CYGPATH_W) 'job_forwardUser.c'; else $(CYGPATH_W) '$(srcdir)/job_forwardUser.c'; fi` 
     809 
     810launchd-mach_excServer.o: mach_excServer.c 
     811@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 
     812@am__fastdepCC_TRUE@    mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po 
     813@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='mach_excServer.c' object='launchd-mach_excServer.o' libtool=no @AMDEPBACKSLASH@ 
     814@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
     815@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 
     816 
     817launchd-mach_excServer.obj: mach_excServer.c 
     818@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` 
     819@am__fastdepCC_TRUE@    mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po 
     820@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='mach_excServer.c' object='launchd-mach_excServer.obj' libtool=no @AMDEPBACKSLASH@ 
     821@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 
     822@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` 
    807823install-man1: $(man1_MANS) $(man_MANS) 
    808824        @$(NORMAL_INSTALL) 
     
    11661182@LIBS_ONLY_TRUE@        cp liblaunch_profile.a $(DESTDIR)/usr/local/lib/system/liblaunch_profile.a 
    11671183 
    1168 @LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h 
     1184@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h 
    11691185@LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h job_forward.h 
    11701186 
     
    11741190@LIBS_ONLY_FALSE@notifyServer.c notifyServer.h: /usr/include/mach/notify.defs 
    11751191@LIBS_ONLY_FALSE@       mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs 
     1192 
     1193@LIBS_ONLY_FALSE@mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs 
     1194@LIBS_ONLY_FALSE@       mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs 
    11761195 
    11771196@LIBS_ONLY_FALSE@job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs 
  • trunk/launchd/src/launchd_core_logic.c

    r23443 r23445  
    335335        char *stdoutpath; 
    336336        char *stderrpath; 
     337        char *alt_exc_handler; 
    337338        struct machservice *lastlookup; 
    338339        unsigned int lastlookup_gennum; 
     
    362363                     wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, 
    363364                     per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, 
    364                      poll_for_vfs_changes:1; 
     365                     poll_for_vfs_changes:1, internal_exc_handler:1; 
    365366        const char label[0]; 
    366367}; 
     
    863864                free(j->stderrpath); 
    864865        } 
     866        if (j->alt_exc_handler) { 
     867                free(j->alt_exc_handler); 
     868        } 
    865869        if (j->seatbelt_profile) { 
    866870                free(j->seatbelt_profile); 
     
    13251329                } 
    13261330                break; 
     1331        case 'm': 
     1332        case 'M': 
     1333                if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { 
     1334                        j->internal_exc_handler = value; 
     1335                        found_key = true; 
     1336                } 
     1337                break; 
    13271338        case 'i': 
    13281339        case 'I': 
     
    13781389 
    13791390        switch (key[0]) { 
     1391        case 'm': 
     1392        case 'M': 
     1393                if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { 
     1394                        where2put = &j->alt_exc_handler; 
     1395                } 
     1396                break; 
    13801397        case 'p': 
    13811398        case 'P': 
     
    40044021job_setup_exception_port(job_t j, task_t target_task) 
    40054022{ 
     4023        struct machservice *ms; 
    40064024        thread_state_flavor_t f = 0; 
    4007  
    4008         if (!the_exception_server) { 
     4025        mach_port_t exc_port = the_exception_server; 
     4026 
     4027        if (j->alt_exc_handler) { 
     4028                ms = jobmgr_lookup_service(j->mgr, j->alt_exc_handler, true, 0); 
     4029                if (ms) { 
     4030                        exc_port = machservice_port(ms); 
     4031                } else { 
     4032                        job_log(j, LOG_WARNING, "Falling back to default Mach exception handler. Could not find: %s", j->alt_exc_handler); 
     4033                } 
     4034        } else if (j->internal_exc_handler) { 
     4035                exc_port = runtime_get_kernel_port(); 
     4036        } else if (!exc_port) { 
    40094037                return; 
    40104038        } 
     
    40174045 
    40184046        if (target_task) { 
    4019                 job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, the_exception_server, 
     4047                job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, exc_port, 
    40204048                                        EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); 
    4021         } else if (getpid() == 1) { 
     4049        } else if (getpid() == 1 && the_exception_server) { 
    40224050                mach_port_t mhp = mach_host_self(); 
    40234051                job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, 
  • trunk/launchd/src/launchd_runtime.c

    r23444 r23445  
    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 
    118126static int internal_mask_pri = LOG_UPTO(LOG_NOTICE); 
     
    851859        if (launchd_internal_server_routine(Request)) { 
    852860                return launchd_internal_server(Request, Reply); 
    853         } 
    854  
    855         return notify_server(Request, Reply); 
     861        } else if (notify_server_routine(Request)) { 
     862                return notify_server(Request, Reply); 
     863        } else { 
     864                return mach_exc_server(Request, Reply); 
     865        } 
    856866} 
    857867 
     
    14521462        runtime_busy_cnt--; 
    14531463} 
     1464 
     1465kern_return_t 
     1466catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, 
     1467                exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt) 
     1468{ 
     1469        pid_t p4t = -1; 
     1470 
     1471        launchd_assumes(pid_for_task(task, &p4t) == 0); 
     1472 
     1473        runtime_syslog(LOG_NOTICE, "%s(): PID: %u thread: 0x%x type: 0x%x code: %p codeCnt: 0x%x", 
     1474                        __func__, p4t, thread, exception, code, codeCnt); 
     1475 
     1476        launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); 
     1477        launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); 
     1478 
     1479        return 0; 
     1480} 
     1481 
     1482kern_return_t 
     1483catch_mach_exception_raise_state(mach_port_t exception_port, 
     1484                exception_type_t exception, const mach_exception_data_t code, mach_msg_type_number_t codeCnt, 
     1485                int *flavor, const thread_state_t old_state, mach_msg_type_number_t old_stateCnt, 
     1486                thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) 
     1487{ 
     1488        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", 
     1489                        __func__, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); 
     1490 
     1491        memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); 
     1492        *new_stateCnt = old_stateCnt; 
     1493 
     1494        return 0; 
     1495} 
     1496 
     1497kern_return_t 
     1498catch_mach_exception_raise_state_identity(mach_port_t exception_port, mach_port_t thread, mach_port_t task, 
     1499                exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt, 
     1500                int *flavor, thread_state_t old_state, mach_msg_type_number_t old_stateCnt, 
     1501                thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) 
     1502{ 
     1503        pid_t p4t = -1; 
     1504 
     1505        launchd_assumes(pid_for_task(task, &p4t) == 0); 
     1506 
     1507        runtime_syslog(LOG_NOTICE, "%s(): PID: %u thread: 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", 
     1508                        __func__, p4t, thread, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); 
     1509 
     1510        memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); 
     1511        *new_stateCnt = old_stateCnt; 
     1512 
     1513        launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); 
     1514        launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); 
     1515 
     1516        return 0; 
     1517} 
  • trunk/launchd/src/launchd_runtime.h

    r23444 r23445  
    9999typedef void (*timeout_callback)(void); 
    100100 
    101 boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); 
     101mach_port_t runtime_get_kernel_port(void); 
    102102 
    103103void runtime_add_ref(void); 
  • trunk/launchd/src/liblaunch_private.h

    r23266 r23445  
    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"