Hello, I have questions for this. please read ...

This below code is excerpts from linux kernel fault.c.

#ifdef CONFIG_X86_64
/*
* Instruction fetch faults in the vsyscall page might need
* emulation.
*/
if (unlikely((error_code & PF_INSTR) &&
((address & ~0xfff) == VSYSCALL_ADDR))) {
if (emulate_vsyscall(regs, address))
return;
}
#endif

my question is the meaning of the line : address & ~0xfff.
what does '~' sign mean before the hexdecimal memory address 0xfff?
Thanks for reading.
Regards.
hexadecimal memory address
Not a memory address, but a bitmask.

~ Is called the bit-wise one's complement operator, or alternatively bit-wise NOT.
http://en.cppreference.com/w/cpp/language/operator_arithmetic#Bitwise_logic_operators

~0xFFF is an integer with all bits high except the least-significant twelve, i.e., 0b11...11 0000 0000 0000

The expression value & ~mask (where value and mask are integral) is an integral value with all the bits of value that are set in mask turned off.

1
2
3
int value = 0xFFFF;
value &= ~0xF0F0;
// here value holds 0x0F0F 
Last edited on
Thank you mbozzi. your answer gude me to understand the quoted code.

regards.
Topic archived. No new replies allowed.