-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Add sendmmsg syscall wrapper #2326
Conversation
As `iovec_const` is to `iovec`, `msghdr_const` is to `msghdr`
msg_iovlen: i32, | ||
__pad1: i32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you remove this padding field? Doesn't that break the ABI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This padding field isn't present in freebsd headers. It looked like someone just copy/pasted the linux definition without checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh. That's a problem. Now the entire freebsd.zig file needs to be audited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likewise netbsd.zig; which seems to have been copied from freebsd....
return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); | ||
} | ||
|
||
pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { | ||
if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) { | ||
// workaround kernel brokenness: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #2380 to address this. I'd like to resolve that issue before merging this pull request. It's not a particularly big time investment for me to do that, so I can prioritize it to unblock you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure #2380 is related :P
sendmmsg
is not a posix API (see my comment here)
This is an oversight in the linux kernel when introducing 64bit support to code originally written for 32bit that has now resulted in a broken kernel ABI forever.
But it does of course bring up the question of: where does this wrapper belong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of std.os.posix mapping directly to OS-specific files, it will provide a "zig flavored POSIX" API on top of the native OS API. This is where kernel limitations will be worked around; fork might call clone on Linux, etc.
I think this applies to the sendmmsg workaround. std.os.linux.sendmmsg is meant to be completely raw. std.os.posix.sendmmsg will be a compile error on systems that don't have it, that's fine. Zig is using std.os.posix to mean a specific, slightly different thing than it means in C and that's OK.
@andrewrk any thoughts on:
|
Oops, meant to address that - thanks for the reminder. That's a problem that has come up in several different contexts and I don't have a good answer for it yet. I think it would be worth opening up an issue to discuss potential solutions. |
Opened #2383 to track |
I'm OK with merging this and doing #2380 later. Is this ready to merge @daurnimator? Can you confirm where you got the msghdr struct layouts for arm64, netbsd, and freebsd? |
Yes.
Checked headers of each OS. comments are directly from each OS. |
Includes some cleanups of
msghdr
definition.Open questions:
iovec
andiovec_const
; bothmsghdr
andmsghdr_const
gets messy. What can the zig language do to make this less annoying?Tested with this snippet: