Chapter 4: Virtual Process Memory
❑ The heap where global variables and dynamically generated data are stored.
❑ The stack used to hold local variables and to implement function and procedure calls.
❑ Sections with environment variables and command-line arguments.
❑ Memory mappings that map the contents of files into the virtual address space.
Recall from Chapter 2 that each process in the system is equipped with an instance ofstruct mm_struct
that can be accessed via the task structure. This instance holds memory management information for the
process:
<mm_types.h>
struct mm_struct {
...
unsigned long (*get_unmapped_area) (struct file *filp,
unsigned long addr, unsigned long len,
unsigned long pgoff, unsigned long flags);
...
unsigned long mmap_base; /* base of mmap area */
unsigned long task_size; /* size of task vm space */
...
unsigned long start_code, end_code, start_data, end_data;
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
...
}
The start and end of the virtual address space area consumed by the executable code are marked by
start_codeandend_code. Similarly,start_dataandend_datamark the region that contains initialized
data. Notice that the size of these areas does not change once an ELF binary has been mapped into the
address space.
The start address of the heap is kept instart_brk, whilebrkdenotes the current end of the heap area.
While the start is constant during the lifetime of a process, heap size and thus the value ofbrkwill vary.
The position of the argument list and the environment is described byarg_startandarg_end,respec-
tively,env_startandenv_end. Both regions reside in the topmost area of the stack.
mmapbasedenotes the starting point for memory mappings in the virtual address space, andget
unmapped_areais invoked to find a suitable place for a new mapping in the mmap area.
task_size— variable names don’t lie — stores the task size of the corresponding process. For native
applications, this will usually beTASK_SIZE. However, 64-bit architectures are often binary-compatible
with their predecessors. If a 32-bit binary is executed on a 64-bit machine, thentask_sizedescribes the
effective task size visible to the binary.
The individual architectures can influence the layoutof the virtual address space by several configuration
options:
❑ If an architecture wants to choose between different possibilities for how the mmap area is
arranged, it needs to setHAVE_ARCH_PICK_MMAP_LAYOUTand provide the functionarch_
pick_mmap_layout.