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

Bitflags will clear unsupported fields. #7

Closed
le-jzr opened this issue Aug 28, 2017 · 3 comments
Closed

Bitflags will clear unsupported fields. #7

le-jzr opened this issue Aug 28, 2017 · 3 comments

Comments

@le-jzr
Copy link

le-jzr commented Aug 28, 2017

Currently, unknown flags in bitfields (e.g. CR4) get automatically cleared by the library. This means that if part of the kernel uses a flag this library is not yet aware of, changing flags with this library will corrupt the environment.

This doesn't matter if all parts of the kernel use (the same version of) this crate to access the registers, but that doesn't always need to be the case. I think it would be safer to make sure unknown flags are kept unchanged (by adding a mask with all bits set? I'm not sure about that part).

@phil-opp
Copy link
Member

Thanks for reporting! I agree that this is a problem.

So we need to change Cr4 (and the other bitflag types) somehow. We could wrap them in a struct that also saves the unknown flags and ORs both values together before saving: struct Cr4 { other_flags: usize; flags: Cr4Flags; }. The other_flags field is the result of an XOR of the original value and the result of from_bits_truncate. Alternatively we could create our own bitflags macro with a from_bits_ignore function, which ignores unknown bits instead of dropping them.

@le-jzr
Copy link
Author

le-jzr commented Aug 28, 2017

Alternatively, we can just make bitflags consider all bits relevant, like this:

pub flags Cr4: usize {
    // ...
    // ... supported flags
    // ...

    const ALL = core::usize::MAX,
}

@phil-opp
Copy link
Member

I think this no longer applies today, therefore closing.

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

No branches or pull requests

2 participants