Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Fix send and recv functions #110936

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michaelrj-google
Copy link
Contributor

There were some errors in the implementation. Oops. This patch fixes
those.

There were some errors in the implementation. Oops. This patch fixes
those.
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 2, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

There were some errors in the implementation. Oops. This patch fixes
those.


Full diff: https://github.com/llvm/llvm-project/pull/110936.diff

7 Files Affected:

  • (modified) libc/src/sys/socket/linux/recv.cpp (+8-8)
  • (modified) libc/src/sys/socket/linux/recvfrom.cpp (+8-9)
  • (modified) libc/src/sys/socket/linux/recvmsg.cpp (+7-6)
  • (modified) libc/src/sys/socket/linux/send.cpp (+8-7)
  • (modified) libc/src/sys/socket/linux/sendmsg.cpp (+7-6)
  • (modified) libc/src/sys/socket/linux/sendto.cpp (+7-8)
  • (modified) libc/src/sys/socket/recvfrom.h (+1-1)
diff --git a/libc/src/sys/socket/linux/recv.cpp b/libc/src/sys/socket/linux/recv.cpp
index 55a766aec0e77f..a534dffd0f583f 100644
--- a/libc/src/sys/socket/linux/recv.cpp
+++ b/libc/src/sys/socket/linux/recv.cpp
@@ -8,6 +8,9 @@
 
 #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"
 #include "hdr/types/ssize_t.h"
 #include "hdr/types/struct_sockaddr.h"
@@ -15,8 +18,6 @@
 #include "src/__support/common.h"
 #include "src/__support/macros/sanitizer.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -24,17 +25,16 @@ LLVM_LIBC_FUNCTION(ssize_t, recv,
                    (int sockfd, const void *buf, size_t len, int flags)) {
 #ifdef SYS_recv
   ssize_t ret =
-      LIBC_NAMESPACE::syscall_impl<int>(SYS_recv, sockfd, buf, len, flags);
+      LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recv, sockfd, buf, len, flags);
 #elif defined(SYS_recvfrom)
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_recvfrom, sockfd,
-                                                  reinterpret_cast<long>(buf),
-                                                  len, flags, nullptr, 0);
+  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<int>(SYS_socketcall, SYS_RECV,
-                                                  sockcall_args);
+  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_RECV,
+                                                      sockcall_args);
 #else
 #error "socket and socketcall syscalls unavailable for this platform."
 #endif
diff --git a/libc/src/sys/socket/linux/recvfrom.cpp b/libc/src/sys/socket/linux/recvfrom.cpp
index 990e58da3c1b64..fdcaceee8ad293 100644
--- a/libc/src/sys/socket/linux/recvfrom.cpp
+++ b/libc/src/sys/socket/linux/recvfrom.cpp
@@ -8,6 +8,9 @@
 
 #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"
 #include "hdr/types/ssize_t.h"
 #include "hdr/types/struct_sockaddr.h"
