From d4195672b7571e105cd9fb3891334d8c734ae775 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 24 Jun 2020 22:57:37 +0200 Subject: Kernel+LibC: Add sys$recvfd() and sys$sendfd() for fd passing These new syscalls allow you to send and receive file descriptors over a local domain socket. This will enable various privilege separation techniques and other good stuff. :^) --- Libraries/LibC/sys/socket.cpp | 12 ++++++++++++ Libraries/LibC/sys/socket.h | 2 ++ 2 files changed, 14 insertions(+) (limited to 'Libraries') diff --git a/Libraries/LibC/sys/socket.cpp b/Libraries/LibC/sys/socket.cpp index 81e83aaed7..62e27a20f8 100644 --- a/Libraries/LibC/sys/socket.cpp +++ b/Libraries/LibC/sys/socket.cpp @@ -119,4 +119,16 @@ int getpeername(int sockfd, struct sockaddr* addr, socklen_t* addrlen) int rc = syscall(SC_getpeername, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } + +int sendfd(int sockfd, int fd) +{ + int rc = syscall(SC_sendfd, sockfd, fd); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + +int recvfd(int sockfd) +{ + int rc = syscall(SC_recvfd, sockfd); + __RETURN_WITH_ERRNO(rc, rc, -1); +} } diff --git a/Libraries/LibC/sys/socket.h b/Libraries/LibC/sys/socket.h index 2e98f47865..269158beb1 100644 --- a/Libraries/LibC/sys/socket.h +++ b/Libraries/LibC/sys/socket.h @@ -100,5 +100,7 @@ int getsockopt(int sockfd, int level, int option, void*, socklen_t*); int setsockopt(int sockfd, int level, int option, const void*, socklen_t); int getsockname(int sockfd, struct sockaddr*, socklen_t*); int getpeername(int sockfd, struct sockaddr*, socklen_t*); +int sendfd(int sockfd, int fd); +int recvfd(int sockfd); __END_DECLS -- cgit v1.2.3