git: 7dd9070e4425 - main - libc: INTERPOS_SYS macro for interposed syscalls

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Tue, 16 Apr 2024 16:48:23 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=7dd9070e4425a1c2e2418694fd632425a283d558

commit 7dd9070e4425a1c2e2418694fd632425a283d558
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2024-04-16 16:48:08 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2024-04-16 16:48:08 +0000

    libc: INTERPOS_SYS macro for interposed syscalls
    
    This macro makes uses the __sys_<foo>_t typedefs from libsys.h to
    greatly simplify calling functions in the interposing table.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D44389
---
 lib/libc/gen/sleep.c            | 4 +---
 lib/libc/gen/usleep.c           | 4 +---
 lib/libc/include/libc_private.h | 6 ++++++
 lib/libc/sys/accept.c           | 3 +--
 lib/libc/sys/accept4.c          | 4 +---
 lib/libc/sys/aio_suspend.c      | 5 +----
 lib/libc/sys/clock_nanosleep.c  | 5 +----
 lib/libc/sys/close.c            | 2 +-
 lib/libc/sys/connect.c          | 3 +--
 lib/libc/sys/creat.c            | 5 ++---
 lib/libc/sys/fcntl.c            | 3 +--
 lib/libc/sys/fdatasync.c        | 3 +--
 lib/libc/sys/fork.c             | 2 +-
 lib/libc/sys/fsync.c            | 2 +-
 lib/libc/sys/kevent.c           | 6 ++----
 lib/libc/sys/lockf.c            | 3 +--
 lib/libc/sys/msync.c            | 3 +--
 lib/libc/sys/nanosleep.c        | 3 +--
 lib/libc/sys/open.c             | 4 +---
 lib/libc/sys/openat.c           | 4 +---
 lib/libc/sys/pdfork.c           | 4 +---
 lib/libc/sys/poll.c             | 3 +--
 lib/libc/sys/ppoll.c            | 4 +---
 lib/libc/sys/pselect.c          | 4 +---
 lib/libc/sys/read.c             | 3 +--
 lib/libc/sys/readv.c            | 3 +--
 lib/libc/sys/recv.c             | 5 +----
 lib/libc/sys/recvfrom.c         | 5 +----
 lib/libc/sys/recvmsg.c          | 3 +--
 lib/libc/sys/select.c           | 3 +--
 lib/libc/sys/send.c             | 5 +----
 lib/libc/sys/sendmsg.c          | 3 +--
 lib/libc/sys/sendto.c           | 5 +----
 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     | 4 +---
 lib/libc/sys/sigwait.c          | 3 +--
 lib/libc/sys/sigwaitinfo.c      | 3 +--
 lib/libc/sys/swapcontext.c      | 3 +--
 lib/libc/sys/wait.c             | 4 +---
 lib/libc/sys/wait3.c            | 4 +---
 lib/libc/sys/wait4.c            | 4 +---
 lib/libc/sys/wait6.c            | 4 +---
 lib/libc/sys/waitid.c           | 4 +---
 lib/libc/sys/waitpid.c          | 4 +---
 lib/libc/sys/write.c            | 3 +--
 lib/libc/sys/writev.c           | 3 +--
 49 files changed, 56 insertions(+), 123 deletions(-)

diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c
index 7b6e80353c6e..e32d434d4d33 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -55,9 +55,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_slot(INTERPOS_nanosleep)))(
-	    &time_to_sleep, &time_remaining) != -1)
+	if (INTERPOS_SYS(nanosleep, &time_to_sleep, &time_remaining) != -1)
 		return (0);
 	if (errno != EINTR)
 		return (seconds);		/* best guess */
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c
index f58d81d978e3..31d5567d562d 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -45,9 +45,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_slot(INTERPOS_nanosleep)))(&time_to_sleep,
-	    NULL));
+	return (INTERPOS_SYS(nanosleep, &time_to_sleep, NULL));
 }
 
 __weak_reference(__usleep, usleep);
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index b38603b59a88..73b22beffe88 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -252,6 +252,12 @@ enum {
 	INTERPOS_MAX
 };
 
+#define	_INTERPOS_SYS(type, idx, ...)				\
+    ((type *)*(__libc_interposing_slot(idx)))(__VA_ARGS__)
+#define	INTERPOS_SYS(syscall, ...)				\
+    _INTERPOS_SYS(__sys_## syscall ##_t, INTERPOS_## syscall	\
+    __VA_OPT__(,) __VA_ARGS__)
+
 /*
  * yplib internal interfaces
  */
diff --git a/lib/libc/sys/accept.c b/lib/libc/sys/accept.c
index 609cb31b140e..95c8b4a58c74 100644
--- a/lib/libc/sys/accept.c
+++ b/lib/libc/sys/accept.c
@@ -40,6 +40,5 @@ __weak_reference(__sys_accept, __accept);
 int
 accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 {
-	return (((int (*)(int, struct sockaddr *, socklen_t *))
-	    *(__libc_interposing_slot(INTERPOS_accept)))(s, addr, addrlen));
+	return (INTERPOS_SYS(accept, s, addr, addrlen));
 }
diff --git a/lib/libc/sys/accept4.c b/lib/libc/sys/accept4.c
index c789d0a63250..1a1f75c9f528 100644
--- a/lib/libc/sys/accept4.c
+++ b/lib/libc/sys/accept4.c
@@ -40,7 +40,5 @@ __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_slot(INTERPOS_accept4)))
-	    (s, addr, addrlen, flags));
+	return (INTERPOS_SYS(accept4, s, addr, addrlen, flags));
 }
diff --git a/lib/libc/sys/aio_suspend.c b/lib/libc/sys/aio_suspend.c
index 499d2a349c3c..592cb5b0e1d7 100644
--- a/lib/libc/sys/aio_suspend.c
+++ b/lib/libc/sys/aio_suspend.c
@@ -40,8 +40,5 @@ 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_slot(INTERPOS_aio_suspend)))
-	    (iocbs, niocb, timeout));
+	return (INTERPOS_SYS(aio_suspend, iocbs, niocb, timeout));
 }
diff --git a/lib/libc/sys/clock_nanosleep.c b/lib/libc/sys/clock_nanosleep.c
index ad996220d19f..a50af30e1fb3 100644
--- a/lib/libc/sys/clock_nanosleep.c
+++ b/lib/libc/sys/clock_nanosleep.c
@@ -41,8 +41,5 @@ 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_slot(INTERPOS_clock_nanosleep)))
-	    (clock_id, flags, rqtp, rmtp));
+	return (INTERPOS_SYS(clock_nanosleep, clock_id, flags, rqtp, rmtp));
 }
diff --git a/lib/libc/sys/close.c b/lib/libc/sys/close.c
index 5017f6e3d745..08a5419361a9 100644
--- a/lib/libc/sys/close.c
+++ b/lib/libc/sys/close.c
@@ -40,5 +40,5 @@ __weak_reference(__sys_close, __close);
 int
 close(int fd)
 {
-	return (((int (*)(int))*(__libc_interposing_slot(INTERPOS_close)))(fd));
+	return (INTERPOS_SYS(close, fd));
 }
diff --git a/lib/libc/sys/connect.c b/lib/libc/sys/connect.c
index 70fc4682b06d..e64451683abc 100644
--- a/lib/libc/sys/connect.c
+++ b/lib/libc/sys/connect.c
@@ -40,6 +40,5 @@ __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_slot(INTERPOS_connect)))(s, addr, addrlen));
+	return (INTERPOS_SYS(connect, s, addr, addrlen));
 }
diff --git a/lib/libc/sys/creat.c b/lib/libc/sys/creat.c
index bcb750e93d38..afd626e928bb 100644
--- a/lib/libc/sys/creat.c
+++ b/lib/libc/sys/creat.c
@@ -43,8 +43,7 @@ int __creat(const char *path, mode_t mode);
 int
 __creat(const char *path, mode_t mode)
 {
-	return (((int (*)(int, const char *, int, ...))
-	    *(__libc_interposing_slot(INTERPOS_openat)))
-	    (AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode));
+	return (INTERPOS_SYS(openat, AT_FDCWD, path,
+	    O_WRONLY | O_CREAT | O_TRUNC, mode));
 }
 
diff --git a/lib/libc/sys/fcntl.c b/lib/libc/sys/fcntl.c
index 308d144a4426..fc225fdeb379 100644
--- a/lib/libc/sys/fcntl.c
+++ b/lib/libc/sys/fcntl.c
@@ -49,6 +49,5 @@ fcntl(int fd, int cmd, ...)
 	arg = va_arg(args, long);
 	va_end(args);
 
-	return (((int (*)(int, int, ...))
-	    *(__libc_interposing_slot(INTERPOS_fcntl)))(fd, cmd, arg));
+	return (INTERPOS_SYS(fcntl, fd, cmd, arg));
 }
diff --git a/lib/libc/sys/fdatasync.c b/lib/libc/sys/fdatasync.c
index 2dd81ec1a215..15cef821dc1e 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_slot(INTERPOS_fdatasync)))
-	    (fd));
+	return (INTERPOS_SYS(fdatasync, fd));
 }
diff --git a/lib/libc/sys/fork.c b/lib/libc/sys/fork.c
index 1c70c2587c32..e907c51b5cee 100644
--- a/lib/libc/sys/fork.c
+++ b/lib/libc/sys/fork.c
@@ -39,5 +39,5 @@ __weak_reference(__sys_fork, __fork);
 pid_t
 fork(void)
 {
-	return (((pid_t (*)(void))*(__libc_interposing_slot(INTERPOS_fork)))());
+	return (INTERPOS_SYS(fork));
 }
diff --git a/lib/libc/sys/fsync.c b/lib/libc/sys/fsync.c
index aa33bbdf69e7..e542c8cdea48 100644
--- a/lib/libc/sys/fsync.c
+++ b/lib/libc/sys/fsync.c
@@ -39,5 +39,5 @@ __weak_reference(__sys_fsync, __fsync);
 int
 fsync(int fd)
 {
-	return (((int (*)(int))*(__libc_interposing_slot(INTERPOS_fsync)))(fd));
+	return (INTERPOS_SYS(fsync, fd));
 }
diff --git a/lib/libc/sys/kevent.c b/lib/libc/sys/kevent.c
index e81bcabc568a..f16ac89a36c6 100644
--- a/lib/libc/sys/kevent.c
+++ b/lib/libc/sys/kevent.c
@@ -41,8 +41,6 @@ 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_slot(INTERPOS_kevent)))
-	    (kq, changelist, nchanges, eventlist, nevents, timeout));
+	return (INTERPOS_SYS(kevent, kq, changelist, nchanges, eventlist,
+	    nevents, timeout));
 }
diff --git a/lib/libc/sys/lockf.c b/lib/libc/sys/lockf.c
index 3701cebbc190..6211275e5f16 100644
--- a/lib/libc/sys/lockf.c
+++ b/lib/libc/sys/lockf.c
@@ -78,6 +78,5 @@ lockf(int filedes, int function, off_t size)
 		/* NOTREACHED */
 	}
 
-	return (((int (*)(int, int, ...))
-	    *(__libc_interposing_slot(INTERPOS_fcntl)))(filedes, cmd, &fl));
+	return (INTERPOS_SYS(fcntl, filedes, cmd, (intptr_t)&fl));
 }
diff --git a/lib/libc/sys/msync.c b/lib/libc/sys/msync.c
index bda60db5c333..f825db97b947 100644
--- a/lib/libc/sys/msync.c
+++ b/lib/libc/sys/msync.c
@@ -40,6 +40,5 @@ __weak_reference(__sys_msync, __msync);
 int
 msync(void *addr, size_t len, int flags)
 {
-	return (((int (*)(void *, size_t, int))
-	    *(__libc_interposing_slot(INTERPOS_msync)))(addr, len, flags));
+	return (INTERPOS_SYS(msync, addr, len, flags));
 }
diff --git a/lib/libc/sys/nanosleep.c b/lib/libc/sys/nanosleep.c
index daa4784363db..bd0794c3af8e 100644
--- a/lib/libc/sys/nanosleep.c
+++ b/lib/libc/sys/nanosleep.c
@@ -39,6 +39,5 @@ __weak_reference(__sys_nanosleep, __nanosleep);
 int
 nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
 {
-	return (((int (*)(const struct timespec *, struct timespec *))
-	    *(__libc_interposing_slot(INTERPOS_nanosleep)))(rqtp, rmtp));
+	return (INTERPOS_SYS(nanosleep, rqtp, rmtp));
 }
diff --git a/lib/libc/sys/open.c b/lib/libc/sys/open.c
index 6ea18727c876..57c07637d2aa 100644
--- a/lib/libc/sys/open.c
+++ b/lib/libc/sys/open.c
@@ -50,7 +50,5 @@ open(const char *path, int flags, ...)
 	} else {
 		mode = 0;
 	}
-	return (((int (*)(int, const char *, int, ...))
-	    *(__libc_interposing_slot(INTERPOS_openat)))
-	    (AT_FDCWD, path, flags, mode));
+	return (INTERPOS_SYS(openat, AT_FDCWD, path, flags, mode));
 }
diff --git a/lib/libc/sys/openat.c b/lib/libc/sys/openat.c
index d49aafe35e62..1cd8e7d90745 100644
--- a/lib/libc/sys/openat.c
+++ b/lib/libc/sys/openat.c
@@ -53,7 +53,5 @@ openat(int fd, const char *path, int flags, ...)
 	} else {
 		mode = 0;
 	}
-	return (((int (*)(int, const char *, int, ...))
-	    *(__libc_interposing_slot(INTERPOS_openat)))
-	    (fd, path, flags, mode));
+	return (INTERPOS_SYS(openat, fd, path, flags, mode));
 }
diff --git a/lib/libc/sys/pdfork.c b/lib/libc/sys/pdfork.c
index 6830d878b414..f25f081ec174 100644
--- a/lib/libc/sys/pdfork.c
+++ b/lib/libc/sys/pdfork.c
@@ -37,7 +37,5 @@
 pid_t
 pdfork(int *fdp, int flags)
 {
-	return (((pid_t (*)(int *, int))
-	    *(__libc_interposing_slot(INTERPOS_pdfork)))
-	    (fdp, flags));
+	return (INTERPOS_SYS(pdfork, fdp, flags));
 }
diff --git a/lib/libc/sys/poll.c b/lib/libc/sys/poll.c
index 93b0e1b3c8ed..6528603e7603 100644
--- a/lib/libc/sys/poll.c
+++ b/lib/libc/sys/poll.c
@@ -39,6 +39,5 @@ __weak_reference(__sys_poll, __poll);
 int
 poll(struct pollfd pfd[], nfds_t nfds, int timeout)
 {
-	return (((int (*)(struct pollfd *, nfds_t, int))
-	    *(__libc_interposing_slot(INTERPOS_poll)))(pfd, nfds, timeout));
+	return (INTERPOS_SYS(poll, pfd, nfds, timeout));
 }
diff --git a/lib/libc/sys/ppoll.c b/lib/libc/sys/ppoll.c
index 50e83975da2a..52c4c177cf0a 100644
--- a/lib/libc/sys/ppoll.c
+++ b/lib/libc/sys/ppoll.c
@@ -40,7 +40,5 @@ 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_slot(INTERPOS_ppoll)))
-	    (pfd, nfds, timeout, newsigmask));
+	return (INTERPOS_SYS(ppoll, pfd, nfds, timeout, newsigmask));
 }
diff --git a/lib/libc/sys/pselect.c b/lib/libc/sys/pselect.c
index a7776049013f..38477e39af44 100644
--- a/lib/libc/sys/pselect.c
+++ b/lib/libc/sys/pselect.c
@@ -40,7 +40,5 @@ 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_slot(INTERPOS_pselect)))(n, rs, ws, es, t, s));
+	return (INTERPOS_SYS(pselect, n, rs, ws, es, t, s));
 }
diff --git a/lib/libc/sys/read.c b/lib/libc/sys/read.c
index 2b8185975a6a..b4610e0c38c3 100644
--- a/lib/libc/sys/read.c
+++ b/lib/libc/sys/read.c
@@ -40,6 +40,5 @@ __weak_reference(__sys_read, __read);
 ssize_t
 read(int fd, void *buf, size_t nbytes)
 {
-	return (((ssize_t (*)(int, void *, size_t))
-	    *(__libc_interposing_slot(INTERPOS_read)))(fd, buf, nbytes));
+	return (INTERPOS_SYS(read, fd, buf, nbytes));
 }
diff --git a/lib/libc/sys/readv.c b/lib/libc/sys/readv.c
index 62a8fa976e2b..78a529254fa0 100644
--- a/lib/libc/sys/readv.c
+++ b/lib/libc/sys/readv.c
@@ -41,6 +41,5 @@ __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_slot(INTERPOS_readv)))(fd, iov, iovcnt));
+	return (INTERPOS_SYS(readv, fd, iov, iovcnt));
 }
diff --git a/lib/libc/sys/recv.c b/lib/libc/sys/recv.c
index 21caf2f841f6..9afb1dee0654 100644
--- a/lib/libc/sys/recv.c
+++ b/lib/libc/sys/recv.c
@@ -42,8 +42,5 @@ recv(int s, void *buf, size_t len, int flags)
 	 * POSIX says recv() shall be a cancellation point, so call the
 	 * cancellation-enabled recvfrom() and not _recvfrom().
 	 */
-	return (((ssize_t (*)(int, void *, size_t, int,
-	    struct sockaddr *, socklen_t *))
-	    *(__libc_interposing_slot(INTERPOS_recvfrom)))
-	    (s, buf, len, flags, NULL, NULL));
+	return (INTERPOS_SYS(recvfrom, s, buf, len, flags, NULL, NULL));
 }
diff --git a/lib/libc/sys/recvfrom.c b/lib/libc/sys/recvfrom.c
index 0bb3c4c3b719..04738d06a71c 100644
--- a/lib/libc/sys/recvfrom.c
+++ b/lib/libc/sys/recvfrom.c
@@ -41,8 +41,5 @@ 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_slot(INTERPOS_recvfrom)))
-	    (s, buf, len, flags, from, fromlen));
+	return (INTERPOS_SYS(recvfrom, s, buf, len, flags, from, fromlen));
 }
diff --git a/lib/libc/sys/recvmsg.c b/lib/libc/sys/recvmsg.c
index c8d631ebe56e..c7e34b9beeb4 100644
--- a/lib/libc/sys/recvmsg.c
+++ b/lib/libc/sys/recvmsg.c
@@ -40,6 +40,5 @@ __weak_reference(__sys_recvmsg, __recvmsg);
 ssize_t
 recvmsg(int s, struct msghdr *msg, int flags)
 {
-	return (((int (*)(int, struct msghdr *, int))
-	    *(__libc_interposing_slot(INTERPOS_recvmsg)))(s, msg, flags));
+	return (INTERPOS_SYS(recvmsg, s, msg, flags));
 }
diff --git a/lib/libc/sys/select.c b/lib/libc/sys/select.c
index 27f4ff10a1bb..bbbcfc8bf1e0 100644
--- a/lib/libc/sys/select.c
+++ b/lib/libc/sys/select.c
@@ -39,6 +39,5 @@ __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_slot(INTERPOS_select)))(n, rs, ws, es, t));
+	return (INTERPOS_SYS(select, n, rs, ws, es, t));
 }
diff --git a/lib/libc/sys/send.c b/lib/libc/sys/send.c
index 4e945f969a65..82715c1b880b 100644
--- a/lib/libc/sys/send.c
+++ b/lib/libc/sys/send.c
@@ -42,8 +42,5 @@ send(int s, const void *msg, size_t len, int flags)
 	 * POSIX says send() shall be a cancellation point, so call the
 	 * cancellation-enabled sendto() and not _sendto().
 	 */
-	return (((ssize_t (*)(int, const void *, size_t, int,
-	    const struct sockaddr *, socklen_t))
-	    *__libc_interposing_slot(INTERPOS_sendto))(s, msg, len, flags,
-	    NULL, 0));
+	return (INTERPOS_SYS(sendto, s, msg, len, flags, NULL, 0));
 }
diff --git a/lib/libc/sys/sendmsg.c b/lib/libc/sys/sendmsg.c
index 488e0c736801..fd4e41837c48 100644
--- a/lib/libc/sys/sendmsg.c
+++ b/lib/libc/sys/sendmsg.c
@@ -40,6 +40,5 @@ __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_slot(INTERPOS_sendmsg)))(s, msg, flags));
+	return (INTERPOS_SYS(sendmsg, s, msg, flags));
 }
diff --git a/lib/libc/sys/sendto.c b/lib/libc/sys/sendto.c
index 93d336cfca11..708fc6ec9368 100644
--- a/lib/libc/sys/sendto.c
+++ b/lib/libc/sys/sendto.c
@@ -41,8 +41,5 @@ 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_slot(INTERPOS_sendto)))
-	    (s, msg, len, flags, to, tolen));
+	return (INTERPOS_SYS(sendto, s, msg, len, flags, to, tolen));
 }
