程序代写代做代考 Operating Systems – Recap

Operating Systems – Recap

Admin
Correction: No class week 4 (not week 3 as advertised earlier)

Note on identifying information in Assignment 1

Cybersecurity seminars: Mondays 4-6pm IW B23

‹#›

Executing Programs

‹#›

Background: Operating systems
What are the roles of the operating system?

Present an abstraction of the hardware

Allow sharing of the hardware
Implies protection

‹#›

Computer Programs
An abstraction of a computation task
How do we execute a program?

‹#›

Program execution
Build
Compile – create relocatable object files
Link – create executable files
Run
Launch a process
Program
Processor
Libraries
OS Kernel

‹#›

An Executable File
A program in a form that
the operating system can
execute
Specifies:
Machine code to be executed
Initial data
Initial memory layout
Libraries to link with (and required functions)
Debug information
More…
Program
Processor
Libraries
OS Kernel

‹#›

Text
PH
SH
Data
Linkage
Debug info
ELF
(Executable and Linkable Format)
File format for binary programs
Relocatable objects
Executable files
Shared libraries
Program header – describes segments loaded when a program is launched
Section header – a table of sections, each representing one kind of data

‹#›

Heap
Stack

Text
Data
BSS
Global data:

// Non-zero –> data
char array[] = [‘a’, ‘b’];
// Zero –> bss
int n;
char * p
malloc(), new, etc.
Call stack:
Local variables
Parameters
Return values
Function linkage
Memory layout
A process executes within a virtual address space

Program code:
cmpq %rsi, %rdi
jge .L4
movl %edx, %eax
.L4:
ret

‹#›

Heap
Stack
Memory layout
A process executes within a virtual address space

Text
Data
BSS

‹#›

Heap
Stack
Memory layout
A process executes within a virtual address space

Text
Data
BSS

‹#›

Heap
Stack
Sharing text
Processes that execute the same program can share the text

Can also share the code of shared libraries

Text
Data
BSS

Shared
Library
Heap
Stack

Text
Data
BSS

Shared
Library

‹#›

Implementation – Virtual memory
The virtual address space is divided into fixed size pages
The physical memory is divided into page-sized frames
The OS maintains a mapping of pages to frames
The processor uses the map to convert virtual to physical addresses

Physical memory

Virtual address space

‹#›

Implementation – Virtual memory
Multiple processes can use the physical memory at the same time

Physical memory

Virtual address space

Another virtual address space

‹#›

Implementation – Virtual memory
Sharing is implemented by mapping the same physical page to multiple address spaces

Physical memory

Virtual address space

Another virtual address space
Need protection for non-collaborative sharing
Page maps include protection bits for Read/Write/Execute access

‹#›

Further down the rabbit hole
The mmap function maps a file to the virtual address space of a process.
Lazy mapping – nothing is really loaded in
memory
Virtual address mapping created
when the program
accesses the page

Virtual address space

Physical memory
Text
Data

‹#›

Copy-on-Write (COW)
Data lazily loaded – marked Read Only
The first time the program writes to the
data
The frame is copied
Page points to the new frame
The frame is modified

Virtual address space

Physical memory
Text
Data

‹#›

Page de-duplication
A memory-footprint-reduction technique that
Scans physical memory
Coalesces frames with identical contents
Uses COW to avoid interference

Physical memory

Virtual address space

Another virtual address space

‹#›

Class exercise
You want to check if “Discrete Child Tracker” is installed on your phone.
Discrete Child Tracker does not show up in your apps list
That’s not surprising – that’s why it’s called “discrete”
Your phone uses page de-duplication
How can you exploit this to check if the app is installed?

‹#›