-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
michaelrj-google
wants to merge
1
commit into
llvm:main
Choose a base branch
from
michaelrj-google:libcFixSendRecvOops
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+46
−45
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There were some errors in the implementation. Oops. This patch fixes those.
@llvm/pr-subscribers-libc Author: Michael Jones (michaelrj-google) ChangesThere were some errors in the implementation. Oops. This patch fixes Full diff: https://github.com/llvm/llvm-project/pull/110936.diff 7 Files Affected:
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
|
lntue
approved these changes
Oct 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There were some errors in the implementation. Oops. This patch fixes
those.