Top Banner
A heap, a stack, a bottle and a rack
15

A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc//maps The Stack - The working memory. “Canary Birds” (and other stuff on the

Jul 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

A heap, a stack, a bottle and a rack

Page 2: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 3: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

/proc/<pid>/maps

Page 4: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

The Stack

- The working memory.

Page 5: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

“Canary Birds” (and other stuff on the stack)

- Can be hard to identify all objects on the stack

- Canary birds: To ensure nothing is broken

- Other scap data: To align memory

- Can help to optimize compile (-O) if you want to identify all items

Page 6: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

The heap

(S)heap

- malloc

- When we need more permanent data

- Called “dynamic data” in previous figure

Page 7: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

Exam question 1

What is done in the procedure below and where should gurka be allocated?Why? Complete the code so that gurka is allocated space.

Page 8: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

Exam question 2

Page 9: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 10: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 11: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

Answer: The first three segments are: code, read-only data and global data for the running process gurka. Then there is a segment for the heap. The segment marked with lib-2.23.so is a shared library. In the uppermost region we nd the segment of the stack.

Page 12: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 13: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 14: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the
Page 15: A heap, a stack, a bottle and a rack - KTH...A heap, a stack, a bottle and a rack /proc/<pid>/maps The Stack - The working memory. “Canary Birds” (and other stuff on the

Relevant Sections from the Book

For reading at your own time

● Chapter 13 - The Abstraction: Address Spaces● Chapter 14 - Interlude: Memory API