Skip to content

Commit

Permalink
lib{c,sys}: return wrapped syscall APIs to libc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brooksdavis committed Mar 13, 2024
1 parent ef5fddd commit d7847a8
Show file tree
Hide file tree
Showing 72 changed files with 125 additions and 94 deletions.
3 changes: 1 addition & 2 deletions lib/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lib/libc/amd64/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
FBSD_1.0 {
.mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetprec;
fpgetround;
fpgetsticky;
fpsetmask;
fpsetprec;
fpsetround;
sbrk;
};

/*
Expand All @@ -26,4 +28,5 @@ FBSDprivate_1.0 {
__signalcontext;
signalcontext;
__siglongjmp;
_brk;
};
3 changes: 3 additions & 0 deletions lib/libc/arm/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
FBSD_1.0 {
__mcount;
alloca;
brk;
sbrk;
};

FBSD_1.3 {
Expand All @@ -23,6 +25,7 @@ FBSD_1.6 {
};

FBSDprivate_1.0 {
_brk;
__aeabi_read_tp;
___longjmp;
__longjmp;
Expand Down
3 changes: 3 additions & 0 deletions lib/libc/i386/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/
FBSD_1.0 {
.mcount;
brk;
__flt_rounds;
___tls_get_addr;
sbrk;
};

FBSDprivate_1.0 {
Expand All @@ -15,4 +17,5 @@ FBSDprivate_1.0 {
__signalcontext;
signalcontext;
__siglongjmp;
_brk;
};
2 changes: 2 additions & 0 deletions lib/libc/powerpc/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
FBSD_1.0 {
_mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetround;
fpgetsticky;
fpsetmask;
fpsetround;
sbrk;
};

FBSD_1.3 {
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/powerpc64/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
FBSD_1.0 {
_mcount;
__flt_rounds;
brk;
fpgetmask;
fpgetround;
fpgetsticky;
fpsetmask;
fpsetround;
sbrk;
};
38 changes: 38 additions & 0 deletions lib/libc/sys/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
73 changes: 73 additions & 0 deletions lib/libc/sys/Symbol.map
Original file line number Diff line number Diff line change
@@ -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;
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions lib/libsys/Makefile.sys
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +98,6 @@ INTERPOSED = \
write \
writev

SRCS+= ${INTERPOSED:S/$/.c/}
PSEUDO+= ${INTERPOSED}

# Add machine dependent asm sources:
Expand Down
Loading

0 comments on commit d7847a8

Please sign in to comment.