From nobody Mon Feb 05 20:38:23 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TTJ9r0kH2z58xwJ; Mon, 5 Feb 2024 20:38:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TTJ9r0TSzz4pqC; Mon, 5 Feb 2024 20:38:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707165504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SwtCROZonXt9RWqn30qbXpJTpa/4g9xRrjKzP4i97S4=; b=ID/sIzJ3enSGAs4mpsSZeNORQcgDrVLc64i9eS5GSxMr8WAElP7f7LXQ6QUrkjgpKqCeJc LKbVVkRa6mWTH3X+JUqb0mTNeT8BREy2OH9vv5Lz7QtBe23RRnR4Uo6SJkBbqWJVdvbfVE +Qla3CJ1jCU4HNBiLY6GNWjIdl5cu9aqg97FcIwIYEvSo9qZefQQWq5BTi5MDzGWwIhpqP 2BrnJip8XRWHShh+h7p7HW9sbfJ6HCyl8REEH4EcofD/NirKZY66yRK6Yj+FEjiW0i1/Vu RRqgHe8h3Spnte13X6823pOSI4mWboB7o8YB5q/KRk5jBgKIo817A0LJm/uxNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707165504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SwtCROZonXt9RWqn30qbXpJTpa/4g9xRrjKzP4i97S4=; b=a/17Z+Z+QqznLmq4C+rP7B5qwm9lHqpFoya+yUIYQ2vyDFQkOy3dsFnqV5BFR77uq99Prv E5coXEjp0SbAgFG4hJvyDBcCm2XstBagiVTlXtTXKP5e7PJUjxa/PaJGdSfr3re3MAlmXR L4e8Jdz0UsmTfunWlO7Wh0zw1vf8z8tl32T7ppruBbAs/kapofNJtmumKIwG2spb1//RIy B9zicvoYJMgTrQb/5BhSYReGU24DnLcHe2kcniIZUBh+7BbofRo2asa5vef8IHpcAMaxth MsEgCGtXZLEEiP2kOnUjNurdiASHWzXtIidDipjVMuB7SYgmaQVAUfSFKzo3KQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707165504; a=rsa-sha256; cv=none; b=EHVT2F+0lpg/6T5RxXtTdjehFrQhvVO+4LqBwjju5XGg48gkvA73sA+q4qZPukHfyZMAol VB0LkXAo4PHFgLS0SHBBHy+JD9W003+u0h0ePO3h3xIuqQN+Kx1Le6exsUBYbMCAgB70Ic 6eofCt6BbzsK0V5eD6ou90bXf1FQiuLU/YIymbumvN0pvCOXKmVJLlQ173/MFX4bYvt9R7 oxzf6Fybxk3nP74kWbOjSNqaaqvyasM6/Trqa5EcMuHjMtkYnRj0FSVVr4l2G3wF5HAMyU 27xQ1Y2dNNDbk/2Az3altUw/SQ5r/CAjn6ysvy22snMdiroy0A1o/jErJTrJTQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TTJ9q6fgVzvlf; Mon, 5 Feb 2024 20:38:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 415KcNER068807; Mon, 5 Feb 2024 20:38:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 415KcNej068804; Mon, 5 Feb 2024 20:38:23 GMT (envelope-from git) Date: Mon, 5 Feb 2024 20:38:23 GMT Message-Id: <202402052038.415KcNej068804@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 9cbd96582c0a - main - libc: split libc and syscall interposing (1/2) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9cbd96582c0ac133f911270a47bff189d769ac8d Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=9cbd96582c0ac133f911270a47bff189d769ac8d commit 9cbd96582c0ac133f911270a47bff189d769ac8d Author: Brooks Davis AuthorDate: 2024-01-16 20:16:39 +0000 Commit: Brooks Davis CommitDate: 2024-02-05 20:34:55 +0000 libc: split libc and syscall interposing (1/2) System calls or their wrappers are now interposed by __libsys_interposing with purely libc entries remaining in __libc_interposing. Use __libsys_interposing_slot in libthr to update __libsys_interposing, but also make __libc_interposing_slot fall back to __libsys_interposing_slot so an out of date libc has a chance of working during updates. Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908 --- lib/libc/compat-43/creat.c | 3 +-- lib/libc/gen/lockf.c | 4 ++-- lib/libc/gen/sleep.c | 2 +- lib/libc/gen/usleep.c | 2 +- lib/libc/gen/wait.c | 3 +-- lib/libc/gen/wait3.c | 4 ++-- lib/libc/gen/waitid.c | 2 +- lib/libc/gen/waitpid.c | 3 +-- lib/libc/include/libc_private.h | 2 ++ lib/libc/net/recv.c | 2 +- lib/libc/net/send.c | 2 +- lib/libc/sys/Symbol.map | 1 + lib/libc/sys/accept.c | 3 +-- lib/libc/sys/accept4.c | 3 +-- lib/libc/sys/aio_suspend.c | 3 +-- lib/libc/sys/clock_nanosleep.c | 3 +-- lib/libc/sys/close.c | 3 +-- lib/libc/sys/connect.c | 3 +-- lib/libc/sys/fcntl.c | 2 +- lib/libc/sys/fdatasync.c | 3 +-- lib/libc/sys/fork.c | 3 +-- lib/libc/sys/fsync.c | 3 +-- lib/libc/sys/interposing_table.c | 28 ++++++++++++++++++++-------- lib/libc/sys/kevent.c | 3 +-- lib/libc/sys/msync.c | 3 +-- lib/libc/sys/nanosleep.c | 3 +-- lib/libc/sys/open.c | 3 ++- lib/libc/sys/openat.c | 2 +- lib/libc/sys/pdfork.c | 4 ++-- lib/libc/sys/poll.c | 3 +-- lib/libc/sys/ppoll.c | 3 +-- lib/libc/sys/pselect.c | 3 +-- lib/libc/sys/read.c | 3 +-- lib/libc/sys/readv.c | 3 +-- lib/libc/sys/recvfrom.c | 3 +-- lib/libc/sys/recvmsg.c | 3 +-- lib/libc/sys/select.c | 3 +-- lib/libc/sys/sendmsg.c | 3 +-- lib/libc/sys/sendto.c | 3 +-- lib/libc/sys/setcontext.c | 3 +-- lib/libc/sys/sigaction.c | 3 +-- lib/libc/sys/sigprocmask.c | 3 +-- lib/libc/sys/sigsuspend.c | 3 +-- lib/libc/sys/sigtimedwait.c | 3 +-- lib/libc/sys/sigwait.c | 3 +-- lib/libc/sys/sigwaitinfo.c | 3 +-- lib/libc/sys/swapcontext.c | 3 +-- lib/libc/sys/wait4.c | 3 +-- lib/libc/sys/wait6.c | 3 +-- lib/libc/sys/write.c | 3 +-- lib/libc/sys/writev.c | 3 +-- lib/libthr/thread/thr_syscalls.c | 15 ++++++++++----- 52 files changed, 85 insertions(+), 101 deletions(-) diff --git a/lib/libc/compat-43/creat.c b/lib/libc/compat-43/creat.c index 2597b4950ed3..9bc1db19de1d 100644 --- a/lib/libc/compat-43/creat.c +++ b/lib/libc/compat-43/creat.c @@ -43,9 +43,8 @@ int __creat(const char *path, mode_t mode); int __creat(const char *path, mode_t mode) { - return (((int (*)(int, const char *, int, ...)) - __libc_interposing[INTERPOS_openat])(AT_FDCWD, path, O_WRONLY | + __libsys_interposing[INTERPOS_openat])(AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode)); } diff --git a/lib/libc/gen/lockf.c b/lib/libc/gen/lockf.c index fec65896eaaa..bb98ebc1be82 100644 --- a/lib/libc/gen/lockf.c +++ b/lib/libc/gen/lockf.c @@ -63,7 +63,7 @@ lockf(int filedes, int function, off_t size) case F_TEST: fl.l_type = F_WRLCK; if (((int (*)(int, int, ...)) - __libc_interposing[INTERPOS_fcntl])(filedes, F_GETLK, &fl) + __libsys_interposing[INTERPOS_fcntl])(filedes, F_GETLK, &fl) == -1) return (-1); if (fl.l_type == F_UNLCK || (fl.l_sysid == 0 && @@ -79,5 +79,5 @@ lockf(int filedes, int function, off_t size) } return (((int (*)(int, int, ...)) - __libc_interposing[INTERPOS_fcntl])(filedes, cmd, &fl)); + __libsys_interposing[INTERPOS_fcntl])(filedes, cmd, &fl)); } diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index a0ec4898867c..7d0fa5332ecc 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -56,7 +56,7 @@ __sleep(unsigned int seconds) time_to_sleep.tv_sec = seconds; time_to_sleep.tv_nsec = 0; if (((int (*)(const struct timespec *, struct timespec *)) - __libc_interposing[INTERPOS_nanosleep])( + __libsys_interposing[INTERPOS_nanosleep])( &time_to_sleep, &time_remaining) != -1) return (0); if (errno != EINTR) diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index d0d2f020c36b..efd5ee0d1667 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -46,7 +46,7 @@ __usleep(useconds_t useconds) time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; time_to_sleep.tv_sec = useconds / 1000000; return (((int (*)(const struct timespec *, struct timespec *)) - __libc_interposing[INTERPOS_nanosleep])(&time_to_sleep, NULL)); + __libsys_interposing[INTERPOS_nanosleep])(&time_to_sleep, NULL)); } __weak_reference(__usleep, usleep); diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c index 893618880254..c400d07f9dd5 100644 --- a/lib/libc/gen/wait.c +++ b/lib/libc/gen/wait.c @@ -43,9 +43,8 @@ pid_t __wait(int *); pid_t __wait(int *istat) { - return (((pid_t (*)(pid_t, int *, int, struct rusage *)) - __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, 0, NULL)); + __libsys_interposing[INTERPOS_wait4])(WAIT_ANY, istat, 0, NULL)); } __weak_reference(__wait, wait); diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c index bb2ad7638893..40baf70ac6e6 100644 --- a/lib/libc/gen/wait3.c +++ b/lib/libc/gen/wait3.c @@ -43,9 +43,9 @@ pid_t __wait3(int *, int, struct rusage *); pid_t __wait3(int *istat, int options, struct rusage *rup) { - return (((pid_t (*)(pid_t, int *, int, struct rusage *)) - __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, options, rup)); + __libsys_interposing[INTERPOS_wait4])(WAIT_ANY, istat, options, + rup)); } __weak_reference(__wait3, wait3); diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c index 8690105ba147..b6e5ca33eed3 100644 --- a/lib/libc/gen/waitid.c +++ b/lib/libc/gen/waitid.c @@ -47,7 +47,7 @@ __waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags) pid_t ret; ret = ((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *, - siginfo_t *))__libc_interposing[INTERPOS_wait6])(idtype, id, + siginfo_t *))__libsys_interposing[INTERPOS_wait6])(idtype, id, &status, flags, NULL, info); /* diff --git a/lib/libc/gen/waitpid.c b/lib/libc/gen/waitpid.c index 9d5c3a37df59..ba7e667218cf 100644 --- a/lib/libc/gen/waitpid.c +++ b/lib/libc/gen/waitpid.c @@ -43,9 +43,8 @@ pid_t __waitpid(pid_t, int *, int); pid_t __waitpid(pid_t pid, int *istat, int options) { - return (((pid_t (*)(pid_t, int *, int, struct rusage *)) - __libc_interposing[INTERPOS_wait4])(pid, istat, options, NULL)); + __libsys_interposing[INTERPOS_wait4])(pid, istat, options, NULL)); } __weak_reference(__waitpid, waitpid); diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index bfeada696538..b2284d2df5c6 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -200,6 +200,8 @@ int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, typedef int (*interpos_func_t)(void); interpos_func_t *__libc_interposing_slot(int interposno); extern interpos_func_t __libc_interposing[] __hidden; +interpos_func_t *__libsys_interposing_slot(int interposno); +extern interpos_func_t __libsys_interposing[] __hidden; enum { INTERPOS_accept, diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c index 397388dc6b9d..db3d6216ed61 100644 --- a/lib/libc/net/recv.c +++ b/lib/libc/net/recv.c @@ -44,6 +44,6 @@ recv(int s, void *buf, size_t len, int flags) */ return (((ssize_t (*)(int, void *, size_t, int, struct sockaddr *, socklen_t *)) - __libc_interposing[INTERPOS_recvfrom])(s, buf, len, flags, + __libsys_interposing[INTERPOS_recvfrom])(s, buf, len, flags, NULL, NULL)); } diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c index e3efc269d9f6..94983553b1c3 100644 --- a/lib/libc/net/send.c +++ b/lib/libc/net/send.c @@ -44,6 +44,6 @@ send(int s, const void *msg, size_t len, int flags) */ return (((ssize_t (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t)) - __libc_interposing[INTERPOS_sendto])(s, msg, len, flags, + __libsys_interposing[INTERPOS_sendto])(s, msg, len, flags, NULL, 0)); } diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index a49229ace995..ff35693d808d 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -1051,6 +1051,7 @@ FBSDprivate_1.0 { /* Things that aren't system calls (in sort(1) order) */ __libc_interposing_slot; __libc_sigwait; + __libsys_interposing_slot; __set_error_selector; __sigwait; gssd_syscall; diff --git a/lib/libc/sys/accept.c b/lib/libc/sys/accept.c index 81f227c1caab..974d26eeaa6b 100644 --- a/lib/libc/sys/accept.c +++ b/lib/libc/sys/accept.c @@ -40,7 +40,6 @@ __weak_reference(__sys_accept, __accept); int accept(int s, struct sockaddr *addr, socklen_t *addrlen) { - return (((int (*)(int, struct sockaddr *, socklen_t *)) - __libc_interposing[INTERPOS_accept])(s, addr, addrlen)); + __libsys_interposing[INTERPOS_accept])(s, addr, addrlen)); } diff --git a/lib/libc/sys/accept4.c b/lib/libc/sys/accept4.c index 01fdce342e42..d69e843e28e6 100644 --- a/lib/libc/sys/accept4.c +++ b/lib/libc/sys/accept4.c @@ -40,7 +40,6 @@ __weak_reference(__sys_accept4, __accept4); int accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) { - return (((int (*)(int, struct sockaddr *, socklen_t *, int)) - __libc_interposing[INTERPOS_accept4])(s, addr, addrlen, flags)); + __libsys_interposing[INTERPOS_accept4])(s, addr, addrlen, flags)); } diff --git a/lib/libc/sys/aio_suspend.c b/lib/libc/sys/aio_suspend.c index 3324bcc8de2f..41872fbdd049 100644 --- a/lib/libc/sys/aio_suspend.c +++ b/lib/libc/sys/aio_suspend.c @@ -40,8 +40,7 @@ int aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct timespec *timeout) { - return (((int (*)(const struct aiocb * const[], int, const struct timespec *)) - __libc_interposing[INTERPOS_aio_suspend])(iocbs, niocb, timeout)); + __libsys_interposing[INTERPOS_aio_suspend])(iocbs, niocb, timeout)); } diff --git a/lib/libc/sys/clock_nanosleep.c b/lib/libc/sys/clock_nanosleep.c index a9d811f11b04..58d76243f42c 100644 --- a/lib/libc/sys/clock_nanosleep.c +++ b/lib/libc/sys/clock_nanosleep.c @@ -41,9 +41,8 @@ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp) { - return (((int (*)(clockid_t, int, const struct timespec *, struct timespec *)) - __libc_interposing[INTERPOS_clock_nanosleep])(clock_id, flags, + __libsys_interposing[INTERPOS_clock_nanosleep])(clock_id, flags, rqtp, rmtp)); } diff --git a/lib/libc/sys/close.c b/lib/libc/sys/close.c index e4d81614b056..923339f06e71 100644 --- a/lib/libc/sys/close.c +++ b/lib/libc/sys/close.c @@ -40,6 +40,5 @@ __weak_reference(__sys_close, __close); int close(int fd) { - - return (((int (*)(int))__libc_interposing[INTERPOS_close])(fd)); + return (((int (*)(int))__libsys_interposing[INTERPOS_close])(fd)); } diff --git a/lib/libc/sys/connect.c b/lib/libc/sys/connect.c index dd70908496a7..c908ec5dc493 100644 --- a/lib/libc/sys/connect.c +++ b/lib/libc/sys/connect.c @@ -40,7 +40,6 @@ __weak_reference(__sys_connect, __connect); int connect(int s, const struct sockaddr *addr, socklen_t addrlen) { - return (((int (*)(int, const struct sockaddr *, socklen_t)) - __libc_interposing[INTERPOS_connect])(s, addr, addrlen)); + __libsys_interposing[INTERPOS_connect])(s, addr, addrlen)); } diff --git a/lib/libc/sys/fcntl.c b/lib/libc/sys/fcntl.c index ad3734dfbf14..52e041003b4d 100644 --- a/lib/libc/sys/fcntl.c +++ b/lib/libc/sys/fcntl.c @@ -50,5 +50,5 @@ fcntl(int fd, int cmd, ...) va_end(args); return (((int (*)(int, int, ...)) - __libc_interposing[INTERPOS_fcntl])(fd, cmd, arg)); + __libsys_interposing[INTERPOS_fcntl])(fd, cmd, arg)); } diff --git a/lib/libc/sys/fdatasync.c b/lib/libc/sys/fdatasync.c index e400d1bcefb5..dc6927eae324 100644 --- a/lib/libc/sys/fdatasync.c +++ b/lib/libc/sys/fdatasync.c @@ -37,6 +37,5 @@ int fdatasync(int fd) { - - return (((int (*)(int))__libc_interposing[INTERPOS_fdatasync])(fd)); + return (((int (*)(int))__libsys_interposing[INTERPOS_fdatasync])(fd)); } diff --git a/lib/libc/sys/fork.c b/lib/libc/sys/fork.c index ecd8ecdf5730..4feecb355a56 100644 --- a/lib/libc/sys/fork.c +++ b/lib/libc/sys/fork.c @@ -39,6 +39,5 @@ __weak_reference(__sys_fork, __fork); pid_t fork(void) { - - return (((pid_t (*)(void))__libc_interposing[INTERPOS_fork])()); + return (((pid_t (*)(void))__libsys_interposing[INTERPOS_fork])()); } diff --git a/lib/libc/sys/fsync.c b/lib/libc/sys/fsync.c index 32302eb96492..92e3ae89bccc 100644 --- a/lib/libc/sys/fsync.c +++ b/lib/libc/sys/fsync.c @@ -39,6 +39,5 @@ __weak_reference(__sys_fsync, __fsync); int fsync(int fd) { - - return (((int (*)(int))__libc_interposing[INTERPOS_fsync])(fd)); + return (((int (*)(int))__libsys_interposing[INTERPOS_fsync])(fd)); } diff --git a/lib/libc/sys/interposing_table.c b/lib/libc/sys/interposing_table.c index e497319e8d27..f7678a1352ff 100644 --- a/lib/libc/sys/interposing_table.c +++ b/lib/libc/sys/interposing_table.c @@ -30,11 +30,22 @@ */ #include +#include #include "libc_private.h" #define SLOT(a, b) \ [INTERPOS_##a] = (interpos_func_t)b interpos_func_t __libc_interposing[INTERPOS_MAX] = { + SLOT(system, __libc_system), + SLOT(tcdrain, __libc_tcdrain), + SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub), + SLOT(spinlock, __libc_spinlock_stub), + SLOT(spinunlock, __libc_spinunlock_stub), + SLOT(map_stacks_exec, __libc_map_stacks_exec), + SLOT(distribute_static_tls, __libc_distribute_static_tls), +}; + +interpos_func_t __libsys_interposing[INTERPOS_MAX] = { SLOT(accept, __sys_accept), SLOT(accept4, __sys_accept4), SLOT(aio_suspend, __sys_aio_suspend), @@ -63,21 +74,14 @@ interpos_func_t __libc_interposing[INTERPOS_MAX] = { SLOT(sigtimedwait, __sys_sigtimedwait), SLOT(sigwaitinfo, __sys_sigwaitinfo), SLOT(swapcontext, __sys_swapcontext), - SLOT(system, __libc_system), - SLOT(tcdrain, __libc_tcdrain), SLOT(wait4, __sys_wait4), SLOT(write, __sys_write), SLOT(writev, __sys_writev), - SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub), - SLOT(spinlock, __libc_spinlock_stub), - SLOT(spinunlock, __libc_spinunlock_stub), SLOT(kevent, __sys_kevent), SLOT(wait6, __sys_wait6), SLOT(ppoll, __sys_ppoll), - SLOT(map_stacks_exec, __libc_map_stacks_exec), SLOT(fdatasync, __sys_fdatasync), SLOT(clock_nanosleep, __sys_clock_nanosleep), - SLOT(distribute_static_tls, __libc_distribute_static_tls), SLOT(pdfork, __sys_pdfork), }; #undef SLOT @@ -85,6 +89,14 @@ interpos_func_t __libc_interposing[INTERPOS_MAX] = { interpos_func_t * __libc_interposing_slot(int interposno) { - + /* XXX: forward compat. Remove after 15.0-RELEASE. */ + if (__libc_interposing[interposno] == NULL) + return (__libsys_interposing_slot(interposno)); return (&__libc_interposing[interposno]); } + +interpos_func_t * +__libsys_interposing_slot(int interposno) +{ + return (&__libsys_interposing[interposno]); +} diff --git a/lib/libc/sys/kevent.c b/lib/libc/sys/kevent.c index 4987dbc9a967..4be825e5c078 100644 --- a/lib/libc/sys/kevent.c +++ b/lib/libc/sys/kevent.c @@ -41,9 +41,8 @@ int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout) { - return (((int (*)(int, const struct kevent *, int, struct kevent *, int, const struct timespec *)) - __libc_interposing[INTERPOS_kevent])(kq, changelist, nchanges, + __libsys_interposing[INTERPOS_kevent])(kq, changelist, nchanges, eventlist, nevents, timeout)); } diff --git a/lib/libc/sys/msync.c b/lib/libc/sys/msync.c index 587687e636a5..6836d4db265c 100644 --- a/lib/libc/sys/msync.c +++ b/lib/libc/sys/msync.c @@ -40,7 +40,6 @@ __weak_reference(__sys_msync, __msync); int msync(void *addr, size_t len, int flags) { - return (((int (*)(void *, size_t, int)) - __libc_interposing[INTERPOS_msync])(addr, len, flags)); + __libsys_interposing[INTERPOS_msync])(addr, len, flags)); } diff --git a/lib/libc/sys/nanosleep.c b/lib/libc/sys/nanosleep.c index 22ebd4868fd4..83d54a1ca04a 100644 --- a/lib/libc/sys/nanosleep.c +++ b/lib/libc/sys/nanosleep.c @@ -39,7 +39,6 @@ __weak_reference(__sys_nanosleep, __nanosleep); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { - return (((int (*)(const struct timespec *, struct timespec *)) - __libc_interposing[INTERPOS_nanosleep])(rqtp, rmtp)); + __libsys_interposing[INTERPOS_nanosleep])(rqtp, rmtp)); } diff --git a/lib/libc/sys/open.c b/lib/libc/sys/open.c index 25e72d1a03d7..0ab3e9c4501e 100644 --- a/lib/libc/sys/open.c +++ b/lib/libc/sys/open.c @@ -51,5 +51,6 @@ open(const char *path, int flags, ...) mode = 0; } return (((int (*)(int, const char *, int, ...)) - __libc_interposing[INTERPOS_openat])(AT_FDCWD, path, flags, mode)); + __libsys_interposing[INTERPOS_openat])(AT_FDCWD, path, flags, + mode)); } diff --git a/lib/libc/sys/openat.c b/lib/libc/sys/openat.c index 8ed95e938a38..4d8a0fc627cb 100644 --- a/lib/libc/sys/openat.c +++ b/lib/libc/sys/openat.c @@ -54,5 +54,5 @@ openat(int fd, const char *path, int flags, ...) mode = 0; } return (((int (*)(int, const char *, int, ...)) - __libc_interposing[INTERPOS_openat])(fd, path, flags, mode)); + __libsys_interposing[INTERPOS_openat])(fd, path, flags, mode)); } diff --git a/lib/libc/sys/pdfork.c b/lib/libc/sys/pdfork.c index e2a5eca848ea..12cf6d858826 100644 --- a/lib/libc/sys/pdfork.c +++ b/lib/libc/sys/pdfork.c @@ -37,6 +37,6 @@ pid_t pdfork(int *fdp, int flags) { - return (((pid_t (*)(int *, int))__libc_interposing[ - INTERPOS_pdfork])(fdp, flags)); + return (((pid_t (*)(int *, int))__libsys_interposing[INTERPOS_pdfork]) + (fdp, flags)); } diff --git a/lib/libc/sys/poll.c b/lib/libc/sys/poll.c index 69c44731d18b..58fbb64fdda5 100644 --- a/lib/libc/sys/poll.c +++ b/lib/libc/sys/poll.c @@ -39,7 +39,6 @@ __weak_reference(__sys_poll, __poll); int poll(struct pollfd pfd[], nfds_t nfds, int timeout) { - return (((int (*)(struct pollfd *, nfds_t, int)) - __libc_interposing[INTERPOS_poll])(pfd, nfds, timeout)); + __libsys_interposing[INTERPOS_poll])(pfd, nfds, timeout)); } diff --git a/lib/libc/sys/ppoll.c b/lib/libc/sys/ppoll.c index ea998b6dadb5..2ff693fc5b19 100644 --- a/lib/libc/sys/ppoll.c +++ b/lib/libc/sys/ppoll.c @@ -40,8 +40,7 @@ int ppoll(struct pollfd pfd[], nfds_t nfds, const struct timespec *__restrict timeout, const sigset_t *__restrict newsigmask) { - return (((int (*)(struct pollfd *, nfds_t, const struct timespec *, - const sigset_t *)) __libc_interposing[INTERPOS_ppoll])(pfd, nfds, + const sigset_t *)) __libsys_interposing[INTERPOS_ppoll])(pfd, nfds, timeout, newsigmask)); } diff --git a/lib/libc/sys/pselect.c b/lib/libc/sys/pselect.c index 562c304fc594..dfd918b4c6d2 100644 --- a/lib/libc/sys/pselect.c +++ b/lib/libc/sys/pselect.c @@ -40,8 +40,7 @@ int pselect(int n, fd_set *rs, fd_set *ws, fd_set *es, const struct timespec *t, const sigset_t *s) { - return (((int (*)(int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *)) - __libc_interposing[INTERPOS_pselect])(n, rs, ws, es, t, s)); + __libsys_interposing[INTERPOS_pselect])(n, rs, ws, es, t, s)); } diff --git a/lib/libc/sys/read.c b/lib/libc/sys/read.c index 266763257dd8..846e7185bc02 100644 --- a/lib/libc/sys/read.c +++ b/lib/libc/sys/read.c @@ -40,7 +40,6 @@ __weak_reference(__sys_read, __read); ssize_t read(int fd, void *buf, size_t nbytes) { - return (((ssize_t (*)(int, void *, size_t)) - __libc_interposing[INTERPOS_read])(fd, buf, nbytes)); + __libsys_interposing[INTERPOS_read])(fd, buf, nbytes)); } diff --git a/lib/libc/sys/readv.c b/lib/libc/sys/readv.c index 05c14b5dd030..5493f7964098 100644 --- a/lib/libc/sys/readv.c +++ b/lib/libc/sys/readv.c @@ -41,7 +41,6 @@ __weak_reference(__sys_readv, __readv); ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { - return (((ssize_t (*)(int, const struct iovec *, int)) - __libc_interposing[INTERPOS_readv])(fd, iov, iovcnt)); + __libsys_interposing[INTERPOS_readv])(fd, iov, iovcnt)); } diff --git a/lib/libc/sys/recvfrom.c b/lib/libc/sys/recvfrom.c index dd5df99b8898..630b27404b7a 100644 --- a/lib/libc/sys/recvfrom.c +++ b/lib/libc/sys/recvfrom.c @@ -41,9 +41,8 @@ ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr * __restrict from, socklen_t * __restrict fromlen) { - return (((ssize_t (*)(int, void *, size_t, int, struct sockaddr *, socklen_t *)) - __libc_interposing[INTERPOS_recvfrom])(s, buf, len, flags, + __libsys_interposing[INTERPOS_recvfrom])(s, buf, len, flags, from, fromlen)); } diff --git a/lib/libc/sys/recvmsg.c b/lib/libc/sys/recvmsg.c index db471f3fd5d3..69b71c54e636 100644 --- a/lib/libc/sys/recvmsg.c +++ b/lib/libc/sys/recvmsg.c @@ -40,7 +40,6 @@ __weak_reference(__sys_recvmsg, __recvmsg); ssize_t recvmsg(int s, struct msghdr *msg, int flags) { - return (((int (*)(int, struct msghdr *, int)) - __libc_interposing[INTERPOS_recvmsg])(s, msg, flags)); + __libsys_interposing[INTERPOS_recvmsg])(s, msg, flags)); } diff --git a/lib/libc/sys/select.c b/lib/libc/sys/select.c index a03079964d1c..4b5862f72100 100644 --- a/lib/libc/sys/select.c +++ b/lib/libc/sys/select.c @@ -39,7 +39,6 @@ __weak_reference(__sys_select, __select); int select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t) { - return (((int (*)(int, fd_set *, fd_set *, fd_set *, struct timeval *)) - __libc_interposing[INTERPOS_select])(n, rs, ws, es, t)); + __libsys_interposing[INTERPOS_select])(n, rs, ws, es, t)); } diff --git a/lib/libc/sys/sendmsg.c b/lib/libc/sys/sendmsg.c index b4f442e02bcb..769bb4d2d136 100644 --- a/lib/libc/sys/sendmsg.c +++ b/lib/libc/sys/sendmsg.c @@ -40,7 +40,6 @@ __weak_reference(__sys_sendmsg, __sendmsg); ssize_t sendmsg(int s, const struct msghdr *msg, int flags) { - return (((int (*)(int, const struct msghdr *, int)) - __libc_interposing[INTERPOS_sendmsg])(s, msg, flags)); + __libsys_interposing[INTERPOS_sendmsg])(s, msg, flags)); } diff --git a/lib/libc/sys/sendto.c b/lib/libc/sys/sendto.c index 2dbf466360cd..60104ba2e5c7 100644 --- a/lib/libc/sys/sendto.c +++ b/lib/libc/sys/sendto.c @@ -41,9 +41,8 @@ ssize_t sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { - return (((ssize_t (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t)) - __libc_interposing[INTERPOS_sendto])(s, msg, len, flags, + __libsys_interposing[INTERPOS_sendto])(s, msg, len, flags, to, tolen)); } diff --git a/lib/libc/sys/setcontext.c b/lib/libc/sys/setcontext.c index 918377d61e66..734bd9c186fe 100644 --- a/lib/libc/sys/setcontext.c +++ b/lib/libc/sys/setcontext.c @@ -42,7 +42,6 @@ __sym_default(setcontext, setcontext, FBSD_1.2); int setcontext(const ucontext_t *uc) { - return (((int (*)(const ucontext_t *)) - __libc_interposing[INTERPOS_setcontext])(uc)); + __libsys_interposing[INTERPOS_setcontext])(uc)); } diff --git a/lib/libc/sys/sigaction.c b/lib/libc/sys/sigaction.c index 27f003e0eb48..4fa7b5d8699b 100644 --- a/lib/libc/sys/sigaction.c +++ b/lib/libc/sys/sigaction.c @@ -40,7 +40,6 @@ __weak_reference(sigaction, __libc_sigaction); int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) { - return (((int (*)(int, const struct sigaction *, struct sigaction *)) - __libc_interposing[INTERPOS_sigaction])(sig, act, oact)); + __libsys_interposing[INTERPOS_sigaction])(sig, act, oact)); } diff --git a/lib/libc/sys/sigprocmask.c b/lib/libc/sys/sigprocmask.c index 441cd2590c1f..c0d86de4b156 100644 --- a/lib/libc/sys/sigprocmask.c +++ b/lib/libc/sys/sigprocmask.c @@ -40,7 +40,6 @@ __weak_reference(sigprocmask, __libc_sigprocmask); int sigprocmask(int how, const sigset_t *set, sigset_t *oset) { - return (((int (*)(int, const sigset_t *, sigset_t *)) - __libc_interposing[INTERPOS_sigprocmask])(how, set, oset)); + __libsys_interposing[INTERPOS_sigprocmask])(how, set, oset)); } diff --git a/lib/libc/sys/sigsuspend.c b/lib/libc/sys/sigsuspend.c index 1de1e5e4089d..de57d645354d 100644 --- a/lib/libc/sys/sigsuspend.c +++ b/lib/libc/sys/sigsuspend.c @@ -40,7 +40,6 @@ __weak_reference(sigsuspend, __libc_sigsuspend); int sigsuspend(const sigset_t *set) { - return (((int (*)(const sigset_t *)) - __libc_interposing[INTERPOS_sigsuspend])(set)); + __libsys_interposing[INTERPOS_sigsuspend])(set)); } diff --git a/lib/libc/sys/sigtimedwait.c b/lib/libc/sys/sigtimedwait.c index 945a98e191ca..0cfcbb9811bc 100644 --- a/lib/libc/sys/sigtimedwait.c +++ b/lib/libc/sys/sigtimedwait.c @@ -40,8 +40,7 @@ int sigtimedwait(const sigset_t * __restrict set, siginfo_t * __restrict info, const struct timespec * __restrict t) { - return (((int (*)(const sigset_t *, siginfo_t *, const struct timespec *)) - __libc_interposing[INTERPOS_sigtimedwait])(set, info, t)); + __libsys_interposing[INTERPOS_sigtimedwait])(set, info, t)); } diff --git a/lib/libc/sys/sigwait.c b/lib/libc/sys/sigwait.c index 3ca16fb24102..4b863eb04db0 100644 --- a/lib/libc/sys/sigwait.c +++ b/lib/libc/sys/sigwait.c @@ -35,9 +35,8 @@ __weak_reference(__libc_sigwait, __sigwait); int sigwait(const sigset_t *set, int *sig) { - return (((int (*)(const sigset_t *, int *)) - __libc_interposing[INTERPOS_sigwait])(set, sig)); + __libsys_interposing[INTERPOS_sigwait])(set, sig)); } int diff --git a/lib/libc/sys/sigwaitinfo.c b/lib/libc/sys/sigwaitinfo.c index 06df1f67d0ef..277bd96a06a1 100644 --- a/lib/libc/sys/sigwaitinfo.c +++ b/lib/libc/sys/sigwaitinfo.c @@ -39,7 +39,6 @@ __weak_reference(__sys_sigwaitinfo, __sigwaitinfo); int sigwaitinfo(const sigset_t * __restrict set, siginfo_t * __restrict info) { - return (((int (*)(const sigset_t *, siginfo_t *)) - __libc_interposing[INTERPOS_sigwaitinfo])(set, info)); + __libsys_interposing[INTERPOS_sigwaitinfo])(set, info)); } diff --git a/lib/libc/sys/swapcontext.c b/lib/libc/sys/swapcontext.c index ea1942a31d5e..28f7c9f769a7 100644 --- a/lib/libc/sys/swapcontext.c +++ b/lib/libc/sys/swapcontext.c @@ -44,7 +44,6 @@ __sym_default(swapcontext, swapcontext, FBSD_1.2); int swapcontext(ucontext_t *oucp, const ucontext_t *ucp) { - return (((int (*)(ucontext_t *, const ucontext_t *)) - __libc_interposing[INTERPOS_swapcontext])(oucp, ucp)); + __libsys_interposing[INTERPOS_swapcontext])(oucp, ucp)); } diff --git a/lib/libc/sys/wait4.c b/lib/libc/sys/wait4.c index 2650b8932869..bbd866a8bb16 100644 --- a/lib/libc/sys/wait4.c +++ b/lib/libc/sys/wait4.c @@ -39,7 +39,6 @@ __weak_reference(__sys_wait4, __wait4); pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru) { - return (((pid_t (*)(pid_t, int *, int, struct rusage *)) - __libc_interposing[INTERPOS_wait4])(pid, status, options, ru)); + __libsys_interposing[INTERPOS_wait4])(pid, status, options, ru)); } diff --git a/lib/libc/sys/wait6.c b/lib/libc/sys/wait6.c index f2610813ee2b..eab11d4a6212 100644 --- a/lib/libc/sys/wait6.c +++ b/lib/libc/sys/wait6.c @@ -41,8 +41,7 @@ pid_t wait6(idtype_t idtype, id_t id, int *status, int options, struct __wrusage *ru, siginfo_t *infop) { - return (((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *, - siginfo_t *))__libc_interposing[INTERPOS_wait6])(idtype, id, + siginfo_t *))__libsys_interposing[INTERPOS_wait6])(idtype, id, status, options, ru, infop)); } diff --git a/lib/libc/sys/write.c b/lib/libc/sys/write.c index b974dd055a84..5bb372c2b8f4 100644 --- a/lib/libc/sys/write.c +++ b/lib/libc/sys/write.c @@ -40,7 +40,6 @@ __weak_reference(__sys_write, __write); ssize_t write(int fd, const void *buf, size_t nbytes) { - return (((ssize_t (*)(int, const void *, size_t)) - __libc_interposing[INTERPOS_write])(fd, buf, nbytes)); + __libsys_interposing[INTERPOS_write])(fd, buf, nbytes)); } diff --git a/lib/libc/sys/writev.c b/lib/libc/sys/writev.c index a56d9389ddcc..d311cb075e3c 100644 --- a/lib/libc/sys/writev.c +++ b/lib/libc/sys/writev.c @@ -41,7 +41,6 @@ __weak_reference(__sys_writev, __writev); ssize_t writev(int fd, const struct iovec *iov, int iovcnt) { - return (((ssize_t (*)(int, const struct iovec *, int)) - __libc_interposing[INTERPOS_writev])(fd, iov, iovcnt)); + __libsys_interposing[INTERPOS_writev])(fd, iov, iovcnt)); } diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c index d68ca60e5993..31b686c1d064 100644 --- a/lib/libthr/thread/thr_syscalls.c +++ b/lib/libthr/thread/thr_syscalls.c @@ -644,6 +644,16 @@ __thr_interpose_libc(void) #define SLOT(name) \ *(__libc_interposing_slot(INTERPOS_##name)) = \ (interpos_func_t)__thr_##name; + SLOT(system); + SLOT(tcdrain); + SLOT(spinlock); + SLOT(spinunlock); + SLOT(map_stacks_exec); +#undef SLOT + +#define SLOT(name) \ + *(__libsys_interposing_slot(INTERPOS_##name)) = \ + (interpos_func_t)__thr_##name; SLOT(accept); SLOT(accept4); SLOT(aio_suspend); @@ -672,17 +682,12 @@ __thr_interpose_libc(void) SLOT(sigtimedwait); SLOT(sigwaitinfo); SLOT(swapcontext); - SLOT(system); - SLOT(tcdrain); SLOT(wait4); SLOT(write); SLOT(writev); - SLOT(spinlock); - SLOT(spinunlock); SLOT(kevent); SLOT(wait6); SLOT(ppoll); - SLOT(map_stacks_exec); SLOT(fdatasync); SLOT(clock_nanosleep); SLOT(pdfork);