summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-24 22:57:37 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-24 23:08:09 +0200
commitd4195672b7571e105cd9fb3891334d8c734ae775 (patch)
tree6c2797a945aa3fd8f88d31fb9ea9bbb443bb89a4 /Libraries
parentcd02144a06d4b648effdb744e00b664a871bf52b (diff)
downloadserenity-d4195672b7571e105cd9fb3891334d8c734ae775.zip
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. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/sys/socket.cpp12
-rw-r--r--Libraries/LibC/sys/socket.h2
2 files changed, 14 insertions, 0 deletions
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, &params);
__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