Skip to content

Commit ef66936

Browse files
[libc] Fix send and recv functions (#110936)
There were some errors in the implementation. Oops. This patch fixes those.
1 parent 43d51d6 commit ef66936

File tree

7 files changed

+46
-45
lines changed

7 files changed

+46
-45
lines changed

libc/src/sys/socket/linux/recv.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88

99
#include "src/sys/socket/recv.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/socklen_t.h"
1215
#include "hdr/types/ssize_t.h"
1316
#include "hdr/types/struct_sockaddr.h"
1417
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1518
#include "src/__support/common.h"
1619
#include "src/__support/macros/sanitizer.h"
1720
#include "src/errno/libc_errno.h"
18-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
19-
#include <sys/syscall.h> // For syscall numbers.
2021

2122
namespace LIBC_NAMESPACE_DECL {
2223

2324
LLVM_LIBC_FUNCTION(ssize_t, recv,
2425
(int sockfd, const void *buf, size_t len, int flags)) {
2526
#ifdef SYS_recv
2627
ssize_t ret =
27-
LIBC_NAMESPACE::syscall_impl<int>(SYS_recv, sockfd, buf, len, flags);
28+
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recv, sockfd, buf, len, flags);
2829
#elif defined(SYS_recvfrom)
29-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_recvfrom, sockfd,
30-
reinterpret_cast<long>(buf),
31-
len, flags, nullptr, 0);
30+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
31+
SYS_recvfrom, sockfd, buf, len, flags, nullptr, nullptr);
3232
#elif defined(SYS_socketcall)
3333
unsigned long sockcall_args[4] = {
3434
static_cast<unsigned long>(sockfd), reinterpret_cast<unsigned long>(buf),
3535
static_cast<unsigned long>(len), static_cast<unsigned long>(flags)};
36-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_RECV,
37-
sockcall_args);
36+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_RECV,
37+
sockcall_args);
3838
#else
3939
#error "socket and socketcall syscalls unavailable for this platform."
4040
#endif

libc/src/sys/socket/linux/recvfrom.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,34 @@
88

99
#include "src/sys/socket/recvfrom.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/socklen_t.h"
1215
#include "hdr/types/ssize_t.h"
1316
#include "hdr/types/struct_sockaddr.h"
1417
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1518
#include "src/__support/common.h"
1619
#include "src/__support/macros/sanitizer.h"
1720
#include "src/errno/libc_errno.h"
18-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
19-
#include <sys/syscall.h> // For syscall numbers.
2021

2122
namespace LIBC_NAMESPACE_DECL {
2223

2324
LLVM_LIBC_FUNCTION(ssize_t, recvfrom,
2425
(int sockfd, const void *buf, size_t len, int flags,
25-
const struct sockaddr *dest_addr, socklen_t addrlen)) {
26+
const struct sockaddr *dest_addr, socklen_t *addrlen)) {
2627
#ifdef SYS_recvfrom
27-
28-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
29-
SYS_recvfrom, sockfd, reinterpret_cast<long>(buf), len, flags,
30-
reinterpret_cast<long>(dest_addr), addrlen);
28+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
29+
SYS_recvfrom, sockfd, buf, len, flags, dest_addr, addrlen);
3130
#elif defined(SYS_socketcall)
3231
unsigned long sockcall_args[6] = {static_cast<unsigned long>(sockfd),
3332
reinterpret_cast<unsigned long>(buf),
3433
static_cast<unsigned long>(len),
3534
static_cast<unsigned long>(flags),
3635
reinterpret_cast<unsigned long>(dest_addr),
3736
static_cast<unsigned long>(addrlen)};
38-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_RECVFROM,
39-
sockcall_args);
37+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
38+
SYS_socketcall, SYS_RECVFROM, sockcall_args);
4039
#else
4140
#error "socket and socketcall syscalls unavailable for this platform."
4241
#endif

libc/src/sys/socket/linux/recvmsg.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@
88

99
#include "src/sys/socket/recvmsg.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/ssize_t.h"
1215
#include "hdr/types/struct_msghdr.h"
1316
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1417
#include "src/__support/common.h"
1518
#include "src/__support/macros/sanitizer.h"
1619
#include "src/errno/libc_errno.h"
17-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
18-
#include <sys/syscall.h> // For syscall numbers.
1920

2021
namespace LIBC_NAMESPACE_DECL {
2122

2223
LLVM_LIBC_FUNCTION(ssize_t, recvmsg,
2324
(int sockfd, const struct msghdr *msg, int flags)) {
2425
#ifdef SYS_recvmsg
25-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
26-
SYS_recvmsg, sockfd, reinterpret_cast<long>(msg), flags);
26+
ssize_t ret =
27+
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recvmsg, sockfd, msg, flags);
2728
#elif defined(SYS_socketcall)
2829
unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
2930
reinterpret_cast<unsigned long>(msg),
3031
static_cast<unsigned long>(flags)};
31-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_RECVMSG,
32-
sockcall_args);
32+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
33+
SYS_socketcall, SYS_RECVMSG, sockcall_args);
3334
#else
3435
#error "socket and socketcall syscalls unavailable for this platform."
3536
#endif

libc/src/sys/socket/linux/send.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,32 @@
88

