[libc-commits] [libc] [libc] Port remaining socket functions to syscall_wrappers (PR #198463)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue May 19 06:21:23 PDT 2026


================
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for recv.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RECV_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RECV_H
+
+#include "hdr/types/ssize_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<ssize_t> recv(int sockfd, void *buf, size_t len,
+                                  int flags) {
+#ifdef SYS_recv
+  return syscall_checked<ssize_t>(SYS_recv, sockfd, buf, len, flags);
+#elif defined(SYS_recvfrom)
----------------
labath wrote:

I think we can do that. x86 (both 32 and 64 bit) are actually one of the architectures which don't have the plain recv syscall (there is one in the socketcall version, but I guess they decided to drop it even earlier than they decided to drop socketcall. This would also kind of indicate that we do not need the fallback (and a brief excursion into history seems to confirm that).

I'm a bit sad that we will be zeroing two registers for nothing, but I guess that's unlikely to matter.

https://github.com/llvm/llvm-project/pull/198463


More information about the libc-commits mailing list