xywang
xywang

Reputation: 951

What is the user space virtual memory layout for x86_64 Linux process?

I'd like to know how Linux kernel maps userspace sections (like stacks, heap and global variables) below 0x7fffffffffff on x86_64.

Does the kernel prefer a fixed starting address for each section? Or does it depend on linker's decision to some degree? What is the size for each section?

Upvotes: 1

Views: 1438

Answers (1)

Nemanja Boric
Nemanja Boric

Reputation: 22187

Linux (and most other modern operating systems) is doing something that is called Address space layout randomization. This allows operating systems to move stack, heap and libraries to the arbitrary location to prevent certain classes of attacks.

The only section that needs a linker support is text section - you need to build enter link description here in order to randomize the start of this section.

About the sizes of sections, text section obviosly depends on the binary size, and initilized and uninitialized data section on the specific program. Maximum stack size is controlled by kernel, and heap size is determined with the program break (see enter link description here for graphics description) and it can be changed by calling the brk (2).

Upvotes: 2

Related Questions