In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" (struct vm_area_struct
). There is also a structure which represents (again in a very high level view) a process' whole address space (struct mm_struct
). Each process (except some kernel threads) has exactly one struct mm_struct
, which in turn points to all the struct vm_area_struct
for the memory it can accesss.
The sys_brk
system call (found in mm/mmap.c
) simply adjusts some of these memory areas. (sbrk
is a glibc wrapper around brk
). It does so by comparing the old value of the brk
address (found inside struct mm_struct
) and the requested value.
It would be simpler to look at the mmap
family of functions first, since brk
is a special case of it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…