-
Notifications
You must be signed in to change notification settings - Fork 161
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
Use/fix ret_*
helpers for certain libc functions
#1212
base: main
Are you sure you want to change the base?
Use/fix ret_*
helpers for certain libc functions
#1212
Conversation
f21bd7a
to
2bcd91a
Compare
- use ret_usize() instead of ret_send_recv() for c::recvmsg(), as it always returns c::ssize_t - use ret_usize() instead of ret_send_recv() for c::sendmsg(), as it always returns c::ssize_t - change the ret_send_recv() used on OSes different than Windows, Redox, and wasi to take c::ssize_t as parameter, as it is what c::recv(), c::send(), c::recvfrom(), and c::sendto() return on most/all of those OSes
2bcd91a
to
553a614
Compare
Windows doesn't have
This part sounds good. |
Right, there is the Windows version of rustix/src/backend/libc/conv.rs Lines 177 to 182 in d51b195
Did I miss anything? 🤔 |
Because of that, |
Not really:
While the different type of [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html |
Windows doesn't follow POSIX. It uses |
As I said earlier, this only works when
Hence this PR:
So there should be no changes for Windows, and indeed the CI jobs for Windows pass. |
I'm confused about what's going on on hurd. This standalone program: $ cat src/main.rs
fn main() {
unsafe {
let _t: ::libc::ssize_t = ::libc::sendmsg(0, core::ptr::null(), 0);
}
} compiled for 32-bit hurd gets an error: $ cargo +nightly check --target=i686-unknown-hurd-gnu -Zbuild-std
Checking t v0.1.0 (...)
error[E0308]: mismatched types
--> src/main.rs:3:35
|
3 | let _t: ::libc::ssize_t = ::libc::sendmsg(0, core::ptr::null(), 0);
| --------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `i32`
| |
| expected due to this
|
help: you can convert an `i32` to an `isize` and panic if the converted value doesn't fit
|
3 | let _t: ::libc::ssize_t = ::libc::sendmsg(0, core::ptr::null(), 0).try_into().unwrap();
| ++++++++++++++++++++
For more information about this error, try `rustc --explain E0308`. In the libc crate's source code, hurd's pub fn sendmsg(__fd: ::c_int, __message: *const msghdr, __flags: ::c_int) -> ::ssize_t; Why does rustc think that this |
Also, your branch doesn't build on hurd either: Checking rustix v0.38.35 (...)
error[E0308]: mismatched types
--> src/backend/libc/net/syscalls.rs:369:19
|
369 | ret_usize(c::sendmsg(
| _________---------_^
| | |
| | arguments to this function are incorrect
370 | | borrowed_fd(sockfd),
371 | | &msghdr,
372 | | bitflags_bits!(msg_flags),
373 | | ))
| |_________^ expected `isize`, found `i32`
|
note: function defined here
--> src/backend/libc/conv.rs:88:15
|
88 | pub(super) fn ret_usize(raw: c::ssize_t) -> io::Result<usize> {
| ^^^^^^^^^ ---------------
help: you can convert an `i32` to an `isize` and panic if the converted value doesn't fit
|
373 | ).try_into().unwrap())
| ++++++++++++++++++++
... |
It looks like rust-lang/libc#4029 will change hurd's |
So in summary here,
|
ret_usize()
instead ofret_send_recv()
forc::recvmsg()
, as it always returnsc::ssize_t
ret_usize()
instead ofret_send_recv()
forc::sendmsg()
, as it always returnsc::ssize_t
ret_send_recv()
used on OSes different than Windows, Redox, and wasi to takec::ssize_t
as parameter, as it is whatc::recv()
,c::send()
,c::recvfrom()
, andc::sendto()
return on most/all of those OSes