diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2021-01-10 19:22:49 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2021-01-11 20:59:52 +0000 |
| commit | 21f749da82e755aafab127618affeffb86cff9a5 (patch) | |
| tree | 098b89a974c36f89652b952872c0977c31cbfd32 /lib/libthr/thread | |
| parent | 4174e45fb4320dc27969c3fcbdd7d06e3b1150b8 (diff) | |
Diffstat (limited to 'lib/libthr/thread')
| -rw-r--r-- | lib/libthr/thread/thr_fork.c | 64 | ||||
| -rw-r--r-- | lib/libthr/thread/thr_private.h | 1 | ||||
| -rw-r--r-- | lib/libthr/thread/thr_syscalls.c | 1 |
3 files changed, 60 insertions, 6 deletions
diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c index 7b6b47024c12..9861e93c427d 100644 --- a/lib/libthr/thread/thr_fork.c +++ b/lib/libthr/thread/thr_fork.c @@ -132,10 +132,19 @@ __pthread_cxa_finalize(struct dl_phdr_info *phdr_info) _thr_sigact_unload(phdr_info); } -__weak_reference(__thr_fork, _fork); +enum thr_fork_mode { + MODE_FORK, + MODE_PDFORK, +}; -pid_t -__thr_fork(void) +struct thr_fork_args { + enum thr_fork_mode mode; + void *fdp; + int flags; +}; + +static pid_t +thr_fork_impl(const struct thr_fork_args *a) { struct pthread *curthread; struct pthread_atfork *af; @@ -144,8 +153,17 @@ __thr_fork(void) int was_threaded; int rtld_locks[MAX_RTLD_LOCKS]; - if (!_thr_is_inited()) - return (__sys_fork()); + if (!_thr_is_inited()) { + switch (a->mode) { + case MODE_FORK: + return (__sys_fork()); + case MODE_PDFORK: + return (__sys_pdfork(a->fdp, a->flags)); + default: + errno = EDOOFUS; + return (-1); + } + } curthread = _get_curthread(); cancelsave = curthread->no_cancel; @@ -186,7 +204,19 @@ __thr_fork(void) * indirection, the syscall symbol is resolved in * _thr_rtld_init() with side-effect free call. */ - ret = syscall(SYS_fork); + switch (a->mode) { + case MODE_FORK: + ret = syscall(SYS_fork); + break; + case MODE_PDFORK: + ret = syscall(SYS_pdfork, a->fdp, a->flags); + break; + default: + ret = -1; + errno = EDOOFUS; + break; + } + if (ret == 0) { /* Child process */ errsave = errno; @@ -272,3 +302,25 @@ __thr_fork(void) return (ret); } + +__weak_reference(__thr_fork, _fork); + +pid_t +__thr_fork(void) +{ + struct thr_fork_args a; + + a.mode = MODE_FORK; + return (thr_fork_impl(&a)); +} + +pid_t +__thr_pdfork(int *fdp, int flags) +{ + struct thr_fork_args a; + + a.mode = MODE_PDFORK; + a.fdp = fdp; + a.flags = flags; + return (thr_fork_impl(&a)); +} diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 33cb03fce990..a1258940a896 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -984,6 +984,7 @@ void __pthread_distribute_static_tls(size_t offset, void *src, size_t len, int *__error_threaded(void) __hidden; void __thr_interpose_libc(void) __hidden; pid_t __thr_fork(void); +pid_t __thr_pdfork(int *, int); int __thr_setcontext(const ucontext_t *ucp); int __thr_sigaction(int sig, const struct sigaction *act, struct sigaction *oact) __hidden; diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c index 025dfc75fab6..c60308fcd1d2 100644 --- a/lib/libthr/thread/thr_syscalls.c +++ b/lib/libthr/thread/thr_syscalls.c @@ -687,6 +687,7 @@ __thr_interpose_libc(void) SLOT(map_stacks_exec); SLOT(fdatasync); SLOT(clock_nanosleep); + SLOT(pdfork); #undef SLOT *(__libc_interposing_slot( INTERPOS__pthread_mutex_init_calloc_cb)) = |
