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

Are we calling macOS "open" with a wrong argument type? #71915

Closed
RalfJung opened this issue May 5, 2020 · 4 comments · Fixed by #71921
Closed

Are we calling macOS "open" with a wrong argument type? #71915

RalfJung opened this issue May 5, 2020 · 4 comments · Fixed by #71921
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented May 5, 2020

In this line, we are calling open64 (which on macOS is open renamed):

let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?;

As third argument, we are passing something of type c_int. However, according to this document, the type should be mode_t instead, and on macOS these types do not seem identical -- the libc crate has

src/unix/bsd/apple/mod.rs
10:pub type mode_t = u16;

Seems like we are using the wrong argument type here?
(open is variadic so the compiler cannot check this. But Miri complained when I started to check argument sizes.)

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. O-macos Operating system: macOS T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 5, 2020
@tmiasko
Copy link
Contributor

tmiasko commented May 5, 2020

The types are correct. In C, the default argument promotions are performed on trailing arguments.

@RalfJung
Copy link
Member Author

RalfJung commented May 5, 2020

In C, the default argument promotions are performed on trailing arguments.

I don't know what that means, but the man page explicitly says mode_t -- so is the man page wrong then?

@hanna-kruppe
Copy link
Contributor

The third argument is passed as variadic argument, so the man page is not saying the function has signature open(const char*, int, mode_t), just that C programmers should use mode_t for representing the mode if one is needed -- presumably not just w.r.t. open but more generally in all APIs. But at ABI level, the third argument is passed as int because of the C rule that @tmiasko alludes to.

@RalfJung
Copy link
Member Author

RalfJung commented May 5, 2020

So would a comment like this be appropriate? #71921

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants