Skip to content
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 Linux custom ioctl opcode computation #861

Merged
merged 3 commits into from
Sep 30, 2023

Conversation

kevinmehall
Copy link
Contributor

@kevinmehall kevinmehall commented Sep 30, 2023

When attempting to use the recently added custom ioctl APIs I was getting Inappropriate ioctl for device errors and found that the ioctl opcodes being passed to the kernel were equal to just the NUM part with the other components ignored. This seems to be because the shift and the mask were performed in the wrong order when combining the components.

I also added:

  • a test comparing a few computed opcodes to known opcodes from linux_raw_sys as a sanity check
  • documentation referring to the C macros where you would find the values to use with these functions / types.

By the way, I noticed that this library is itself using only BadOpcode with constants from linux_raw_sys rather than the ReadOpcode / WriteOpcode types. Is there any reason to prefer ReadOpcode / WriteOpcode over using an opcode found in linux_raw_sys?

The name Bad made it seem like something I shouldn't be using, but taking the value by name from linux_raw_sys seems less error prone than looking up these components in a C header file and hard-coding them.

cc @notgull

@kevinmehall kevinmehall force-pushed the ioctl-fix branch 2 times, most recently from 9632e57 to 05282c9 Compare September 30, 2023 17:16
Copy link
Contributor

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoopsie daisy

@sunfishcode
Copy link
Member

Thanks!

@sunfishcode sunfishcode merged commit 8bbb1a9 into bytecodealliance:main Sep 30, 2023
43 checks passed
@sunfishcode
Copy link
Member

This is now released in rustix 0.38.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants