I tried to find documentation about the sign extensions of virtual addresses in long mode in the AMD and Intel documentation, but none of them write about it. Also wikipedia doesn't really talk about this...
From reading the Bochs source code my understanding is that the Sign extension is only checked for being canonical, but not used in the page translation process.
Does anyone know if the sign extension has any influence on privilege checks (so that virtual addresses in the negative address space always require cpl 0)?
Does a pointer 0xFFFF800000000008 equal the pointer 0x0000000000000008 in both cpl 0 and cpl 3? Or would code running in cpl 3 always page fault trying to use negative pointer because the system assumes cpl 0 for them?
I hope somebody can shed some light on this for me
[solved] Sign extension on x86-64 (paging)
[solved] Sign extension on x86-64 (paging)
Last edited by TomTom on Fri May 18, 2007 7:16 am, edited 1 time in total.
What I'm interested in is when I'm in a system call that got called from user mode I need to check a pointer to make sure that it's not pointing to kernel memory. On IA-32 this is quite easy because I simply can check if bit 31 of the virtual address is set (making it negative, the highest GB where the kernel resides). But on x86-64 if a negative virtual address equals a positive one, then how could I make sure that a call from user mode is not giving me a pointer to kernel memory? Looking up the privilege level for every pointer in the page table seems very inefficient to me
Never mind, I think I understand it now. Those many bits were confusing a bit....
It's the same concept as on IA-32. Just that in this case it's the last entry of the PML4 that is used for kernel memory. So pointers below or equal to 0x7FFFFFFFFFFF is user mode and everything above (sign extended) can be considered kernel memory (assuming that's how the kernel works). So bit 47 (0x800000000000) decides whether the pointer has to be sign extended, pointing to the last entry in the PML4 (which indicates kernel memory).
It's the same concept as on IA-32. Just that in this case it's the last entry of the PML4 that is used for kernel memory. So pointers below or equal to 0x7FFFFFFFFFFF is user mode and everything above (sign extended) can be considered kernel memory (assuming that's how the kernel works). So bit 47 (0x800000000000) decides whether the pointer has to be sign extended, pointing to the last entry in the PML4 (which indicates kernel memory).