about summary refs log tree commit diff
path: root/src/network
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-08 09:24:19 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-08 09:24:19 -0400
commit7168790763cdeb794df52be6e3b39fbb021c5a64 (patch)
treefa302a8cb7f16d6201db3499082cc6b70012769a /src/network
parent5b8d81f706da0b7dc0abb5d0d74595d5b2f60d52 (diff)
downloadmusl-7168790763cdeb794df52be6e3b39fbb021c5a64.tar.gz
musl-7168790763cdeb794df52be6e3b39fbb021c5a64.tar.xz
musl-7168790763cdeb794df52be6e3b39fbb021c5a64.zip
workaround broken msghdr struct on 64bit linux
POSIX clearly specifies the type of msg_iovlen and msg_controllen, and
Linux ignores it and makes them both size_t instead. to work around
this we add padding (instead of just using the wrong types like glibc
does), but we also need to patch-up the struct before passing it to
the kernel in case the caller did not zero-fill it.

if i could trust the kernel to just ignore the upper 32 bits, this
would not be necessary, but i don't think it will ignore them...
Diffstat (limited to 'src/network')
-rw-r--r--src/network/recvmsg.c12
-rw-r--r--src/network/sendmsg.c9
2 files changed, 21 insertions, 0 deletions
diff --git a/src/network/recvmsg.c b/src/network/recvmsg.c
index edc5f241..65094fc8 100644
--- a/src/network/recvmsg.c
+++ b/src/network/recvmsg.c
@@ -1,12 +1,24 @@
 #include <sys/socket.h>
+#include <limits.h>
 #include "syscall.h"
 #include "libc.h"
 
 ssize_t recvmsg(int fd, struct msghdr *msg, int flags)
 {
 	ssize_t r;
+#if LONG_MAX > INT_MAX
+	struct msghdr h, *orig = msg;
+	if (msg) {
+		h = *msg;
+		h.__pad1 = h.__pad2 = 0;
+		msg = &h;
+	}
+#endif
 	CANCELPT_BEGIN;
 	r = socketcall(recvmsg, fd, msg, flags, 0, 0, 0);
 	CANCELPT_END;
+#if LONG_MAX > INT_MAX
+	if (orig) *orig = h;
+#endif
 	return r;
 }
diff --git a/src/network/sendmsg.c b/src/network/sendmsg.c
index 5d1123f0..047c0eff 100644
--- a/src/network/sendmsg.c
+++ b/src/network/sendmsg.c
@@ -1,10 +1,19 @@
 #include <sys/socket.h>
+#include <limits.h>
 #include "syscall.h"
 #include "libc.h"
 
 ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
 {
 	ssize_t r;
+#if LONG_MAX > INT_MAX
+	struct msghdr h;
+	if (msg) {
+		h = *msg;
+		h.__pad1 = h.__pad2 = 0;
+		msg = &h;
+	}
+#endif
 	CANCELPT_BEGIN;
 	r = socketcall(sendmsg, fd, msg, flags, 0, 0, 0);
 	CANCELPT_END;