capsicum-rs icon indicating copy to clipboard operation
capsicum-rs copied to clipboard

Replace the Fcntl enum with values from libc

Open asomers opened this issue 1 year ago • 2 comments

Replace Fcntl::GetFL with libc::F_GETFL, etc.

asomers avatar Jan 22 '24 22:01 asomers

We have a decision to make here. The tradeoff is type safety vs future proofing. The most future-proof way to do this would be to accept any u32 in FcntlsBuilder::add. That's similar to what IoctlsBuilder does. But it isn't type-safe, which is unfortunate. A safer option would be to create an enum of allowed values. We could even create it automatically by copying Nix's libc_enum! macro. But that isn't future-proof, because if FreeBSD adds a new fnctl value, capsicum-rs would need to be updated before our users could make use. A compromise might be to define Fcntl values as consts, like this:

struct Fcntl(u32);
impl Fcntl {
    const F_GETFL = Fcntl(libc::F_GETFL);
    ...
}

Or something along those lines. What do you think?

The same argument applies to IoctlsBuilder. However, allowed ioctl values are much more numerous, and they may not all be defined in libc. Plus, users may even have custom ioctls that come from out-of-tree (or even proprietary) kernel modules. So for IoctlsBuilder, future-proofing is much more important.

asomers avatar Jan 23 '24 00:01 asomers

Depends on https://github.com/rust-lang/libc/pull/3628

asomers avatar Mar 22 '24 15:03 asomers