History log of /openbsd-current/lib/librthread/rthread_fork.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.23 29-Oct-2017 mpi

Prefer <elf.h> to the non portable <sys/exec_elf.h>.

ok jca@, deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.22 05-Sep-2017 guenther

Move mutex, condvar, and thread-specific data routes, pthread_once, and
pthread_exit from libpthread to libc, along with low-level bits to
support them. Major bump to both libc and libpthread.

Requested by libressl team. Ports testing by naddy@
ok kettenis@


# 1.21 30-Jul-2017 tedu

disable post fork checks for now, too much turbulence in the air


# 1.20 27-Jul-2017 tedu

bad things can (and will) happen if a threaded program calls fork() and
then strays off the path to exec(). one common manifestation of this
problem occurs in pthread_join(), so we can add a little check there.
first person to hit this in real life gets to change the error message.


Revision tags: OPENBSD_6_1_BASE
# 1.19 04-Sep-2016 akfaew

Get rid of ticket support, replace "struct _spinlock" with "_atomic_lock_t".

ok tedu@


# 1.18 01-Sep-2016 otto

Less lock contention by using more pools for mult-threaded programs.
tested by many (thanks!) ok tedu, guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.17 07-May-2016 guenther

Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread
and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable!

Make libpthread dlopen'able by moving the cancelation wrappers into libc
and doing locking and fork/errno handling via callbacks that libpthread
registers when it first initializes. 'errno' *must* be declared via
<errno.h> now!

Clean up libpthread's symbol exports like libc.

On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec.

Testing by various, particularly sthen@ and patrick@
ok kettenis@


# 1.16 02-Apr-2016 guenther

Eliminate the need to explicitly invoke syscalls via their _thread_sys_*
aliases by using a macro REDIRECT_SYSCALL() to map the symbols. Apply
that to getthrid(), sysctl(), and issetugid() as well.

ok mpi@ beck@


Revision tags: OPENBSD_5_9_BASE
# 1.15 27-Jan-2016 kettenis

Replace the malloc spinlock with a mutex. This lock is held over system calls
which run for many cycles and may even sleep. This leads to other threads
spinning for a long time waiting on the lock. Using a mutex means those
threads go to sleep and get woken up when the lock is released, which results
in a lot less CPU usage. More work is needed to improve the performance of
threaded code that suffers from malloc lock contention, but this diff makes
ports like Firefox significantly more usable.

Tested by many.

ok mpi@, guenther@, tedu@, jca@


# 1.14 18-Oct-2015 guenther

ld.so no longer needs or uses a bind lock, so stop setting it. This
eliminates a chunk of complexity from the libpthread init and the fork
wrapper, as it was the bind lock that needed prebinding before use.


Revision tags: OPENBSD_5_8_BASE
# 1.13 19-May-2015 guenther

Instead of testing for __ELF__ and/or vax, leave out the bits for interfacing
with ld.so locking whenever building NOPIC

pointless use of __ELF__ noted by brad@
ok miod@


# 1.12 10-May-2015 guenther

In the child after fork, the dl lock has to be forced as its inner spinlock
may have been grabbed by another thread in the parent before the fork

problem report from dcoppa@, ok kettenis@


# 1.11 07-Apr-2015 guenther

Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback
handling from libpthread to libc, though libpthread still overrides the
inner call to handle locking and thread-library reinitialization.
Major version bump for both libc and libpthread.

verification that this fixes various ports ajacoutot@
asm assistance miod@; ok millert@ deraadt@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.10 29-Nov-2013 guenther

Don't try to reuse _initial_thread in the fork() wrapper, as the
thread's existing handle must continue to be valid and it didn't
fully 'change' the thread handle anyway. For pthread_main_np(),
use a new flag, THREAD_ORIGINAL, to indicate that the flagged thread
is the original thread for *this* process.

Fixes some ConsoleKit failures according to aja@


Revision tags: OPENBSD_5_4_BASE
# 1.9 25-Jun-2013 guenther

nmask and omask only used on ELF. Noted by todd@


# 1.8 21-Jun-2013 guenther

The bind lock must only be grabbed with all signals masked.

backtrace of example case from sthen@
ok kettenis@ millert@


# 1.7 01-Jun-2013 tedu

cleanup and consolidate the spinlock_lock (what a name!) code.
it's now atomic_lock to better reflect its usage, and librthread now
features a new spinlock that's really a ticket lock.
thrlseep can handle both types of lock via a flag in the clock arg.
(temp back compat hack)
remove some old stuff that's accumulated along the way and no longer used.
some feedback from dlg, who is concerned with all things ticket lock.
(you need to boot a new kernel before installing librthread)


Revision tags: OPENBSD_5_3_BASE
# 1.6 22-Aug-2012 matthew

We want to check that the dynamic linker is available at run-time, so
we should actually check for _DYNAMIC at run-time rather than checking
for __PIC__ at compile time, since the two are actually independent.

Problem and solution identified by guenther; minor tweaks by me.
ok guenther


# 1.5 22-Aug-2012 matthew

Test for __PIC__ instead of PIC in preparation for eliminating -DPIC
from bsd.lib.mk for C source files.

ok deraadt, pascal


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.4 06-Nov-2011 guenther

Move <machine/spinlock.h> into rthread.h; strip out unnecessary #includes


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.3 27-Nov-2009 guenther

Change threxit() to take a pointer to a pid_t to zero out from the
kernel so that librthread can detect when a thread is completely
done with its stack without need a kqueue. The dying thread moves
itself to a GC list, other threads scan the GC list on pthread_create()
and pthread_join() and free the stack and handle once the thread's
thread id is zeroed.

"get it in" deraadt@, tedu@, cheers by others


# 1.2 21-Oct-2009 guenther

After forking, the child is single threaded, so tell libc that. This
is needed to avoid deadlocks in popen() on FILE locking.

ok kurt@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.1 05-Jun-2008 kurt

- Add fork/vfork wrapper functions to reset state in the child process.
- Make an effort to protect important libc and ld.so critical areas during
the fork(2)/vfork(2) sys call.
- Add pthread_atfork(3) implementation based on Daniel Eischen's code.

Original diff by Philip Guenther <guenther at gmail.com> with some
additions and refinements by me. Positive test report from brad@ with
many kde apps. fork(2) and pthread_atfork(3) pthread regresses pass.
okay tedu@, kettenis@, marc@