|
28 | 28 | - System call transfers control into the OS while raising the hardware privilege level |
29 | 29 | - User apps run in "user mode" |
30 | 30 | - Hardware restricts what apps can do |
31 | | - |
32 | | -## CPU Timing |
| 31 | +### Stack Overflow |
| 32 | +- Stack is a memory region allocated by the OS |
| 33 | + - Overflowing it, you try to write to memory _outside_ the region where you don't have permission |
| 34 | +- OS raises a segfault due to the illegal memory address |
| 35 | + - It doesn't know what the cause of the segfault is which is why you don't get an actual stack overflow error |
| 36 | +- Historically the heap was started at low addresses, stack at high addresses |
| 37 | + - The big gap in the middle maximized the space available before collision |
| 38 | + - Doesn't matter anymore thanks to enormous virtual address space |
| 39 | +- What contributes to the size of a stack frame? |
| 40 | + - Data |
| 41 | + - Return address |
| 42 | + - Rounding up to alignment boundaries |
| 43 | + - Usually 16 bytes on modern systems |
| 44 | + - Helps with performance |
| 45 | +- You can't map all the virtual address space to actual hardware |
| 46 | +- [[Address Space Layout Randomization]] |
| 47 | +- Programs can request an increase to their stack limit with `setrlimit` |
| 48 | + - You can raise your soft limit up to the hard limit but only root can raise hard limits |
| 49 | + - `getrlimit` to check limits |
| 50 | +- Threads get their own stack to avoid collissions |
| 51 | +- `vmmap` |
| 52 | + - Virtual size --> how much address space is reserved for the stack |
| 53 | + - Resident size --> how much physical RAM is being used |
| 54 | +- Demand paging |
| 55 | + - Declaring an array doesn't allocate physical RAM, you have to write to the memory |
| 56 | + - OS maps physical memory when you touch it |
| 57 | +## Byte write |
| 58 | +- File systems don't track individual bytes on disk |
| 59 | + - Space is allocated in fixed-size chunks (blocks) |
| 60 | + - Blocks are usually 4096 bytes (4 KiB) |
| 61 | + - Writing 1 byte still gets a 4 KiB block |
| 62 | +- Larger blocks === less bookkeeping overhead but more wasted space |
| 63 | +- `/dev/urandom` is an interface to the kernel's random number generator |
| 64 | +- File descriptor is a "handle" to an open file |
| 65 | + - More efficient for accessing a file (open once) |
| 66 | + - Keeps state (position tracking, etc.) |
0 commit comments