99
#include "src/sys/socket/send.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/socklen_t.h"
1215
#include "hdr/types/ssize_t.h"
1316
#include "hdr/types/struct_sockaddr.h"
1417
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1518
#include "src/__support/common.h"
1619
#include "src/errno/libc_errno.h"
17-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
18-
#include <sys/syscall.h> // For syscall numbers.
1920

2021
namespace LIBC_NAMESPACE_DECL {
2122

2223
LLVM_LIBC_FUNCTION(ssize_t, send,
2324
(int sockfd, const void *buf, size_t len, int flags)) {
2425
#ifdef SYS_send
2526
ssize_t ret =
26-
LIBC_NAMESPACE::syscall_impl<int>(SYS_send, sockfd, buf, len, flags);
27+
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_send, sockfd, buf, len, flags);
2728
#elif defined(SYS_sendto)
28-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
29-
SYS_sendto, sockfd, reinterpret_cast<long>(buf), len, flags, nullptr, 0);
29+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendto, sockfd, buf,
30+
len, flags, nullptr, 0);
3031
#elif defined(SYS_socketcall)
3132
unsigned long sockcall_args[4] = {
3233
static_cast<unsigned long>(sockfd), reinterpret_cast<unsigned long>(buf),
3334
static_cast<unsigned long>(len), static_cast<unsigned long>(flags)};
34-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SEND,
35-
sockcall_args);
35+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_socketcall, SYS_SEND,
36+
sockcall_args);
3637
#else
3738
#error "socket and socketcall syscalls unavailable for this platform."
3839
#endif

libc/src/sys/socket/linux/sendmsg.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,28 @@
88

99
#include "src/sys/socket/sendmsg.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/ssize_t.h"
1215
#include "hdr/types/struct_msghdr.h"
1316
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1417
#include "src/__support/common.h"
1518
#include "src/errno/libc_errno.h"
16-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
17-
#include <sys/syscall.h> // For syscall numbers.
1819

1920
namespace LIBC_NAMESPACE_DECL {
2021

2122
LLVM_LIBC_FUNCTION(ssize_t, sendmsg,
2223
(int sockfd, const struct msghdr *msg, int flags)) {
2324
#ifdef SYS_sendmsg
24-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
25-
SYS_sendmsg, sockfd, reinterpret_cast<long>(msg), flags);
25+
ssize_t ret =
26+
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendmsg, sockfd, msg, flags);
2627
#elif defined(SYS_socketcall)
2728
unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),
2829
reinterpret_cast<unsigned long>(msg),
2930
static_cast<unsigned long>(flags)};
30-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SENDMSG,
31-
sockcall_args);
31+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
32+
SYS_socketcall, SYS_SENDMSG, sockcall_args);
3233
#else
3334
#error "socket and socketcall syscalls unavailable for this platform."
3435
#endif

libc/src/sys/socket/linux/sendto.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,33 @@
88

99
#include "src/sys/socket/sendto.h"
1010

11+
#include <linux/net.h> // For SYS_SOCKET socketcall number.
12+
#include <sys/syscall.h> // For syscall numbers.
13+
1114
#include "hdr/types/socklen_t.h"
1215
#include "hdr/types/ssize_t.h"
1316
#include "hdr/types/struct_sockaddr.h"
1417
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1518
#include "src/__support/common.h"
1619
#include "src/errno/libc_errno.h"
17-
#include <linux/net.h> // For SYS_SOCKET socketcall number.
18-
#include <sys/syscall.h> // For syscall numbers.
1920

2021
namespace LIBC_NAMESPACE_DECL {
2122

2223
LLVM_LIBC_FUNCTION(ssize_t, sendto,
2324
(int sockfd, const void *buf, size_t len, int flags,
2425
const struct sockaddr *dest_addr, socklen_t addrlen)) {
2526
#ifdef SYS_sendto
26-
27-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(
28-
SYS_sendto, sockfd, reinterpret_cast<long>(buf), len, flags,
29-
reinterpret_cast<long>(dest_addr), addrlen);
27+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
28+
SYS_sendto, sockfd, buf, len, flags, dest_addr, addrlen);
3029
#elif defined(SYS_socketcall)
3130
unsigned long sockcall_args[6] = {static_cast<unsigned long>(sockfd),
3231
reinterpret_cast<unsigned long>(buf),
3332
static_cast<unsigned long>(len),
3433
static_cast<unsigned long>(flags),
3534
reinterpret_cast<unsigned long>(dest_addr),
3635
static_cast<unsigned long>(addrlen)};
37-
ssize_t ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_socketcall, SYS_SENDTO,
38-
sockcall_args);
36+
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
37+
SYS_socketcall, SYS_SENDTO, sockcall_args);
3938
#else
4039
#error "socket and socketcall syscalls unavailable for this platform."
4140
#endif

libc/src/sys/socket/recvfrom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace LIBC_NAMESPACE_DECL {
1919

2020
ssize_t recvfrom(int sockfd, const void *buf, size_t len, int flags,
21-
const struct sockaddr *address, socklen_t addrlen);
21+
const struct sockaddr *address, socklen_t *addrlen);
2222

2323
} // namespace LIBC_NAMESPACE_DECL
2424

0 commit comments

Comments
 (0)