@@ -15,19 +18,15 @@
 #include "src/__support/common.h"
 #include "src/__support/macros/sanitizer.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(ssize_t, recvfrom,
                    (int sockfd, const void *buf, size_t len, int flags,
-                    const struct sockaddr *dest_addr, socklen_t addrlen)) {
+                    const struct sockaddr *dest_addr, socklen_t *addrlen)) {
 #ifdef SYS_recvfrom
-
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
-      SYS_recvfrom, sockfd, reinterpret_cast<long>(buf), len, flags,
-      reinterpret_cast<long>(dest_addr), addrlen);
+  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
+      SYS_recvfrom, 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),
@@ -35,8 +34,8 @@ LLVM_LIBC_FUNCTION(ssize_t, recvfrom,
                                     static_cast<unsigned long>(flags),
                                     reinterpret_cast<unsigned long>(dest_addr),
                                     static_cast<unsigned long>(addrlen)};
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_RECVFROM,
-                                                  sockcall_args);
+  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
diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index f44e5800d817f2..59a99210c1a840 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -8,28 +8,29 @@
 
 #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"
 #include "hdr/types/struct_msghdr.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
 #include "src/__support/macros/sanitizer.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(ssize_t, recvmsg,
                    (int sockfd, const struct msghdr *msg, int flags)) {
 #ifdef SYS_recvmsg
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
-      SYS_recvmsg, sockfd, reinterpret_cast<long>(msg), flags);
+  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<int>(SYS_socketcall, SYS_RECVMSG,
-                                                  sockcall_args);
+  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
diff --git a/libc/src/sys/socket/linux/send.cpp b/libc/src/sys/socket/linux/send.cpp
index 0d29b6fd35b903..cb3b4d5a9ece72 100644
--- a/libc/src/sys/socket/linux/send.cpp
+++ b/libc/src/sys/socket/linux/send.cpp
@@ -8,14 +8,15 @@
 
 #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"
 #include "hdr/types/ssize_t.h"
 #include "hdr/types/struct_sockaddr.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -23,16 +24,16 @@ 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<int>(SYS_send, sockfd, buf, len, flags);
+      LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_send, sockfd, buf, len, flags);
 #elif defined(SYS_sendto)
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
-      SYS_sendto, sockfd, reinterpret_cast<long>(buf), len, flags, nullptr, 0);
+  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<int>(SYS_socketcall, SYS_SEND,
-                                                  sockcall_args);
+  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_SEND,
+                                                      sockcall_args);
 #else
 #error "socket and socketcall syscalls unavailable for this platform."
 #endif
diff --git a/libc/src/sys/socket/linux/sendmsg.cpp b/libc/src/sys/socket/linux/sendmsg.cpp
index ba2b37768cc246..b4d9c9deda028e 100644
--- a/libc/src/sys/socket/linux/sendmsg.cpp
+++ b/libc/src/sys/socket/linux/sendmsg.cpp
@@ -8,27 +8,28 @@
 
 #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"
 #include "hdr/types/struct_msghdr.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 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<int>(
-      SYS_sendmsg, sockfd, reinterpret_cast<long>(msg), flags);
+  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<int>(SYS_socketcall, SYS_SENDMSG,
-                                                  sockcall_args);
+  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
diff --git a/libc/src/sys/socket/linux/sendto.cpp b/libc/src/sys/socket/linux/sendto.cpp
index f5c3ffe8954da9..2fada192b08656 100644
--- a/libc/src/sys/socket/linux/sendto.cpp
+++ b/libc/src/sys/socket/linux/sendto.cpp
@@ -8,14 +8,15 @@
 
 #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"
 #include "hdr/types/ssize_t.h"
 #include "hdr/types/struct_sockaddr.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
 #include "src/errno/libc_errno.h"
-#include <linux/net.h>   // For SYS_SOCKET socketcall number.
-#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -23,10 +24,8 @@ 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<int>(
-      SYS_sendto, sockfd, reinterpret_cast<long>(buf), len, flags,
-      reinterpret_cast<long>(dest_addr), addrlen);
+  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),
@@ -34,8 +33,8 @@ LLVM_LIBC_FUNCTION(ssize_t, sendto,
                                     static_cast<unsigned long>(flags),
                                     reinterpret_cast<unsigned long>(dest_addr),
                                     static_cast<unsigned long>(addrlen)};
-  ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SENDTO,
-                                                  sockcall_args);
+  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
diff --git a/libc/src/sys/socket/recvfrom.h b/libc/src/sys/socket/recvfrom.h
index ee8d52157b705d..40e6cabca043b9 100644
--- a/libc/src/sys/socket/recvfrom.h
+++ b/libc/src/sys/socket/recvfrom.h
@@ -18,7 +18,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 ssize_t recvfrom(int sockfd, const void *buf, size_t len, int flags,
-                 const struct sockaddr *address, socklen_t addrlen);
+                 const struct sockaddr *address, socklen_t *addrlen);
 
 } // namespace LIBC_NAMESPACE_DECL
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants