Week 6 Flashcards

1
Q

What is the stack?

A

The stack is used for local variables and all fo the data needed to make function calling work.

The stack is implicitly managed memory (automatic memory).

Every change of the stack pointer is either an allocation or deallocation of memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the heap?

A

The heap is used for user-managed, dynamically allocated memory.

One common interface to heap is Libc’s malloc() and free() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain malloc and free.

A

malloc(size) allocates a size number of bytes from the heap and returns a void pointer to those bytes.

free() takes a pointer to some previously allocated heap memory and deallocates that memory.

Under the hood these functions using systems calls (e.g sbrk) to request memory from the OS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are these common memory errors.
Buffer overflow:
Unintialized reads:
Memory leaks:
Use-after-free
Double frees:
Invalid frees:

A

Buffer overflow: writing or reading past the end of an allocated area

Unintialized reads: reading from allocated memory before it has been initialized

Memory leaks: forgetting to free memory

Use-after-free: using memory after it has been freed.

Double frees: free a block that was previously freed.

Invalid frees: calling free with the wrong pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are these implementation goals for memory management.

Transparency
Efficiency
Protection

A

Transparency: OS should implement virtual memory in a way that is invisible to the process

Efficiency: Structures used to support memory virtualization shouldn’t take up too much space.

Protection: OS must protect the process memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are stack canaries?

What is stack smashing?

A

Stack canaries are a type of software defense that attempts to mitigate buffer overflow attacks.

Stack smashing is a classic attack in which an attacker attempts to write beyond the bounds of a local variable to modify the return address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or flase, stack canaries are automatically added by modern compilers for functions with buffers that might overflow.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the pros of the stack? What are some cons?

A

Pros: Allocations and deallocation are really fast because we only need to add or subtract from the stack pointer. Supports variable sized allocations

Cons: Can only allocate and deallocate objects in the reverse order they are allocated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is direct mapping? What are some pros and cons.

A

Direct mapping: Give all of physical memory to the process.

Pros: Simple, the process knows exactly where every byte of memory is.

Cons: Where does the OS go? What if I want to run one more process.

Uses: microcontroller-based embedded systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is dynamic relocation?

A

Divides the memory in slots and each process gets a slot.

Physical address is equal to the base of the physical memory region plus the virtual address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we implement the translation done in dynamic relocation in hardware?

A

We need a base register and a bounds register and privileged instructions to set the register’s value.

Typically we call the associated hardware component the Memory Management Unit (MMU).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Where does the OS fit in with dynamic relocation.

A

It handles the allocation and management.

The OS has to decide where to place the process.

The OS must save the values upon a context switch

The OS must provide exception handlers to “take care” of those processes that don’t follow the rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is dynamic relocation?

A

Dynamic relocation divides the memory in slots and each process gets a slot.

Physical address is equal to the base of the physical memory region, plus the virtual address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the pros and cons of dynamic relocation?

A

Pros: simple; translations are transparent and fast, allocation is easy and protection is straight forward.

Cons: Wasted space, internal fragmentation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is segmentaion?

A

Idea: let’s split up the address space, storing each segment (heap, stack, code) separately.

SegmentL continguous portion of the address space of an arbitrary length.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the pros and cons of segmentation?

A

Pros: Better ultilization of phyiscal memory

Cons: Segments can be different sizes, now the OS has to worry about finding space.

External fragmentation: little holes between segments, might have enough space free for a new process but it is not contiguous.

17
Q

What is the approach for paging?

A

Divide both the physical memory and the virtual address space of each process into small fixed size chunks called pages (or page frames).

18
Q

In paging, how do we know what to look for?

A

We use a virtual page number. It is just the highest order bits.