Changeset 23580
- Timestamp:
- 2008-03-28 12:47:54 (6 months ago)
- Location:
- trunk/launchd/src
- Files:
-
- 7 modified
-
launchd.c (modified) (2 diffs)
-
launchd_core_logic.c (modified) (18 diffs)
-
launchd_runtime.c (modified) (8 diffs)
-
launchd_runtime.h (modified) (1 diff)
-
libvproc.c (modified) (10 diffs)
-
libvproc_internal.h (modified) (1 diff)
-
libvproc_private.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchd.c
r23553 r23580 71 71 #include "libbootstrap_public.h" 72 72 #include "libvproc_public.h" 73 #include "libvproc_private.h" 73 74 #include "libvproc_internal.h" 74 75 #include "liblaunch_public.h" … … 159 160 if (pid1_magic) { 160 161 handle_pid1_crashes_separately(); 162 } else { 163 /* prime shared memory before the 'bootstrap_port' global is set to zero */ 164 _vproc_transaction_begin(); 165 _vproc_transaction_end(); 161 166 } 162 167 -
trunk/launchd/src/launchd_core_logic.c
r23577 r23580 564 564 job_stop(job_t j) 565 565 { 566 char extralog[100]; 566 567 int32_t newval = 1; 567 568 … … 596 597 } 597 598 598 job_log(j, LOG_DEBUG, "Sent SIGTERM signal"); 599 if (j->kill_via_shmem) { 600 snprintf(extralog, sizeof(extralog), ": %d remaining transactions", j->shmem->vp_shmem_transaction_cnt + 1); 601 } else { 602 extralog[0] = '\0'; 603 } 604 605 job_log(j, LOG_DEBUG, "Sent SIGTERM signal%s", extralog); 599 606 } 600 607 } … … 804 811 805 812 if (jm->parentmgr) { 806 runtime_del_ ref();813 runtime_del_weak_ref(); 807 814 SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); 808 815 } else if (pid1_magic) { … … 960 967 } 961 968 if (j->start_interval) { 962 runtime_del_ ref();969 runtime_del_weak_ref(); 963 970 job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); 964 971 } … … 1665 1672 job_log(j, LOG_WARNING, "%s is too large. Ignoring.", LAUNCH_JOBKEY_STARTINTERVAL); 1666 1673 } else { 1667 runtime_add_ ref();1674 runtime_add_weak_ref(); 1668 1675 j->start_interval = value; 1669 1676 … … 2231 2238 2232 2239 if (j->shmem) { 2233 job_assumes(j, munmap(j->shmem, getpagesize()) == 0);2240 job_assumes(j, vm_deallocate(mach_task_self(), (vm_address_t)j->shmem, getpagesize()) == 0); 2234 2241 j->shmem = NULL; 2235 2242 } … … 3792 3799 calendarinterval_setalarm(j, ci); 3793 3800 3794 runtime_add_ ref();3801 runtime_add_weak_ref(); 3795 3802 3796 3803 return true; … … 3805 3812 free(ci); 3806 3813 3807 runtime_del_ ref();3814 runtime_del_weak_ref(); 3808 3815 } 3809 3816 … … 3863 3870 SLIST_INSERT_HEAD(&j->sockets, sg, sle); 3864 3871 3865 runtime_add_ ref();3872 runtime_add_weak_ref(); 3866 3873 3867 3874 return true; … … 3894 3901 free(sg); 3895 3902 3896 runtime_del_ ref();3903 runtime_del_weak_ref(); 3897 3904 } 3898 3905 … … 4730 4737 4731 4738 if (jmr->parentmgr) { 4732 runtime_add_ ref();4739 runtime_add_weak_ref(); 4733 4740 } 4734 4741 … … 5170 5177 5171 5178 if (add) { 5172 runtime_add_ ref();5179 runtime_add_weak_ref(); 5173 5180 } else { 5174 runtime_del_ ref();5181 runtime_del_weak_ref(); 5175 5182 } 5176 5183 } … … 5438 5445 { 5439 5446 memory_object_size_t size_of_page, size_of_page_orig; 5447 vm_address_t vm_addr; 5440 5448 kern_return_t kr; 5441 5449 … … 5445 5453 5446 5454 if (unlikely(j->anonymous)) { 5455 job_log(j, LOG_ERR, "Anonymous job tried to setup shared memory"); 5447 5456 return BOOTSTRAP_NOT_PRIVILEGED; 5448 5457 } … … 5455 5464 size_of_page_orig = size_of_page = getpagesize(); 5456 5465 5457 if (!job_assumes(j, j->shmem = mmap(NULL, size_of_page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0))) { 5458 return BOOTSTRAP_NO_MEMORY; 5459 } 5466 kr = vm_allocate(mach_task_self(), &vm_addr, size_of_page, true); 5467 5468 if (!job_assumes(j, kr == 0)) { 5469 return kr; 5470 } 5471 5472 j->shmem = (typeof(j->shmem))vm_addr; 5473 j->shmem->vp_shmem_standby_timeout = j->timeout; 5460 5474 5461 5475 kr = mach_make_memory_entry_64(mach_task_self(), &size_of_page, 5462 (memory_object_offset_t) ((long)j->shmem), VM_PROT_DEFAULT, shmem_port, 0);5476 (memory_object_offset_t)vm_addr, VM_PROT_READ|VM_PROT_WRITE, shmem_port, 0); 5463 5477 5464 5478 if (job_assumes(j, kr == 0)) { 5465 5479 job_assumes(j, size_of_page == size_of_page_orig); 5466 5480 } 5481 5482 /* no need to inherit this in child processes */ 5483 job_assumes(j, vm_inherit(mach_task_self(), (vm_address_t)j->shmem, size_of_page_orig, VM_INHERIT_NONE) == 0); 5467 5484 5468 5485 return kr; … … 5777 5794 } else if (inval) { 5778 5795 if (j->start_interval == 0) { 5779 runtime_add_ ref();5796 runtime_add_weak_ref(); 5780 5797 } else { 5781 5798 /* Workaround 5225889 */ … … 5787 5804 job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); 5788 5805 if (j->start_interval != 0) { 5789 runtime_del_ ref();5806 runtime_del_weak_ref(); 5790 5807 } 5791 5808 j->start_interval = 0; … … 6015 6032 ji->mach_uid = which_user; 6016 6033 ji->per_user = true; 6034 ji->kill_via_shmem = true; 6017 6035 6018 6036 if ((ms = machservice_new(ji, lbuf, up_cont, false)) == NULL) { -
trunk/launchd/src/launchd_runtime.c
r23563 r23580 70 70 #include "launchd.h" 71 71 #include "launchd_core_logic.h" 72 #include "libvproc_public.h" 73 #include "libvproc_private.h" 72 74 #include "libvproc_internal.h" 73 75 #include "job_reply.h" … … 100 102 static struct ldcred ldc; 101 103 static size_t runtime_busy_cnt; 104 static size_t runtime_standby_cnt; 102 105 103 106 … … 990 993 mach_msg_timeout_t to; 991 994 mach_msg_return_t mr; 995 size_t busy_cnt; 992 996 993 997 options = MACH_RCV_MSG|MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT) | … … 997 1001 998 1002 for (;;) { 1003 busy_cnt = runtime_busy_cnt + runtime_standby_cnt; 999 1004 to = MACH_MSG_TIMEOUT_NONE; 1000 1005 … … 1008 1013 } 1009 1014 1010 if ((tmp_options & MACH_RCV_MSG) && (runtime_idle_callback || ( runtime_busy_cnt == 0))) {1015 if ((tmp_options & MACH_RCV_MSG) && (runtime_idle_callback || (busy_cnt == 0))) { 1011 1016 tmp_options |= MACH_RCV_TIMEOUT; 1012 1017 1013 1018 if (!(tmp_options & MACH_SEND_TIMEOUT)) { 1014 to = runtime_busy_cnt ? runtime_idle_timeout : (RUNTIME_ADVISABLE_IDLE_TIMEOUT* 1000);1019 to = busy_cnt ? runtime_idle_timeout : (_vproc_standby_timeout() * 1000); 1015 1020 } 1016 1021 } … … 1034 1039 case MACH_RCV_TIMED_OUT: 1035 1040 if (to != MACH_MSG_TIMEOUT_NONE) { 1036 if ( runtime_busy_cnt == 0) {1041 if (busy_cnt == 0) { 1037 1042 launchd_shutdown(); 1038 1043 } else if (runtime_idle_callback) { … … 1478 1483 runtime_add_ref(void) 1479 1484 { 1485 if (!pid1_magic) { 1486 _vproc_transaction_begin(); 1487 } 1480 1488 runtime_busy_cnt++; 1481 1489 } … … 1484 1492 runtime_del_ref(void) 1485 1493 { 1494 if (!pid1_magic) { 1495 _vproc_transaction_end(); 1496 } 1486 1497 runtime_busy_cnt--; 1498 } 1499 1500 INTERNAL_ABI void 1501 runtime_add_weak_ref(void) 1502 { 1503 if (!pid1_magic) { 1504 _vproc_standby_begin(); 1505 } 1506 runtime_standby_cnt++; 1507 } 1508 1509 INTERNAL_ABI void 1510 runtime_del_weak_ref(void) 1511 { 1512 if (!pid1_magic) { 1513 _vproc_standby_end(); 1514 } 1515 runtime_standby_cnt--; 1487 1516 } 1488 1517 -
trunk/launchd/src/launchd_runtime.h
r23542 r23580 112 112 INTERNAL_ABI void runtime_add_ref(void); 113 113 INTERNAL_ABI void runtime_del_ref(void); 114 INTERNAL_ABI void runtime_add_weak_ref(void); 115 INTERNAL_ABI void runtime_del_weak_ref(void); 114 116 115 117 INTERNAL_ABI void launchd_runtime_init(void); -
trunk/launchd/src/libvproc.c
r23578 r23580 34 34 #include <pthread.h> 35 35 #include <signal.h> 36 #include <assert.h> 36 37 #if HAVE_QUARANTINE 37 38 #include <quarantine.h> … … 66 67 kr = vproc_mig_setup_shmem(bootstrap_port, &shmem_port); 67 68 68 if (unlikely(kr)) { 69 abort(); 70 } 71 72 kr = vm_map_64(mach_task_self(), &vm_addr, getpagesize(), 0, true, shmem_port, 0, false, 69 assert(kr == 0); 70 71 kr = vm_map(mach_task_self(), &vm_addr, getpagesize(), 0, true, shmem_port, 0, false, 73 72 VM_PROT_READ|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE, VM_INHERIT_NONE); 74 73 75 if (unlikely(kr)) { 76 abort(); 77 } 74 assert(kr == 0); 78 75 79 76 vproc_shmem = (struct vproc_shmem_s *)vm_addr; … … 85 82 vproc_transaction_t vpt = (vproc_transaction_t)vproc_shmem_init; /* we need a "random" variable that is testable */ 86 83 87 _ basic_vproc_transaction_begin();84 _vproc_transaction_begin(); 88 85 89 86 return vpt; … … 91 88 92 89 void 93 _ basic_vproc_transaction_begin(void)90 _vproc_transaction_begin(void) 94 91 { 95 92 typeof(vproc_shmem->vp_shmem_transaction_cnt) newval; … … 116 113 117 114 size_t 118 _ basic_vproc_transaction_count(void)115 _vproc_transaction_count(void) 119 116 { 120 117 return likely(vproc_shmem) ? vproc_shmem->vp_shmem_transaction_cnt : INT32_MAX; 121 118 } 122 119 123 void 124 _basic_vproc_transaction_try_exit(int status) 120 size_t 121 _vproc_standby_count(void) 122 { 123 return likely(vproc_shmem) ? vproc_shmem->vp_shmem_standby_cnt : INT32_MAX; 124 } 125 126 size_t 127 _vproc_standby_timeout(void) 128 { 129 return likely(vproc_shmem) ? vproc_shmem->vp_shmem_standby_timeout : 0; 130 } 131 132 void 133 _vproc_transaction_try_exit(int status) 125 134 { 126 135 typeof(vproc_shmem->vp_shmem_transaction_cnt) newval; … … 147 156 } 148 157 149 _ basic_vproc_transaction_end();150 } 151 152 void 153 _ basic_vproc_transaction_end(void)158 _vproc_transaction_end(); 159 } 160 161 void 162 _vproc_transaction_end(void) 154 163 { 155 164 typeof(vproc_shmem->vp_shmem_transaction_cnt) newval; … … 172 181 { 173 182 vproc_standby_t vpsb = (vproc_standby_t)vproc_shmem_init; /* we need a "random" variable that is testable */ 183 184 _vproc_standby_begin(); 185 186 return vpsb; 187 } 188 189 void 190 _vproc_standby_begin(void) 191 { 174 192 typeof(vproc_shmem->vp_shmem_standby_cnt) newval; 175 193 … … 177 195 int po_r = pthread_once(&shmem_inited, vproc_shmem_init); 178 196 if (po_r != 0 || vproc_shmem == NULL) { 179 return NULL;197 return; 180 198 } 181 199 } … … 187 205 abort(); 188 206 } 189 190 return vpsb;191 207 } 192 208 … … 194 210 vproc_standby_end(vproc_t vp __attribute__((unused)), vproc_standby_t vpt) 195 211 { 196 typeof(vproc_shmem->vp_shmem_standby_cnt) newval;197 198 212 if (unlikely(vpt != (vproc_standby_t)vproc_shmem_init)) { 199 213 __crashreporter_info__ = "Bogus standby handle passed to vproc_standby_end() "; 200 214 abort(); 201 215 } 216 217 _vproc_standby_end(); 218 } 219 220 void 221 _vproc_standby_end(void) 222 { 223 typeof(vproc_shmem->vp_shmem_standby_cnt) newval; 202 224 203 225 newval = __sync_sub_and_fetch(&vproc_shmem->vp_shmem_standby_cnt, 1); -
trunk/launchd/src/libvproc_internal.h
r23574 r23580 39 39 int32_t vp_shmem_transaction_cnt; 40 40 int32_t vp_shmem_standby_cnt; 41 uint32_t vp_shmem_standby_timeout; 41 42 int32_t vp_shmem_flags; 42 43 }; -
trunk/launchd/src/libvproc_private.h
r23578 r23580 77 77 vproc_err_t _vprocmgr_move_subset_to_user(uid_t target_user, const char *session_type); 78 78 79 void _basic_vproc_transaction_begin(void); 80 void _basic_vproc_transaction_end(void); 81 size_t _basic_vproc_transaction_count(void); 82 void _basic_vproc_transaction_try_exit(int status); 79 void _vproc_standby_begin(void); 80 void _vproc_standby_end(void); 81 size_t _vproc_standby_count(void); 82 size_t _vproc_standby_timeout(void); 83 84 void _vproc_transaction_try_exit(int status); 85 void _vproc_transaction_begin(void); 86 void _vproc_transaction_end(void); 87 size_t _vproc_transaction_count(void); 83 88 84 89

