From cb5c4b10ba7c6d9f83b961c24be8f766ea6156c0 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 27 Nov 2008 11:27:59 +0000 Subject: Add two rtld exported symbols, _rtld_atfork_pre and _rtld_atfork_post. Threading library calls _pre before the fork, allowing the rtld to lock itself to ensure that other threads of the process are out of dynamic linker. _post releases the locks. This allows the rtld to have consistent state in the child. Although child may legitimately call only async-safe functions, the call may need plt relocation resolution, and this requires working rtld. Reported and debugging help by: rink Reviewed by: kan, davidxu MFC after: 1 month (anyway, not before 7.1 is out) --- libexec/rtld-elf/rtld_lock.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libexec/rtld-elf/rtld_lock.c') diff --git a/libexec/rtld-elf/rtld_lock.c b/libexec/rtld-elf/rtld_lock.c index 5bb891a2ae82..bf4caf71176b 100644 --- a/libexec/rtld-elf/rtld_lock.c +++ b/libexec/rtld-elf/rtld_lock.c @@ -316,3 +316,19 @@ _rtld_thread_init(struct RtldLockInfo *pli) thread_mask_set(flags); dbg("_rtld_thread_init: done"); } + +void +_rtld_atfork_pre(int *locks) +{ + + locks[2] = wlock_acquire(rtld_phdr_lock); + locks[0] = rlock_acquire(rtld_bind_lock); +} + +void +_rtld_atfork_post(int *locks) +{ + + rlock_release(rtld_bind_lock, locks[0]); + wlock_release(rtld_phdr_lock, locks[2]); +} -- cgit v1.3