@@ -31,6 +31,11 @@ extern void *_keymgr_get_and_lock_processwide_ptr(unsigned int key);
31
31
extern int _keymgr_get_and_lock_processwide_ptr_2 (unsigned int key , void * * result );
32
32
extern int _keymgr_set_lockmode_processwide_ptr (unsigned int key , unsigned int mode );
33
33
34
+ // private dyld3/dyld4 stuff
35
+ extern void _dyld_atfork_prepare (void ) __attribute__((weak_import ));
36
+ extern void _dyld_atfork_parent (void ) __attribute__((weak_import ));
37
+ //extern void _dyld_fork_child(void) __attribute__((weak_import));
38
+
34
39
static void attach_exception_port (thread_port_t thread , int segv_only );
35
40
36
41
// low 16 bits are the thread id, the next 8 bits are the original gc_state
@@ -521,6 +526,28 @@ static kern_return_t profiler_segv_handler
521
526
}
522
527
#endif
523
528
529
+ static int jl_lock_profile_mach (void )
530
+ {
531
+ jl_lock_profile ();
532
+ void * unused = NULL ;
533
+ int keymgr_locked = _keymgr_get_and_lock_processwide_ptr_2 (KEYMGR_GCC3_DW2_OBJ_LIST , & unused ) == 0 ;
534
+ if (_dyld_atfork_prepare != NULL && _dyld_atfork_parent != NULL )
535
+ _dyld_atfork_prepare ();
536
+ return keymgr_locked ;
537
+ }
538
+
539
+ static void jl_unlock_profile_mach (int keymgr_locked )
540
+ {
541
+ if (_dyld_atfork_prepare != NULL && _dyld_atfork_parent != NULL )
542
+ _dyld_atfork_parent ();
543
+ if (keymgr_locked )
544
+ _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST );
545
+ jl_unlock_profile ();
546
+ }
547
+
548
+ #define jl_lock_profile () int keymgr_locked = jl_lock_profile_mach()
549
+ #define jl_unlock_profile () jl_unlock_profile_mach(keymgr_locked)
550
+
524
551
void * mach_profile_listener (void * arg )
525
552
{
526
553
(void )arg ;
@@ -538,8 +565,6 @@ void *mach_profile_listener(void *arg)
538
565
// sample each thread, round-robin style in reverse order
539
566
// (so that thread zero gets notified last)
540
567
jl_lock_profile ();
541
- void * unused = NULL ;
542
- int keymgr_locked = _keymgr_get_and_lock_processwide_ptr_2 (KEYMGR_GCC3_DW2_OBJ_LIST , & unused ) == 0 ;
543
568
jl_shuffle_int_array_inplace (profile_round_robin_thread_order , jl_n_threads , & profile_cong_rng_seed );
544
569
for (int idx = jl_n_threads ; idx -- > 0 ; ) {
545
570
// Stop the threads in the random round-robin order.
@@ -609,8 +634,6 @@ void *mach_profile_listener(void *arg)
609
634
// We're done! Resume the thread.
610
635
jl_thread_resume (i , 0 );
611
636
}
612
- if (keymgr_locked )
613
- _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST );
614
637
jl_unlock_profile ();
615
638
if (running ) {
616
639
// Reset the alarm
0 commit comments