[libc-commits] [libc] 5366692 - [libc] Remove legacy SYS_socketcall fallbacks (#197189)
via libc-commits
libc-commits at lists.llvm.org
Thu May 14 05:12:01 PDT 2026
Author: Pavel Labath
Date: 2026-05-14T12:11:56Z
New Revision: 5366692aeefd1101cb8dfde7fb65c9565b476d96
URL: https://github.com/llvm/llvm-project/commit/5366692aeefd1101cb8dfde7fb65c9565b476d96
DIFF: https://github.com/llvm/llvm-project/commit/5366692aeefd1101cb8dfde7fb65c9565b476d96.diff
LOG: [libc] Remove legacy SYS_socketcall fallbacks (#197189)
This patch removes legacy SYS_socketcall fallback paths from all Linux
socket entry points. The individual syscall entry points were
[added](https://github.com/torvalds/linux/commit/9dea5dc921b5f4045a18c63eb92e84dc274d17eb)
in linux 4.3 (on x86, other architectures have had them even sooner).
Our policy is to support the lowest kernel version on
https://kernel.org/, which is 5.10 as of this writing.
This is motivated by the problems in
[testing](https://github.com/llvm/llvm-project/pull/196903#pullrequestreview-4263553670)
the fallback paths -- to make sure this even builds, one needs to get a
hold of very old kernel headers, or otherwise hack its build to force it
to select the fallback path.
New ABIs don't have the accept syscall (only accept4), so I've added an
accept->accept4 fallback.
Assisted by Gemini.
Added:
Modified:
libc/src/__support/OSUtil/linux/syscall_wrappers/accept.h
libc/src/__support/OSUtil/linux/syscall_wrappers/accept4.h
libc/src/__support/OSUtil/linux/syscall_wrappers/connect.h
libc/src/__support/OSUtil/linux/syscall_wrappers/getsockopt.h
libc/src/__support/OSUtil/linux/syscall_wrappers/listen.h
libc/src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h
libc/src/__support/OSUtil/linux/syscall_wrappers/shutdown.h
libc/src/sys/socket/linux/bind.cpp
libc/src/sys/socket/linux/recv.cpp
libc/src/sys/socket/linux/recvfrom.cpp
libc/src/sys/socket/linux/recvmsg.cpp
libc/src/sys/socket/linux/send.cpp
libc/src/sys/socket/linux/sendmsg.cpp
libc/src/sys/socket/linux/sendto.cpp
libc/src/sys/socket/linux/socket.cpp
libc/src/sys/socket/linux/socketpair.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/accept.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/accept.h
index e661f4df1daab..b25f0fac1f071 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/accept.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/accept.h
@@ -16,7 +16,6 @@
#include "hdr/types/socklen_t.h"
#include "hdr/types/struct_sockaddr.h"
-#include <linux/net.h> // For SYS_ACCEPT socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -24,17 +23,12 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> accept(int sockfd, struct sockaddr *addr,
socklen_t *addrlen) {
-#ifdef SYS_accept
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_accept, sockfd, addr, addrlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(addr),
- reinterpret_cast<unsigned long>(addrlen)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_ACCEPT,
- sockcall_args);
+#if defined(SYS_accept)
+ int ret = syscall_impl<int>(SYS_accept, sockfd, addr, addrlen);
+#elif defined(SYS_accept4)
+ int ret = syscall_impl<int>(SYS_accept4, sockfd, addr, addrlen, 0);
#else
-#error "accept and socketcall syscalls unavailable for this platform."
+#error "accept and accept4 syscalls unavailable for this platform."
#endif
if (ret < 0)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/accept4.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/accept4.h
index ebe82f189af50..69c316fb72766 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/accept4.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/accept4.h
@@ -16,7 +16,6 @@
#include "hdr/types/socklen_t.h"
#include "hdr/types/struct_sockaddr.h"
-#include <linux/net.h> // For SYS_ACCEPT4 socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -24,20 +23,7 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> accept4(int sockfd, struct sockaddr *addr,
socklen_t *addrlen, int flags) {
-#ifdef SYS_accept4
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_accept4, sockfd, addr,
- addrlen, flags);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[4] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(addr),
- reinterpret_cast<unsigned long>(addrlen),
- static_cast<unsigned long>(flags)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_ACCEPT4,
- sockcall_args);
-#else
-#error "accept4 and socketcall syscalls unavailable for this platform."
-#endif
-
+ int ret = syscall_impl<int>(SYS_accept4, sockfd, addr, addrlen, flags);
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/connect.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/connect.h
index 6974546630b00..9ddc4674e4d9f 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/connect.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/connect.h
@@ -16,7 +16,6 @@
#include "hdr/types/socklen_t.h"
#include "hdr/types/struct_sockaddr.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -24,19 +23,7 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> connect(int sockfd, const struct sockaddr *addr,
socklen_t addrlen) {
-#ifdef SYS_connect
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_connect, sockfd, addr, addrlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(addr),
- static_cast<unsigned long>(addrlen)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_CONNECT,
- sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
-
+ int ret = syscall_impl<int>(SYS_connect, sockfd, addr, addrlen);
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getsockopt.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getsockopt.h
index 623ba58ebb2ed..9a0c0570ad2b7 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/getsockopt.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getsockopt.h
@@ -15,7 +15,6 @@
#include "src/__support/macros/config.h"
#include "hdr/types/socklen_t.h"
-#include <linux/net.h> // For SYS_GETSOCKOPT socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -23,20 +22,8 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> getsockopt(int sockfd, int level, int optname,
void *optval, socklen_t *optlen) {
-#ifdef SYS_getsockopt
int ret =
syscall_impl<int>(SYS_getsockopt, sockfd, level, optname, optval, optlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[5] = {static_cast<unsigned long>(sockfd),
- static_cast<unsigned long>(level),
- static_cast<unsigned long>(optname),
- reinterpret_cast<unsigned long>(optval),
- reinterpret_cast<unsigned long>(optlen)};
- int ret = syscall_impl<int>(SYS_socketcall, SYS_GETSOCKOPT, sockcall_args);
-#else
-#error "getsockopt and socketcall syscalls unavailable for this platform."
-#endif
-
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/listen.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/listen.h
index 9de54ce0a9a9f..e764c6b108432 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/listen.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/listen.h
@@ -14,24 +14,13 @@
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
-#include <linux/net.h> // For SYS_LISTEN socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> listen(int sockfd, int backlog) {
-#ifdef SYS_listen
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_listen, sockfd, backlog);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[2] = {static_cast<unsigned long>(sockfd),
- static_cast<unsigned long>(backlog)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_LISTEN,
- sockcall_args);
-#else
-#error "listen and socketcall syscalls unavailable for this platform."
-#endif
-
+ int ret = syscall_impl<int>(SYS_listen, sockfd, backlog);
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h
index d16c397bba6ac..f1cfa8cd8e562 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h
@@ -15,7 +15,6 @@
#include "src/__support/macros/config.h"
#include "hdr/types/socklen_t.h"
-#include <linux/net.h> // For SYS_SETSOCKOPT socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -23,20 +22,8 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> setsockopt(int sockfd, int level, int optname,
const void *optval, socklen_t optlen) {
-#ifdef SYS_setsockopt
int ret =
syscall_impl<int>(SYS_setsockopt, sockfd, level, optname, optval, optlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[5] = {static_cast<unsigned long>(sockfd),
- static_cast<unsigned long>(level),
- static_cast<unsigned long>(optname),
- reinterpret_cast<unsigned long>(optval),
- static_cast<unsigned long>(optlen)};
- int ret = syscall_impl<int>(SYS_socketcall, SYS_SETSOCKOPT, sockcall_args);
-#else
-#error "setsockopt and socketcall syscalls unavailable for this platform."
-#endif
-
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/shutdown.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/shutdown.h
index 2a9e92364f637..156905a408f1a 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/shutdown.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/shutdown.h
@@ -14,24 +14,13 @@
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
-#include <linux/net.h> // For SYS_SHUTDOWN socketcall number.
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> shutdown(int sockfd, int how) {
-#ifdef SYS_shutdown
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_shutdown, sockfd, how);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[2] = {static_cast<unsigned long>(sockfd),
- static_cast<unsigned long>(how)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SHUTDOWN,
- sockcall_args);
-#else
-#error "shutdown and socketcall syscalls unavailable for this platform."
-#endif
-
+ int ret = syscall_impl<int>(SYS_shutdown, sockfd, how);
if (ret < 0)
return Error(-static_cast<int>(ret));
return ret;
diff --git a/libc/src/sys/socket/linux/bind.cpp b/libc/src/sys/socket/linux/bind.cpp
index 83a3d06f5380b..1b0a868f6b127 100644
--- a/libc/src/sys/socket/linux/bind.cpp
+++ b/libc/src/sys/socket/linux/bind.cpp
@@ -14,7 +14,6 @@
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
@@ -22,18 +21,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, bind,
(int socket, const struct sockaddr *address,
socklen_t address_len)) {
-#ifdef SYS_bind
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_bind, socket, address, address_len);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(socket),
- reinterpret_cast<unsigned long>(address),
- static_cast<unsigned long>(address_len)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_BIND,
- sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ int ret = syscall_impl<int>(SYS_bind, socket, address, address_len);
if (ret < 0) {
libc_errno = -ret;
return -1;
diff --git a/libc/src/sys/socket/linux/recv.cpp b/libc/src/sys/socket/linux/recv.cpp
index baf4de1b5eb54..b7b208d454ffe 100644
--- a/libc/src/sys/socket/linux/recv.cpp
+++ b/libc/src/sys/socket/linux/recv.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/recv.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/socklen_t.h"
@@ -24,19 +23,12 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, recv,
(int sockfd, void *buf, size_t len, int flags)) {
#ifdef SYS_recv
- ssize_t ret =
- LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recv, sockfd, buf, len, flags);
+ ssize_t ret = syscall_impl<ssize_t>(SYS_recv, sockfd, buf, len, flags);
#elif defined(SYS_recvfrom)
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_recvfrom, sockfd, buf, len, flags, nullptr, nullptr);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[4] = {
- static_cast<unsigned long>(sockfd), reinterpret_cast<unsigned long>(buf),
- static_cast<unsigned long>(len), static_cast<unsigned long>(flags)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_RECV,
- sockcall_args);
+ ssize_t ret = syscall_impl<ssize_t>(SYS_recvfrom, sockfd, buf, len, flags,
+ nullptr, nullptr);
#else
-#error "socket and socketcall syscalls unavailable for this platform."
+#error "recv or recvfrom syscalls unavailable for this platform."
#endif
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
diff --git a/libc/src/sys/socket/linux/recvfrom.cpp b/libc/src/sys/socket/linux/recvfrom.cpp
index 3d8397b478cc4..ff4d5494fbeff 100644
--- a/libc/src/sys/socket/linux/recvfrom.cpp
+++ b/libc/src/sys/socket/linux/recvfrom.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/recvfrom.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/socklen_t.h"
@@ -34,21 +33,8 @@ LLVM_LIBC_FUNCTION(ssize_t, recvfrom,
srcaddr_sz = *addrlen;
(void)srcaddr_sz; // prevent "set but not used" warning
-#ifdef SYS_recvfrom
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_recvfrom, sockfd, buf, len, flags, src_addr, addrlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[6] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(buf),
- static_cast<unsigned long>(len),
- static_cast<unsigned long>(flags),
- reinterpret_cast<unsigned long>(src_addr),
- static_cast<unsigned long>(addrlen)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_socketcall, SYS_RECVFROM, sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ ssize_t ret = syscall_impl<ssize_t>(SYS_recvfrom, sockfd, buf, len, flags,
+ src_addr, addrlen);
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
return -1;
diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index bc6d072dbf9a1..e7650c508115c 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/recvmsg.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/ssize_t.h"
@@ -21,18 +20,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, recvmsg, (int sockfd, msghdr *msg, int flags)) {
-#ifdef SYS_recvmsg
- ssize_t ret =
- LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recvmsg, sockfd, msg, flags);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(msg),
- static_cast<unsigned long>(flags)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_socketcall, SYS_RECVMSG, sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ ssize_t ret = syscall_impl<ssize_t>(SYS_recvmsg, sockfd, msg, flags);
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
return -1;
diff --git a/libc/src/sys/socket/linux/send.cpp b/libc/src/sys/socket/linux/send.cpp
index 43b01e7e6e0f6..7e63e9e716433 100644
--- a/libc/src/sys/socket/linux/send.cpp
+++ b/libc/src/sys/socket/linux/send.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/send.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/socklen_t.h"
@@ -23,19 +22,12 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, send,
(int sockfd, const void *buf, size_t len, int flags)) {
#ifdef SYS_send
- ssize_t ret =
- LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_send, sockfd, buf, len, flags);
+ ssize_t ret = syscall_impl<ssize_t>(SYS_send, sockfd, buf, len, flags);
#elif defined(SYS_sendto)
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendto, sockfd, buf,
- len, flags, nullptr, 0);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[4] = {
- static_cast<unsigned long>(sockfd), reinterpret_cast<unsigned long>(buf),
- static_cast<unsigned long>(len), static_cast<unsigned long>(flags)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_SEND,
- sockcall_args);
+ ssize_t ret =
+ syscall_impl<ssize_t>(SYS_sendto, sockfd, buf, len, flags, nullptr, 0);
#else
-#error "socket and socketcall syscalls unavailable for this platform."
+#error "send or sendto syscalls unavailable for this platform."
#endif
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
diff --git a/libc/src/sys/socket/linux/sendmsg.cpp b/libc/src/sys/socket/linux/sendmsg.cpp
index b04783ebfe7e7..b4bbd7f78d433 100644
--- a/libc/src/sys/socket/linux/sendmsg.cpp
+++ b/libc/src/sys/socket/linux/sendmsg.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/sendmsg.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/ssize_t.h"
@@ -21,18 +20,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, sendmsg,
(int sockfd, const struct msghdr *msg, int flags)) {
-#ifdef SYS_sendmsg
- ssize_t ret =
- LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendmsg, sockfd, msg, flags);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(msg),
- static_cast<unsigned long>(flags)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_socketcall, SYS_SENDMSG, sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ ssize_t ret = syscall_impl<ssize_t>(SYS_sendmsg, sockfd, msg, flags);
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
return -1;
diff --git a/libc/src/sys/socket/linux/sendto.cpp b/libc/src/sys/socket/linux/sendto.cpp
index 9dda127f872d5..48450e22e9f48 100644
--- a/libc/src/sys/socket/linux/sendto.cpp
+++ b/libc/src/sys/socket/linux/sendto.cpp
@@ -8,7 +8,6 @@
#include "src/sys/socket/sendto.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
#include "hdr/types/socklen_t.h"
@@ -23,21 +22,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, sendto,
(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen)) {
-#ifdef SYS_sendto
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_sendto, sockfd, buf, len, flags, dest_addr, addrlen);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[6] = {static_cast<unsigned long>(sockfd),
- reinterpret_cast<unsigned long>(buf),
- static_cast<unsigned long>(len),
- static_cast<unsigned long>(flags),
- reinterpret_cast<unsigned long>(dest_addr),
- static_cast<unsigned long>(addrlen)};
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_socketcall, SYS_SENDTO, sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ ssize_t ret = syscall_impl<ssize_t>(SYS_sendto, sockfd, buf, len, flags,
+ dest_addr, addrlen);
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
return -1;
diff --git a/libc/src/sys/socket/linux/socket.cpp b/libc/src/sys/socket/linux/socket.cpp
index 69eb6cfa01ced..a2da75a0d7be0 100644
--- a/libc/src/sys/socket/linux/socket.cpp
+++ b/libc/src/sys/socket/linux/socket.cpp
@@ -14,24 +14,12 @@
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, socket, (int domain, int type, int protocol)) {
-#ifdef SYS_socket
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_socket, domain, type, protocol);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {static_cast<unsigned long>(domain),
- static_cast<unsigned long>(type),
- static_cast<unsigned long>(protocol)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SOCKET,
- sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ int ret = syscall_impl<int>(SYS_socket, domain, type, protocol);
if (ret < 0) {
libc_errno = -ret;
return -1;
diff --git a/libc/src/sys/socket/linux/socketpair.cpp b/libc/src/sys/socket/linux/socketpair.cpp
index 7ea8ca46cee58..a17850a3468fa 100644
--- a/libc/src/sys/socket/linux/socketpair.cpp
+++ b/libc/src/sys/socket/linux/socketpair.cpp
@@ -13,25 +13,13 @@
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/sanitizer.h"
-#include <linux/net.h> // For SYS_SOCKET socketcall number.
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, socketpair,
(int domain, int type, int protocol, int sv[2])) {
-#ifdef SYS_socketpair
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketpair, domain, type,
- protocol, sv);
-#elif defined(SYS_socketcall)
- unsigned long sockcall_args[3] = {
- static_cast<unsigned long>(domain), static_cast<unsigned long>(type),
- static_cast<unsigned long>(protocol), static_cast<unsigned long>(sv)};
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SOCKETPAIR,
- sockcall_args);
-#else
-#error "socket and socketcall syscalls unavailable for this platform."
-#endif
+ int ret = syscall_impl<int>(SYS_socketpair, domain, type, protocol, sv);
if (ret < 0) {
libc_errno = -ret;
return -1;
More information about the libc-commits
mailing list