-
Notifications
You must be signed in to change notification settings - Fork 677
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
Fix the 3rd argument type of ioctl_write_int_bad #2233
Conversation
changelog/2233.changed.md
Outdated
@@ -0,0 +1 @@ | |||
`ioctl_write_int_bad!` now properly supports passing a `c_ulong` as the parameter on Linux non-musl targets. |
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.
From our code, it seems that this type ioctl_param_type
is c_ulong
on all Linux targets, including musl
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.
Fixed. Thank you!
This patch follows 5dad660 'Correct the third argument to ioctl on appropriate platforms', where only ioctl_write_int was fixed. Signed-off-by: Changyuan Lyu <[email protected]>
I am not familiar with The example ioctl provided in the Nix doc,
The other example, So this argument seems to change depending on the actual ioctl it is used with. |
|
Ping! Any feedback about this PR? If this change is not acceptable, how about adding another macro that allows specifying the type of the 3rd parameter? For example, ioctl_write_num_bad!(kvm_set_tss_addr, request_code_none!(KVMIO, 0x47), libc::c_ulong); This generates a function of the following signature pub unsafe fn kvm_set_tss_addr(fd: nix::libc::c_int, data: libc::c_long) -> nix::Result<nix::libc::c_int> and will pass |
@Lencerf from your explanation, on Linux no ioctl should ever use an |
@asomers Thanks for the feedback! My argument is, at the ABI level, on linux targets, the third argument should be something that has the same size as a pointer To support my argument
let's look at glibc's wrapper of int
__ioctl (int fd, unsigned long int request, ...)
{
va_list args;
va_start (args, request);
void *arg = va_arg (args, void *); // <== check this line
va_end (args);
int r;
if (!__ioctl_arch (&r, fd, request, arg))
{
r = INTERNAL_SYSCALL_CALL (ioctl, fd, request, arg);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r)))
{
__set_errno (-r);
return -1;
}
}
return r;
} it's quite clear that Coming back to the original topic, since nix is aimed at providing type safe wrappers for rust, I agree that for ioctls like |
So for this macro, the user would supply a type, and the macro would cast from that type to |
This patch follows 5dad660 'Correct the third argument to ioctl on appropriate platforms', where only ioctl_write_int was fixed.
What does this PR do
Checklist:
CONTRIBUTING.md