diff --git a/lib/libc/sys/setcontext.c b/lib/libc/sys/setcontext.c
index e54d4ba82395..96b5dc115067 100644
--- a/lib/libc/sys/setcontext.c
+++ b/lib/libc/sys/setcontext.c
@@ -42,6 +42,5 @@ __sym_default(setcontext, setcontext, FBSD_1.2);
 int
 setcontext(const ucontext_t *uc)
 {
-	return (((int (*)(const ucontext_t *))
-	    *(__libc_interposing_slot(INTERPOS_setcontext)))(uc));
+	return (INTERPOS_SYS(setcontext, uc));
 }
diff --git a/lib/libc/sys/sigaction.c b/lib/libc/sys/sigaction.c
index 07593a4e540d..809881ca4d3f 100644
--- a/lib/libc/sys/sigaction.c
+++ b/lib/libc/sys/sigaction.c
@@ -40,6 +40,5 @@ __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_slot(INTERPOS_sigaction)))(sig, act, oact));
+	return (INTERPOS_SYS(sigaction, sig, act, oact));
 }
diff --git a/lib/libc/sys/sigprocmask.c b/lib/libc/sys/sigprocmask.c
index 6b20065ff6d1..96cb9586509b 100644
--- a/lib/libc/sys/sigprocmask.c
+++ b/lib/libc/sys/sigprocmask.c
@@ -40,6 +40,5 @@ __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_slot(INTERPOS_sigprocmask)))(how, set, oset));
+	return (INTERPOS_SYS(sigprocmask, how, set, oset));
 }
diff --git a/lib/libc/sys/sigsuspend.c b/lib/libc/sys/sigsuspend.c
index 32125eb846be..e5a9495f9f39 100644
--- a/lib/libc/sys/sigsuspend.c
+++ b/lib/libc/sys/sigsuspend.c
@@ -40,6 +40,5 @@ __weak_reference(sigsuspend, __libc_sigsuspend);
 int
 sigsuspend(const sigset_t *set)
 {
-	return (((int (*)(const sigset_t *))
-	    *(__libc_interposing_slot(INTERPOS_sigsuspend)))(set));
+	return (INTERPOS_SYS(sigsuspend, set));
 }
diff --git a/lib/libc/sys/sigtimedwait.c b/lib/libc/sys/sigtimedwait.c
index 4b449407e754..839e5fe4d992 100644
--- a/lib/libc/sys/sigtimedwait.c
+++ b/lib/libc/sys/sigtimedwait.c
@@ -40,7 +40,5 @@ 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_slot(INTERPOS_sigtimedwait)))(set, info, t));
+	return (INTERPOS_SYS(sigtimedwait, set, info, t));
 }
diff --git a/lib/libc/sys/sigwait.c b/lib/libc/sys/sigwait.c
index 23c341461639..5a7d71bf3ed9 100644
--- a/lib/libc/sys/sigwait.c
+++ b/lib/libc/sys/sigwait.c
@@ -32,6 +32,5 @@
 int
 sigwait(const sigset_t *set, int *sig)
 {
-	return (((int (*)(const sigset_t *, int *))
-	    *(__libc_interposing_slot(INTERPOS_sigwait)))(set, sig));
+	return (INTERPOS_SYS(sigwait, set, sig));
 }
diff --git a/lib/libc/sys/sigwaitinfo.c b/lib/libc/sys/sigwaitinfo.c
index d8a0780441d1..611d09c3c221 100644
--- a/lib/libc/sys/sigwaitinfo.c
+++ b/lib/libc/sys/sigwaitinfo.c
@@ -39,6 +39,5 @@ __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_slot(INTERPOS_sigwaitinfo)))(set, info));
+	return (INTERPOS_SYS(sigwaitinfo, set, info));
 }
diff --git a/lib/libc/sys/swapcontext.c b/lib/libc/sys/swapcontext.c
index 0793dd838526..b69a5b19e698 100644
--- a/lib/libc/sys/swapcontext.c
+++ b/lib/libc/sys/swapcontext.c
@@ -44,6 +44,5 @@ __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_slot(INTERPOS_swapcontext)))(oucp, ucp));
+	return (INTERPOS_SYS(swapcontext, oucp, ucp));
 }
diff --git a/lib/libc/sys/wait.c b/lib/libc/sys/wait.c
index 7c847a616003..6678ecc522ba 100644
--- a/lib/libc/sys/wait.c
+++ b/lib/libc/sys/wait.c
@@ -43,9 +43,7 @@ pid_t __wait(int *);
 pid_t
 __wait(int *istat)
 {
-	return (((pid_t (*)(pid_t, int *, int, struct rusage *))
-	    *(__libc_interposing_slot(INTERPOS_wait4)))
-	    (WAIT_ANY, istat, 0, NULL));
+	return (INTERPOS_SYS(wait4, WAIT_ANY, istat, 0, NULL));
 }
 
 __weak_reference(__wait, wait);
diff --git a/lib/libc/sys/wait3.c b/lib/libc/sys/wait3.c
index 5d7d7bc22a67..4e98ccff5227 100644
--- a/lib/libc/sys/wait3.c
+++ b/lib/libc/sys/wait3.c
@@ -43,9 +43,7 @@ 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_slot(INTERPOS_wait4)))
-	    (WAIT_ANY, istat, options, rup));
+	return (INTERPOS_SYS(wait4, WAIT_ANY, istat, options, rup));
 }
 
 __weak_reference(__wait3, wait3);
diff --git a/lib/libc/sys/wait4.c b/lib/libc/sys/wait4.c
index eab2e9b6e2c0..57b0071ef87f 100644
--- a/lib/libc/sys/wait4.c
+++ b/lib/libc/sys/wait4.c
@@ -39,7 +39,5 @@ __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_slot(INTERPOS_wait4)))
-	    (pid, status, options, ru));
+	return (INTERPOS_SYS(wait4, pid, status, options, ru));
 }
diff --git a/lib/libc/sys/wait6.c b/lib/libc/sys/wait6.c
index eff40eae3b76..118a7ef6b99e 100644
--- a/lib/libc/sys/wait6.c
+++ b/lib/libc/sys/wait6.c
@@ -41,7 +41,5 @@ 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_slot(INTERPOS_wait6)))
-	    (idtype, id, status, options, ru, infop));
+	return (INTERPOS_SYS(wait6, idtype, id, status, options, ru, infop));
 }
diff --git a/lib/libc/sys/waitid.c b/lib/libc/sys/waitid.c
index f885e8f55912..334f25e99bb6 100644
--- a/lib/libc/sys/waitid.c
+++ b/lib/libc/sys/waitid.c
@@ -46,9 +46,7 @@ __waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
 	int status;
 	pid_t ret;
 
-	ret = ((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *,
-	    siginfo_t *))*(__libc_interposing_slot(INTERPOS_wait6)))
-	    (idtype, id, &status, flags, NULL, info);
+	ret = INTERPOS_SYS(wait6, idtype, id, &status, flags, NULL, info);
 
 	/*
 	 * According to SUSv4, waitid() shall not return a PID when a
diff --git a/lib/libc/sys/waitpid.c b/lib/libc/sys/waitpid.c
index 971c598d6a93..d8fdcec23a1c 100644
--- a/lib/libc/sys/waitpid.c
+++ b/lib/libc/sys/waitpid.c
@@ -43,9 +43,7 @@ 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_slot(INTERPOS_wait4)))
-	    (pid, istat, options, NULL));
+	return (INTERPOS_SYS(wait4, pid, istat, options, NULL));
 }
 
 __weak_reference(__waitpid, waitpid);
diff --git a/lib/libc/sys/write.c b/lib/libc/sys/write.c
index c2050374431b..5880856b8af8 100644
--- a/lib/libc/sys/write.c
+++ b/lib/libc/sys/write.c
@@ -40,6 +40,5 @@ __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_slot(INTERPOS_write)))(fd, buf, nbytes));
+	return (INTERPOS_SYS(write, fd, buf, nbytes));
 }
diff --git a/lib/libc/sys/writev.c b/lib/libc/sys/writev.c
index 40f6f2f211ae..9a32cb603ab8 100644
--- a/lib/libc/sys/writev.c
+++ b/lib/libc/sys/writev.c
@@ -41,6 +41,5 @@ __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_slot(INTERPOS_writev)))(fd, iov, iovcnt));
+	return (INTERPOS_SYS(writev, fd, iov, iovcnt));
 }