When a program runs on a machine, the computer runs the program as a process.
Current computer architecture allows multiple processes to be run concurrently(at the same time by a computer).
While these processes may appear to run at the same time, the computer actually switches between the processes very quickly and makes it look like they are running at the same time.
Buffer Overflows: Process Layout
Switching between processes is called a context switch. Since each process may need different information to run(e.g. The current instruction to execute), the operating system has to keep track of all the information in a process.
The memory in the process is organised sequentially and has the following layout:
Buffer Overflows: Process Layout
User Stack: Contains the information required to run the program. This information would include the current program counter, saved registers and more information. The section after the user stack is unused memory and it is used in case the stack grows(downwards)
Shared Library Regions: Are used to either statically/dynamically link libraries that are used by the program
Buffer Overflows: Process Layout
The heap increases and decreases dynamically depending on whether a program dynamically assigns memory. Notice there is a section that is unassigned above the heap which is used in the event that the size of the heap increases.
The program code and data stores the program executable and initialized variables.