2.7 KiB
x86_64 Virtual Memory Layout
┌─────────────────────┐ 0xFFFFFFFF_FFFFFFFF │ Higher Half │ ├─────────────────────┤ 0xFFFFFFFF_FF600000 │ Recursive │ (Optional: for page table manipulation) │ Page Mapping │ ├─────────────────────┤ 0xFFFFFFFF_C0000000 │ Kernel Stacks │ (Multiple 16KB or 32KB stacks, guard pages between) ├─────────────────────┤ │ Kernel Heap │ (Dynamic allocation for kernel) ├─────────────────────┤ 0xFFFFFFFF_80000000 │ Kernel Code │ (Loaded by bootloader) ├─────────────────────┤ 0x00007FFF_FFFFFFFF │ Guard │ (Prevent user->kernel pointer errors) ├─────────────────────┤ 0x00007FFF_00000000 │ User Stacks │ (Grows down) ├─────────────────────┤ │ ... │ (Available for mmap, shared libraries, etc.) ├─────────────────────┤ │ User Heap │ (Grows up) ├─────────────────────┤ │ Program .bss │ (Uninitialized data) │ Program .data │ (Initialized data) │ Program .rodata │ (Read-only data) │ Program .text │ (Code) ├─────────────────────┤ 0x0000000000400000 │ Guard │ (Catch null pointer dereference) └─────────────────────┘ 0x0000000000000000
Memory Regions Explanation
Kernel Space (Higher Half)
- Kernel Code: Fixed location at -2GB
- Kernel Heap: Dynamic memory for kernel operations
- Kernel Stacks: Multiple stacks for different CPU modes/tasks
- Recursive Mapping: Optional region for page table manipulation
User Space (Lower Half)
- Guard Pages: Protect against null pointer dereference (0-4MB)
- Program Sections: Start at 0x400000
- .text: Program code
- .rodata: Read-only data
- .data: Initialized data
- .bss: Uninitialized data
- User Heap: Grows upward from end of program sections
- Dynamic Region: Space for mmap allocations, shared libraries
- User Stacks: Grows downward from 0x00007FFF_00000000
Key Features
- Full 48-bit addressing support (256TB virtual address space)
- Clear separation between user and kernel space
- Protected null pointer dereference
- Room for stack/heap growth
- Space for dynamic libraries and mappings