Raphael S.Carvalho's Programming Blog

raphael.scarv@gmail.com

"A programmer that cannot debug effectively is blind."

Saturday, November 17, 2012

Address Space Layout Alternatives

So, I enrolled myself in a course provided by MIT opencourseware. It has been an enjoyable course so far, though I found myself overwhelmed.

Challenge! Write up an outline of how a kernel could be designed to allow user environments unrestricted use of the full 4GB virtual and linear address space. Hint: the technique is sometimes known as "follow the bouncing kernel. Finally, think about and describe the advantages and disadvantages of such a scheme in terms of flexibility, performance, kernel complexity, and other factors you can think of.

* Question:
"In your design, be sure to address exactly what has to happen when the processor transitions between kernel and user modes,"
* Answer:
There are two ways in which processor transitions between kernel and user mode.
1 - Interruptions
    - Hardware
    - Software (System call)
2 - Call Gates

* Question:
"and how the kernel would accomplish such transitions."
* Answer:
1 - Also note that for the question to make any sense, "unrestricted use of the full 4GB virtual and linear address space" needs to be considered a typo and should be replaced with "unrestricted use of *almost* the full 4GB virtual and linear address space".

2 - It's impossible because the GDT and IDT (which should not be considered part of the process) must be in the virtual address space.
    * For IDT, GDT, TSS and SYSCALL/SYSEXT the CPU uses linear addresses.

It also would have to reload the CR3 register with the kernel page directory's physical address.
Consequently, flushing the TLB (Translation lookaside buffer) and loading the kernel address space.

* Question:
"Also describe how the kernel would access physical memory and I/O
devices in this scheme,
* Answer:
The kernel could map virtual addresses into the same physical addresses,
so that access to memory would occur as if "paging "wasn't enabled".
In fact, it might use I/O instructions normally since the processor is in the supervisor mode.

* Question:
"and how the kernel would access a user
environment's virtual address space during system calls and the like."
* Answer:
Kernel address space is the main responsible to allocate a page structure, then it could access
the user environment's virtual address space by looking into its respective page directory.

- Conclusion:
First of all, it increases the kernel complexity significantly, and reduces the performance in orders of magnitude.
However, it improves the kernel flexibility since it might address memory as if "paging was disabled".

No comments:

Post a Comment