-
Notifications
You must be signed in to change notification settings - Fork 667
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
Re-use MultiHeader<()>
in subsequent recvmmsg()
calls
#2506
Comments
MultiHeader<()>
and recvmmsg()
MultiHeader<()>
in subsequent recvmmsg()
calls
I guess this is an optimization done by Rust, $ cat src/main.rs
#![feature(strict_provenance)]
fn main() {
println!("{:p}", std::ptr::dangling() as *const nix::libc::c_void);
}
$ cargo +nightly r -q
0x1 |
According to documentation for
We've been using it in production in this way for quite a while now while reusing reallocated headers with no problems on Linux. The fact that |
I guess API can/should be extended to be able to set and reset buffer length? My main use case was working with multicast streams so knowing source address is not necessary. |
A data point, I'm using fbdac70, about to upgrade. Both before and after I'm seeing |
0.25 works, 0.26 does not - producing |
#2041 - regression originates here |
Reverting this "fixes" this problem by initializing address with a null pointer, not sure if things fixed by #2041 are still working after that. - (*p).msg_name = (*address).as_mut_ptr() as *mut c_void;
+ (*p).msg_name = address as *mut c_void; I guess the right fix would be to figure out how to make it work as expected. From what I can tell this code existed before my changes to |
This fixes the problem: (*p).msg_name = if S::size() == 0 { ptr::nul_mut() } else { (*address).as_mut_ptr() as *mut c_void } Proper fix should include some tests for both sized and unsized addresses. There might be similar patterns in the code. |
After #2091 this rust-analyzer is no longer useful in the default state. What's the trick? |
If you're using vscode you can: "rust-analyzer.cargo.features": "all", in your global/workspace settings.json |
I'm using neovim. This kind of setting doesn't belong to global editor settings - I'm working on other projects as well. I'll look into making a fix after I figure out the config - fairly low priority at the moment. |
|
I made this that fixes the problem with R-A: #2516 There will be one more to fix |
The msg_name field points to a caller-allocated buffer that is used to return the source address if the socket is unconnected. The caller should set msg_namelen to the size of this buffer before this call; upon return from a successful call, msg_namelen will contain the length of the returned address. If the application does not need to know the source address, msg_name can be specified as NULL. In case we use () msgname_len gets initialized with 0, but pointer to the array with msg_name. This works for the first iteration somehow, but after that kernel sets msgname_len to a non-zero and second invocation with the same MultiHeader fails Fixes nix-rust#2506
The msg_name field points to a caller-allocated buffer that is used to return the source address if the socket is unconnected. The caller should set msg_namelen to the size of this buffer before this call; upon return from a successful call, msg_namelen will contain the length of the returned address. If the application does not need to know the source address, msg_name can be specified as NULL. In case we use () msgname_len gets initialized with 0, but a dangling pointer to the array with msg_name. This works for the first iteration somehow, but after that kernel sets msgname_len to a non-zero and second invocation with the same MultiHeader fails Fixes nix-rust#2506
The msg_name field points to a caller-allocated buffer that is used to return the source address if the socket is unconnected. The caller should set msg_namelen to the size of this buffer before this call; upon return from a successful call, msg_namelen will contain the length of the returned address. If the application does not need to know the source address, msg_name can be specified as NULL. In case we use () msgname_len gets initialized with 0, but a dangling pointer to the array with msg_name. This works for the first iteration somehow, but after that kernel sets msgname_len to a non-zero and second invocation with the same MultiHeader fails Fixes nix-rust#2506
* Use as_mut_ptr() to initialize msg_name in pack_mhdr_to_receive The msg_name field points to a caller-allocated buffer that is used to return the source address if the socket is unconnected. The caller should set msg_namelen to the size of this buffer before this call; upon return from a successful call, msg_namelen will contain the length of the returned address. If the application does not need to know the source address, msg_name can be specified as NULL. In case we use () msgname_len gets initialized with 0, but a dangling pointer to the array with msg_name. This works for the first iteration somehow, but after that kernel sets msgname_len to a non-zero and second invocation with the same MultiHeader fails Fixes #2506 * CI doesn't check for rustfmt but I'm tired of picking stuff
Problem
Before call:
After call:
The main thing to call out is that the kernel set the
msg_namelen
value to28
. This makes re-using MultiHeader for subsequent reads impossible because the kernel will complain witherr=Bad address (os error 14)
due to the fact we have amsg_name: NULL
andmsg_namelen: 28
in the input.I'd like to re-use
MultiHeader
for subsequent reads and have confirmed it works if I instead useMultiHeaders<UnixAddr>
, as we now have space of the address to be written.Potential Solution
Letting the caller set the
msglen
would allow us to re-zero it so the kernel doesn't think we have space available for an address when we don't.Side Question
Do you know why msg_name renders like this:
msg_hdr.msg_name: 0x1
, I would have thought0x0
forNULL
?The text was updated successfully, but these errors were encountered: