CSE 451
Operating Systems
L3 - The Kernel Abstraction - 2
Slides by: Tom Anderson
Baris Kasikci
Question
Memory management – limit memory access
Mode switch in CPU – privilege mode
In user mode, not change memory limit
Dual-Mode Operation
sector, send/read any packet
Privilege levels in x86
A Model of a CPU
Dual-Mode Operation
Hardware Support for Dual-Mode Operation
Privileged instructions
Change the page table for an application
Change the mode (kernel mode -> restriction on where I am running the code to handle the switch)
Fault/exception
Simple Memory Protection
What Happens When Isolation Fails?
Physical Memory
Virtual Addresses
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size page frames
Virtual Address Example
int staticVar = 0; // a static variable main() {
int localVar = 0; // a procedure local variable
staticVar += 1;
localVar += 1;
sleep(10); // sleep for x seconds
printf ("static address: %x, value: %d\n", &staticVar, staticVar); printf (”local address: %x, value: %d\n", &localVar, localVar);
}
What if we run two instances of this program at the same time?
Virtual Addresses
Virtual Address != Physical Address
Hardware Timer
User->Kernel Mode Switch
Some Exceptions
Some More Exceptions
Trap and Emulate
System Calls
UNIX systems calls (1972)
Kernel System Call Handler
How Many User<->Kernel Transitions?
| | | |
| | | |
| | | |
User/Kernel Virtual Addresses
Why dup?
A shell is a user application that runs other programs
% grep “To be or not” Shakespeare.txt
shell creates process “grep”, with arguments; outputs to stdout
% grep “To be or not” Shakespeare.txt > logfile
shell creates process “grep”, with arguments; outputs to logfile
fd = open(“logfile”)
close(stdout)
dup(fd) -> grep uses logfile as its stdout
% grep “To be or not” Shakespeare.txt | wc
Shell creates two processes, “grep” and “wc”
A pipe provides one-way communication between two processes
Shell sets stdout of grep to be one end of pipe; stdin of wc to be the other
Kernel->User Mode Switch
Restoring User State
How do we take interrupts/exceptions safely?
Interrupt Vector on x86
Kernel (Interrupt) Stack
interrupted user process?
Interrupt Stack
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Interrupt Masking
Interrupt Handlers
Case Study: x86 Interrupt (Hardware Support)
During Interrupt
|
|
|
|
|
|
|
|
|
|
Aft er Interrupt
|
|
|
xk
At end of handler
Question
Question
Upcall: User-level event delivery
Upcalls vs Interrupts
Upcall: Before
|
|
|
Upcall: During
|
|
|