Intel manual says some implementations support less than 64 bits as linear addresses and canonical addressing is checked and may lead to #SS exception.

Does programmer should keep all the addresses canonical?(the most significant supported bit is extended to bit position 63)

If yes, a linear address is not specified completely till loader of operating system loads the program into memory!! Does the kernel of OS makes addresses canonical?

If no, how #SS(in 64 bits), stack segment fault is generate by CPU then? 
Posted on 2010-05-11 23:39:29 by logicman112
The answer is yes. And almost none of the current CPUs support full 64-bit addresses. Usually they support something like 36 bits (64 GB).
Posted on 2010-05-12 00:21:32 by ti_mo_n

Usually they support something like 36 bits (64 GB).


That sounds more like the physical address space, in which maxes out at 52 bits, but I think it is already beyond 36 bits (i.e. PAE) for most processors.

I think all x86-64 compatible CPU's support, at least, a 48-bit virtual address space.


Intel manual says some implementations support less than 64 bits as linear addresses and canonical addressing is checked and may lead to #SS exception.

Does programmer should keep all the addresses canonical?(the most significant supported bit is extended to bit position 63)


If you mean the application developer, then no, this is something that the OS should be handling via the program loader.

Moreover, x86-64 supports position independent code (RIP-relative) within a range of +/- 2GB, so absolute addressing within a program is usually not of much concern.

A smart developer will make sure they have little need of the program loader in terms of patching up relocations, by utilizing position independent code.


If yes, a linear address is not specified completely till loader of operating system loads the program into memory!! Does the kernel of OS makes addresses canonical?


Any decent OS will take into consideration the limitations of the architecture, so, as long as the programmer properly utilizes position independent code and/or a relocatable object format, then yes, the OS should be ensuring the program loads and operates within a canonical address space.


If no, how #SS(in 64 bits), stack segment fault is generate by CPU then? 


The #SS exception is generated as per the Intel/AMD documentation, in which is pretty self-explanatory.

All software can potentially have bugs, including the OS in which can allow the stack to progress to an invalid state, hence the need for critical exceptions such as #SS.
Posted on 2010-05-12 08:22:50 by SpooK
Thank you for the replies.

Violation from the correct canonical address can cause #SS exception. When memory is referenced by SS register. 

It seems that OS kernel assigns an address space to each process(a virtual address space) and this space is canonical. So referencing this memory by application causes no exception.

 
Posted on 2010-05-14 23:47:10 by logicman112