提交 71687907 编写于 作者: R Rich Felker

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...
上级 5b8d81f7
...@@ -3,9 +3,9 @@ struct msghdr ...@@ -3,9 +3,9 @@ struct msghdr
void *msg_name; void *msg_name;
socklen_t msg_namelen; socklen_t msg_namelen;
struct iovec *msg_iov; struct iovec *msg_iov;
int msg_iovlen; int msg_iovlen, __pad1;
void *msg_control; void *msg_control;
socklen_t msg_controllen; socklen_t msg_controllen, __pad2;
int msg_flags; int msg_flags;
}; };
......
#include <sys/socket.h> #include <sys/socket.h>
#include <limits.h>
#include "syscall.h" #include "syscall.h"
#include "libc.h" #include "libc.h"
ssize_t recvmsg(int fd, struct msghdr *msg, int flags) ssize_t recvmsg(int fd, struct msghdr *msg, int flags)
{ {
ssize_t r; 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; CANCELPT_BEGIN;
r = socketcall(recvmsg, fd, msg, flags, 0, 0, 0); r = socketcall(recvmsg, fd, msg, flags, 0, 0, 0);
CANCELPT_END; CANCELPT_END;
#if LONG_MAX > INT_MAX
if (orig) *orig = h;
#endif
return r; return r;
} }
#include <sys/socket.h> #include <sys/socket.h>
#include <limits.h>
#include "syscall.h" #include "syscall.h"
#include "libc.h" #include "libc.h"
ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
{ {
ssize_t r; 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; CANCELPT_BEGIN;
r = socketcall(sendmsg, fd, msg, flags, 0, 0, 0); r = socketcall(sendmsg, fd, msg, flags, 0, 0, 0);
CANCELPT_END; CANCELPT_END;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册