OSDev.org

The Place to Start for Operating System Developers
It is currently Fri May 17, 2024 1:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [solved] Sign extension on x86-64 (paging)
PostPosted: Fri May 18, 2007 5:51 am 
Offline

Joined: Tue May 01, 2007 2:03 am
Posts: 23
Location: USA
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 :)


Last edited by TomTom on Fri May 18, 2007 7:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 6:18 am 
Offline

Joined: Tue May 01, 2007 2:03 am
Posts: 23
Location: USA
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 7:16 am 
Offline

Joined: Tue May 01, 2007 2:03 am
Posts: 23
Location: USA
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).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group