Week 6 (Lect 14-16) Flashcards
(36 cards)
How does the program use Code, Stack, Heap? (what are their functions?)
Code: instructions that live in memory
Stack: to keep track of where it is in the function call. used for local variables.
Heap: Dynamically allocated, user managed memory
2 types of allocated memory?
- Stack: managed implicitly (automatic memory)
- Heap: managed explicitly by the user
What does a stack save in a function?
- return address
- save main’s pointer
- arguments and local variables
3 goals of a virtual memory system?
- Transparency (code that is invisible to the running program)
- Efficiency (in terms of time and space)
- Protection (protect processes from one another)
What is the malloc() call?
Pass a size asking for room in the heap.
Ex: malloc(10 * sizeof())
Some sources of segmentation fault?
- not allocating enough memory
- forgetting to initialize allocated memory
- forgetting to free memory
- double freeing
- freeing memory before you’re done
- invalid frees
What are stack canaries?
software defense that attempts to stop buffer overflow attacks / stack smashing.
It is a value (buffer) placed between local variables and return addresses. If an attacker attempts to overflow the buffer the overflow will also modify the canary
What is stack smashing?
An attack where an attacker attempts to write beyond the bounds of a local variable to modify the return address
Pros of a stack being a bump allocator?
Allocations/deallocations are really fast because we only move the stack pointer.
Cons of a stack being a bump allocator?
Allocations / deallocations only in the reverse order of which they are allocated
3 Ways to load virtual address into physical address?
- Direct Mapping
- Dynamic Relocation (whole memory)
- Segmentation (segments the memory)
What is direct mapping?
Give all the physical memory to the process.
Pros of direct mapping?
simple to implement, process knows where every byte of memory is
Cons of direct mapping?
Where does the OS go and what if you want to run more than one process
What is dynamic relocation?
divides the memory into slots, each process gets a slot.
translates virtual -> physical address by:
physical = virtual + base
Implemented by a base and bounds registers with the help of the MMU (memory management unit)
What is the base and bounds register?
Base (OFFSET) register: stores the starting address in physical memory (the offset from virtual –> physical)
Bounds (SIZE): defines the size/limit of the programs memory
What is internal fragmentation?
The space inside an allocated memory block is not all used. Happens a lot with dynamic relocation.
What are some Hardware Requirements for Dynamic Relocation?
- Privlege mode to update base/bounds
- Implement base/bound registers
- Translate virtual address
- Raise exceptions
What is Segmentation?
Splitting up the address space and storing each segment separately
What are the 3 main segments?
- Heap
- Stack
- Code
Pros of Segmentation?
Better utilization of physical memory, can place independently.
Cons of segmentation?
- External Fragmentation
- segments can be different sizes so the OS has to worry about finding space
What is external fragmentation?
Physical memory has become full o flittle holes of free space between segments.
What is the explicit approach to knowing the offset and specific segment an address is refering to?
USE VIRTUAL ADDRESS:
- top 2 bits to determine the type of segment
- the remaining bits determine the offset