libsys, libc: provide rfork_thread() and pdrfork_thread() on all arches
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54898
This commit is contained in:
@@ -182,6 +182,7 @@ FBSD_1.0 {
|
|||||||
rename;
|
rename;
|
||||||
revoke;
|
revoke;
|
||||||
rfork;
|
rfork;
|
||||||
|
rfork_thread;
|
||||||
rmdir;
|
rmdir;
|
||||||
rtprio;
|
rtprio;
|
||||||
rtprio_thread;
|
rtprio_thread;
|
||||||
@@ -391,6 +392,7 @@ FBSD_1.8 {
|
|||||||
|
|
||||||
FBSD_1.9 {
|
FBSD_1.9 {
|
||||||
pdrfork;
|
pdrfork;
|
||||||
|
pdrfork_thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSDprivate_1.0 {
|
FBSDprivate_1.0 {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
MIASM:= ${MIASM:Nfreebsd[467]_*}
|
MIASM:= ${MIASM:Nfreebsd[467]_*}
|
||||||
|
|
||||||
SRCS+= __vdso_gettc.c \
|
SRCS+= __vdso_gettc.c \
|
||||||
|
pdrfork_thread_gen.c \
|
||||||
|
rfork_thread_gen.c \
|
||||||
sched_getcpu_gen.c
|
sched_getcpu_gen.c
|
||||||
|
|
||||||
MDASM= cerror.S \
|
MDASM= cerror.S \
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
FBSD_1.0 {
|
FBSD_1.0 {
|
||||||
rfork_thread;
|
|
||||||
amd64_get_fsbase;
|
amd64_get_fsbase;
|
||||||
amd64_get_gsbase;
|
amd64_get_gsbase;
|
||||||
amd64_set_fsbase;
|
amd64_set_fsbase;
|
||||||
@@ -17,10 +16,6 @@ FBSD_1.8 {
|
|||||||
amd64_set_tlsbase;
|
amd64_set_tlsbase;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSD_1.9 {
|
|
||||||
pdrfork_thread;
|
|
||||||
};
|
|
||||||
|
|
||||||
FBSDprivate_1.0 {
|
FBSDprivate_1.0 {
|
||||||
_vfork;
|
_vfork;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
SRCS+= __vdso_gettc.c \
|
SRCS+= __vdso_gettc.c \
|
||||||
|
pdrfork_thread_gen.c \
|
||||||
|
rfork_thread_gen.c \
|
||||||
sched_getcpu_gen.c
|
sched_getcpu_gen.c
|
||||||
|
|
||||||
MDASM= \
|
MDASM= \
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ FBSD_1.0 {
|
|||||||
i386_set_ldt;
|
i386_set_ldt;
|
||||||
i386_set_watch;
|
i386_set_watch;
|
||||||
i386_vm86;
|
i386_vm86;
|
||||||
rfork_thread;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSD_1.6 {
|
FBSD_1.6 {
|
||||||
@@ -20,10 +19,6 @@ FBSD_1.6 {
|
|||||||
x86_pkru_unprotect_range;
|
x86_pkru_unprotect_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSD_1.9 {
|
|
||||||
pdrfork_thread;
|
|
||||||
};
|
|
||||||
|
|
||||||
FBSDprivate_1.0 {
|
FBSDprivate_1.0 {
|
||||||
_vfork;
|
_vfork;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*-
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright 2026 The FreeBSD Foundation
|
||||||
|
*
|
||||||
|
* This software were developed by
|
||||||
|
* Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
|
||||||
|
* the FreeBSD Foundation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/procdesc.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
pid_t
|
||||||
|
pdrfork_thread(int *fdp, int pdflags, int rfflags, void *stack_addr,
|
||||||
|
int (*start_fn)(void *), void *arg)
|
||||||
|
{
|
||||||
|
pid_t res;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* See comment in rfork_thread_gen.c. */
|
||||||
|
if (stack_addr != NULL) {
|
||||||
|
errno = EOPNOTSUPP;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
res = pdrfork(fdp, pdflags, rfflags);
|
||||||
|
if (res == 0) {
|
||||||
|
ret = start_fn(arg);
|
||||||
|
_exit(ret);
|
||||||
|
}
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
SRCS+= __vdso_gettc.c \
|
SRCS+= __vdso_gettc.c \
|
||||||
|
pdrfork_thread_gen.c \
|
||||||
|
rfork_thread_gen.c \
|
||||||
sched_getcpu_gen.c
|
sched_getcpu_gen.c
|
||||||
|
|
||||||
MDASM+= cerror.S
|
MDASM+= cerror.S
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
SRCS+= __vdso_gettc.c \
|
SRCS+= __vdso_gettc.c \
|
||||||
|
pdrfork_thread_gen.c \
|
||||||
|
rfork_thread_gen.c \
|
||||||
sched_getcpu_gen.c
|
sched_getcpu_gen.c
|
||||||
|
|
||||||
MDASM+= cerror.S
|
MDASM+= cerror.S
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*-
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright 2026 The FreeBSD Foundation
|
||||||
|
*
|
||||||
|
* This software were developed by
|
||||||
|
* Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
|
||||||
|
* the FreeBSD Foundation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
pid_t
|
||||||
|
rfork_thread(int flags, void *stack_addr, int (*start_fn)(void *), void *arg)
|
||||||
|
{
|
||||||
|
pid_t res;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic implementation cannot switch stacks. Only
|
||||||
|
* architecture-specific code knows how to do it. Require
|
||||||
|
* that caller knows that, and refuse to do operate if the
|
||||||
|
* stack was supplied.
|
||||||
|
*
|
||||||
|
* Note that implementations that do switch stack, would fault
|
||||||
|
* immediately if the passed stack is NULL. They do not need to
|
||||||
|
* specifically check for the NULL stack value.
|
||||||
|
*/
|
||||||
|
if (stack_addr != NULL) {
|
||||||
|
errno = EOPNOTSUPP;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
res = rfork(flags);
|
||||||
|
if (res == 0) {
|
||||||
|
ret = start_fn(arg);
|
||||||
|
_exit(ret);
|
||||||
|
}
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
SRCS+= __vdso_gettc.c \
|
SRCS+= __vdso_gettc.c \
|
||||||
|
pdrfork_thread_gen.c \
|
||||||
|
rfork_thread_gen.c \
|
||||||
sched_getcpu_gen.c
|
sched_getcpu_gen.c
|
||||||
|
|
||||||
MDASM= cerror.S \
|
MDASM= cerror.S \
|
||||||
|
|||||||
Reference in New Issue
Block a user