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

Invalid value for CR4 #156

Open
not-matthias opened this issue Jan 12, 2024 · 1 comment
Open

Invalid value for CR4 #156

not-matthias opened this issue Jan 12, 2024 · 1 comment

Comments

@not-matthias
Copy link

While writing my hypervisor, I noticed crashes after 10 seconds. After a week debugging this issue, I realized that reading CR4 using this crate is the issue.

INFO: CR4 (manual): b52ef8
INFO: CR4 (x86_64): b52ef8
INFO: CR4 (x86): 	352ef8

How to reproduce:

let mut value= 0;
unsafe { core::arch::asm!("mov {}, cr4", out(reg) value) };
log::info!("CR4 (manual): {:x}", value);

let value = x86_64::registers::control::Cr4::read_raw();
log::info!("CR4 (x86_64): {:x}",  value);

let value = unsafe { x86::controlregs::cr4() };
log::info!("CR4 (x86): {:x}", value);
@gz
Copy link
Owner

gz commented Jan 12, 2024

Hm sorry about that, the cr4 function uses from_bits_truncate from bitflags

Cr4::from_bits_truncate(ret)
to make sure the value only sets the bits that are known to the Cr4 bitflag struct.

This is probably not the best way (when hardware supports new flags that the library doesn't know about yet the bits are dropped).

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