lib{c,sys}: return wrapped syscall APIs to libc

These provide standard APIs, but are implemented using another system
call (e.g., pipe implemented in terms of pipe2) or are interposed by the
threading library to support cancelation.

After discussion with kib (see D44111), I've concluded that it is
better to keep most public interfaces in libc with as little
as possible in libsys.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D44241
This commit is contained in:
Brooks Davis 2024-03-13 17:42:01 +00:00
parent ef5fddd344
commit d7847a8d35
72 changed files with 125 additions and 94 deletions

View File

@ -122,8 +122,7 @@ NOASM=
.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
.include "${LIBC_SRCTOP}/string/Makefile.inc"
SHARED_CFLAGS+= -D'_SYSCALL_BODY(name)='
.include "${LIBSYS_SRCTOP}/Makefile.sys"
.include "${LIBC_SRCTOP}/sys/Makefile.inc"
.include "${LIBC_SRCTOP}/secure/Makefile.inc"
.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
.include "${LIBC_SRCTOP}/uuid/Makefile.inc"

View File

@ -6,6 +6,7 @@
FBSD_1.0 {
.mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetprec;
fpgetround;
@ -13,6 +14,7 @@ FBSD_1.0 {
fpsetmask;
fpsetprec;
fpsetround;
sbrk;
};
/*
@ -26,4 +28,5 @@ FBSDprivate_1.0 {
__signalcontext;
signalcontext;
__siglongjmp;
_brk;
};

View File

@ -6,6 +6,8 @@
FBSD_1.0 {
__mcount;
alloca;
brk;
sbrk;
};
FBSD_1.3 {
@ -23,6 +25,7 @@ FBSD_1.6 {
};
FBSDprivate_1.0 {
_brk;
__aeabi_read_tp;
___longjmp;
__longjmp;

View File

@ -5,8 +5,10 @@
*/
FBSD_1.0 {
.mcount;
brk;
__flt_rounds;
___tls_get_addr;
sbrk;
};
FBSDprivate_1.0 {
@ -15,4 +17,5 @@ FBSDprivate_1.0 {
__signalcontext;
signalcontext;
__siglongjmp;
_brk;
};

View File

@ -6,11 +6,13 @@
FBSD_1.0 {
_mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetround;
fpgetsticky;
fpsetmask;
fpsetround;
sbrk;
};
FBSD_1.3 {

View File

@ -6,9 +6,11 @@
FBSD_1.0 {
_mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetround;
fpgetsticky;
fpsetmask;
fpsetround;
sbrk;
};

38
lib/libc/sys/Makefile.inc Normal file
View File

@ -0,0 +1,38 @@
# libc-specific portion of the system call interface
.PATH: ${LIBC_SRCTOP}/sys
# Most of the implementation is shared with libsys:
.include "${LIBSYS_SRCTOP}/Makefile.sys"
# emit empty assembly stubs for syscalls in dynamic libc
SHARED_CFLAGS+= -D'_SYSCALL_BODY(name)='
SYM_MAPS+= ${LIBC_SRCTOP}/sys/Symbol.map
# Add the interposer wrappers
SRCS+= ${INTERPOSED:S/$/.c/}
# Pseudo system calls implemented atop other interfaces.
SRCS+= \
POSIX2x_Fork.c \
brk.c \
closefrom.c \
compat-stub.c \
creat.c \
getdents.c \
lockf.c \
lstat.c \
mknod.c \
pipe.c \
recv.c \
recvmmsg.c \
send.c \
sendmmsg.c \
shm_open.c \
stat.c \
vadvise.c \
wait.c \
wait3.c \
waitid.c \
waitpid.c

73
lib/libc/sys/Symbol.map Normal file
View File

@ -0,0 +1,73 @@
FBSD_1.0 {
accept;
aio_suspend;
close;
connect;
fcntl;
fork;
fsync;
msync;
nanosleep;
open;
pipe;
poll;
pselect;
ptrace;
read;
readv;
recvfrom;
recvmsg;
select;
sendmsg;
sendto;
shm_open;
sigaction;
sigprocmask;
sigsuspend;
sigtimedwait;
sigwait;
sigwaitinfo;
vadvise;
wait4;
write;
writev;
};
FBSD_1.1 {
closefrom;
};
FBSD_1.2 {
pdfork;
};
FBSD_1.3 {
accept4;
wait6;
};
FBSD_1.4 {
ppoll;
numa_setaffinity;
numa_getaffinity;
sendmmsg;
recvmmsg;
};
FBSD_1.5 {
clock_nanosleep;
fdatasync;
getdents;
kevent;
lstat;
mknod;
stat;
};
FBSD_1.6 {
shm_create_largepage;
};
FBSD_1.7 {
_Fork;
};

View File

@ -40,21 +40,6 @@ SRCS+= \
interposing_table.c \
libsys_sigwait.c
SRCS+= getdents.c lstat.c mknod.c stat.c
SRCS+= creat.c
SRCS+= lockf.c wait.c wait3.c waitpid.c waitid.c
SRCS+= recv.c recvmmsg.c send.c sendmmsg.c
SRCS+= brk.c
SRCS+= closefrom.c
SRCS+= pipe.c
SRCS+= shm_open.c
SRCS+= vadvise.c
SRCS+= POSIX2x_Fork.c
SRCS+= compat-stub.c
.if ${LIB} == "c"
# Trapping stubs in dynamic libc to be filtered by libsys.
SOBJS+= libc_stubs.pico
@ -113,7 +98,6 @@ INTERPOSED = \
write \
writev
SRCS+= ${INTERPOSED:S/$/.c/}
PSEUDO+= ${INTERPOSED}
# Add machine dependent asm sources:

View File

@ -33,7 +33,6 @@ FBSD_1.0 {
_exit;
_umtx_op;
abort2;
accept;
access;
acct;
adjtime;
@ -42,7 +41,6 @@ FBSD_1.0 {
aio_fsync;
aio_read;
aio_return;
aio_suspend;
aio_waitcomplete;
aio_write;
audit;
@ -57,8 +55,6 @@ FBSD_1.0 {
clock_getres;
clock_gettime;
clock_settime;
close;
connect;
dup;
dup2;
eaccess;
@ -81,12 +77,9 @@ FBSD_1.0 {
fchflags;
fchmod;
fchown;
fcntl;
fhopen;
flock;
fork;
fpathconf;
fsync;
futimes;
getaudit;
getaudit_addr;
@ -173,32 +166,21 @@ FBSD_1.0 {
msgrcv;
msgsnd;
msgsys;
msync;
munlock;
munlockall;
munmap;
nanosleep;
nfssvc;
nmount;
ntp_adjtime;
ntp_gettime;
open;
pathconf;
pipe;
poll;
posix_openpt;
preadv;
profil;
pselect;
ptrace;
pwritev;
quotactl;
read;
readlink;
readv;
reboot;
recvfrom;
recvmsg;
rename;
revoke;
rfork;
@ -213,13 +195,10 @@ FBSD_1.0 {
sched_setparam;
sched_setscheduler;
sched_yield;
select;
semget;
semop;
semsys;
sendfile;
sendmsg;
sendto;
setaudit;
setaudit_addr;
setauid;
@ -240,23 +219,16 @@ FBSD_1.0 {
setsockopt;
settimeofday;
setuid;
shm_open;
shm_unlink;
shmat;
shmdt;
shmget;
shmsys;
shutdown;
sigaction;
sigaltstack;
sigpending;
sigprocmask;
sigqueue;
sigreturn;
sigsuspend;
sigtimedwait;
sigwait;
sigwaitinfo;
socket;
socketpair;
swapon;
@ -285,11 +257,7 @@ FBSD_1.0 {
utimes;
utrace;
uuidgen;
vadvise;
vfork;
wait4;
write;
writev;
__error;
ftruncate;
@ -302,7 +270,6 @@ FBSD_1.0 {
FBSD_1.1 {
__semctl;
closefrom;
cpuset;
cpuset_getid;
cpuset_setid;
@ -334,7 +301,6 @@ FBSD_1.2 {
cap_getmode;
getloginclass;
getpagesizes;
pdfork;
pdgetpid;
pdkill;
posix_fallocate;
@ -347,7 +313,6 @@ FBSD_1.2 {
};
FBSD_1.3 {
accept4;
aio_mlock;
bindat;
cap_fcntls_get;
@ -365,37 +330,24 @@ FBSD_1.3 {
pipe2;
posix_fadvise;
procctl;
wait6;
};
FBSD_1.4 {
futimens;
ppoll;
utimensat;
numa_setaffinity;
numa_getaffinity;
sendmmsg;
recvmmsg;
};
FBSD_1.5 {
clock_nanosleep;
elf_aux_info;
fdatasync;
fhstat;
fhstatfs;
fstat;
fstatat;
fstatfs;
getdents;
getdirentries;
getfsstat;
getrandom;
kevent;
lstat;
mknod;
mknodat;
stat;
statfs;
cpuset_getdomain;
cpuset_setdomain;
@ -412,12 +364,10 @@ FBSD_1.6 {
fhreadlink;
getfhat;
funlinkat;
shm_create_largepage;
shm_rename;
};
FBSD_1.7 {
_Fork;
fspacectl;
kqueuex;
membarrier;

View File

@ -4,8 +4,6 @@ FBSD_1.0 {
amd64_get_gsbase;
amd64_set_fsbase;
amd64_set_gsbase;
brk;
sbrk;
};
FBSD_1.6 {
@ -15,12 +13,6 @@ FBSD_1.6 {
x86_pkru_unprotect_range;
};
/*
*
* FreeBSD private ABI
*
*/
FBSDprivate_1.0 {
_brk;
_vfork;
};

View File

@ -1,10 +1,3 @@
FBSD_1.0 {
brk;
sbrk;
};
FBSDprivate_1.0 {
_vfork;
_brk;
_sbrk;
};

View File

@ -1,6 +1,5 @@
FBSD_1.0 {
rfork_thread;
brk;
i386_clr_watch;
i386_get_fsbase;
i386_get_gsbase;
@ -12,7 +11,6 @@ FBSD_1.0 {
i386_set_ldt;
i386_set_watch;
i386_vm86;
sbrk;
};
FBSD_1.6 {
@ -24,5 +22,4 @@ FBSD_1.6 {
FBSDprivate_1.0 {
_vfork;
_brk;
};

View File

@ -1,4 +0,0 @@
FBSD_1.0 {
brk;
sbrk;
};

View File

@ -1,4 +0,0 @@
FBSD_1.0 {
brk;
sbrk;
};