SlideShare a Scribd company logo
1 of 29
Plan for Today
Between libc and the kernel
PS3 Benchmarking Results
Project Time

7 November 2013

University of Virginia cs4414

1
Rust Runtime

Recap
run::Process::new(program, argv, options)
spawn_process_os(prog, args, env, dir, in_fd, …)
fork()
Today
libc: fork()
linux kernel: fork syscall

7 November 2013

University of Virginia cs4414

2
libstd/rt/io/native/process.rs

#[cfg(unix)]
fn spawn_process_os(prog: &str, args: &[~str],
env: Option<~[(~str, ~str)]>, dir: Option<&Path>,
in_fd: c_int, out_fd: c_int, err_fd: c_int) -> SpawnProcessResult {
…
#[cfg(not(target_os = "macos"), not(windows))]
unsafe fn set_environ(envp: *c_void) {
extern {
static mut environ: *c_void;
}
environ = envp;
}
unsafe {

let pid = fork();
if pid < 0 {
fail!("failure in fork: {}", os::last_os_error());
} else if pid > 0 {
return SpawnProcessResult {pid: pid, handle: ptr::null()};
}
… // 25 lines of failure-handing code
}

7 November 2013

University of Virginia cs4414

3
Test Program
use std::libc::funcs::posix88::unistd::fork;
#[fixed_stack_segment]
fn main() {
let pid = unsafe { fork() } ;
println(fmt!("pid = %?", pid));
}

7 November 2013

University of Virginia cs4414

> rustc fork.rs
> ./fork
pid = 0i32
pid = 15039i32
$ ./fork
pid = 15043i32
pid = 0i32
4
use std::libc::funcs::posix88::unistd::fork;

> rustc -O -S fork.rs
> wc -l fork.S
72 fork.S

#[fixed_stack_segment]
fn main() { unsafe { fork() } ; }
.section
__TEXT,__text,regular,pure_instructio
ns
.align 4, 0x90
__ZN4main18h8b6694fe33a5855ag4
v0.0E:
.cfi_startproc
leaq -2097152(%rsp), %r11
cmpq %gs:816, %r11
ja LBB0_2
movabsq $2097152, %r10
movabsq $0, %r11
callq ___morestack
ret
LBB0_2:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp

7 November 2013

Ltmp4:
.cfi_def_cfa_register %rbp
popq %rbp

jmp

_fork

.cfi_endproc
.globl _main
.align 4, 0x90
_main:
.cfi_startproc
cmpq %gs:816, %rsp
ja LBB1_2
movabsq $8, %r10
movabsq $0, %r11
callq ___morestack
ret
LBB1_2:
pushq %rbp
Ltmp7:
.cfi_def_cfa_offset 16
Ltmp8:
.cfi_offset %rbp, -16
movq %rsp, %rbp

University of Virginia cs4414

Ltmp9:
.cfi_def_cfa_register %rbp
movq %rsi, %rax
movq %rdi, %rcx
movq %rsi, %rax
movq %rdi, %rcx
leaq __ZN4main18h8b6694fe33a5855ag4v0.0E(%rip), %rsi
xorl %edi, %edi
movq %rcx, %rdx
movq %rax, %rcx
popq %rbp
jmp __ZN8unstable4lang5start17hf72eb8b3c3a0a9ac4v0.8E
.cfi_endproc

.section
__DATA,__data
.globl __rust_crate_map_toplevel
.align 4
__rust_crate_map_toplevel:
.long 1
.space 4
.quad __rust_mod_map
.quad __rust_crate_map_std_0.8_6c65cf4b443341b1
.quad 0
.zerofill __DATA,__bss,__rust_mod_map,16,3
.section
__TEXT,__const
.globl _rust_abi_version
.align 3
_rust_abi_version:
.quad 1

.subsections_via_symbols

5
Could actual call to kernel
fork be a regular call?

7 November 2013

University of Virginia cs4414

6
Rust Runtime

Entering the Kernel
run::Process::new(program, argv, options)
spawn_process_os(prog, args, env, dir, in_fd, …)
fork()
libc: fork()
linux kernel: fork syscall

7 November 2013

University of Virginia cs4414

7
Supervisor Mode
Kernel code needs (or at least uses)
special privileges!
What would happen if user-level code could
just jump into kernel code?

7 November 2013

University of Virginia cs4414

8
Entering the Kernel
User-Level Code
…
movl $SYS_fork,%eax
int
$0x80
int instruction generates an interrupt

7 November 2013

University of Virginia cs4414

9
Traditional PC Design
Programmable
Interrupt
Controller

CPU

(PIC)

Keyboard
7 November 2013

Interval Timer
University of Virginia cs4414

10
Page 2213 of Intel x86 Manual:
http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf

Modern x86 Design:
“APIC” = “Advanced PIC”

7 November 2013

University of Virginia cs4414

11
Page 2213 of Intel x86 Manual:
http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf

What should generate a
“Local Interrupt”?

7 November 2013

What should generate an
“External Interrupt”?

University of Virginia cs4414

12
7 November 2013

University of Virginia cs4414

13
7 November 2013

University of Virginia cs4414

14
7 November 2013

University of Virginia cs4414

15
…
movl $SYS_fork,%eax
int
$0x80

Programmable
Interrupt
Controller

(PIC)

7 November 2013

University of Virginia cs4414

Handling
Syscall
Interrupts

CPU
16
7 November 2013

University of Virginia cs4414

17
7 November 2013

University of Virginia cs4414

18
Intel manual, p. 146:

7 November 2013

University of Virginia cs4414

19
7 November 2013

University of Virginia cs4414

20
Rust Runtime

Running in Supervisor Mode
run::Process::new(program, argv, options)
spawn_process_os(prog, args, env, dir, in_fd, …)
fork()
int 0x80

libc: fork()
jumps into kernel code
sets supervisor mode

linux kernel: fork syscall
7 November 2013

University of Virginia cs4414

21
PS3 Bakeoff Winners
13.2, 5701.3

Average Response Time (milliseconds)

6,000

5,000
9.7, 3908.1

4,000

217.1, 3902.7

reference zhtta

3,000

2,000
44.0, 989.7
39.8, 960.8

1,000

225.2, 531.3
5.5, 0.6

0

0

50

100

150

200

Total Duration (seconds)
5 November 2013

University of Virginia cs4414

23
8pm Friday
Rouss/Robertson Hall Room 120
7 November 2013

University of Virginia cs4414

24
Decoy Project!

7 November 2013

University of Virginia cs4414

25
7 November 2013

University of Virginia cs4414

26
13.2, 5701.3

6,000

Average Response Time (milliseconds)

Kiet, Mark, Tanmoy
5,000
9.7, 3908.1

4,000

217.1, 3902.7

reference zhtta

3,000

2,000
44.0, 989.7
39.8, 960.8

Hong, Jireh, Marshall

Chris, Tong, Yicheng

1,000

225.2, 531.3
5.5, 0.6

0

0

Harriet, Kevin, Zeming
50

100

150

200

Total Duration (seconds)
5 November 2013

University of Virginia cs4414

27
Charge
Find a team and project!

Decoy projects are only allowed in security classes.
Sneaking around my house is no longer permitted.

7 November 2013

University of Virginia cs4414

28

More Related Content

What's hot

The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
Kevin Lo
 

What's hot (20)

Kernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtKernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring Naught
 
System Calls
System CallsSystem Calls
System Calls
 
Managing Memory
Managing MemoryManaging Memory
Managing Memory
 
SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and Scheduling
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)
 
The Internet
The InternetThe Internet
The Internet
 
Scheduling in Linux and Web Servers
Scheduling in Linux and Web ServersScheduling in Linux and Web Servers
Scheduling in Linux and Web Servers
 
How to write memory efficient code?
How to write memory efficient code?How to write memory efficient code?
How to write memory efficient code?
 
Once Upon a Process
Once Upon a ProcessOnce Upon a Process
Once Upon a Process
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
How & why-memory-efficient?
How & why-memory-efficient?How & why-memory-efficient?
How & why-memory-efficient?
 
EBtree - Design for a Scheduler and Use (Almost) Everywhere
EBtree - Design for a Scheduler and Use (Almost) EverywhereEBtree - Design for a Scheduler and Use (Almost) Everywhere
EBtree - Design for a Scheduler and Use (Almost) Everywhere
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
Lec11 timing
Lec11 timingLec11 timing
Lec11 timing
 
Python twisted
Python twistedPython twisted
Python twisted
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
 
Flash! (Modern File Systems)
Flash! (Modern File Systems)Flash! (Modern File Systems)
Flash! (Modern File Systems)
 
Microkernels and Beyond
Microkernels and BeyondMicrokernels and Beyond
Microkernels and Beyond
 
Lec07 threading hw
Lec07 threading hwLec07 threading hw
Lec07 threading hw
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 

Similar to Crossing into Kernel Space

Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
Jian-Hong Pan
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
Kan-Ru Chen
 
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing WorldCloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
Omer Kilic
 

Similar to Crossing into Kernel Space (20)

Transparent GPU Exploitation for Java
Transparent GPU Exploitation for JavaTransparent GPU Exploitation for Java
Transparent GPU Exploitation for Java
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
Deep Learning Edge
Deep Learning Edge Deep Learning Edge
Deep Learning Edge
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
 
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
 
App container rkt
App container rktApp container rkt
App container rkt
 
PL-4044, OpenACC on AMD APUs and GPUs with the PGI Accelerator Compilers, by ...
PL-4044, OpenACC on AMD APUs and GPUs with the PGI Accelerator Compilers, by ...PL-4044, OpenACC on AMD APUs and GPUs with the PGI Accelerator Compilers, by ...
PL-4044, OpenACC on AMD APUs and GPUs with the PGI Accelerator Compilers, by ...
 
Getting started with Intel IoT Developer Kit
Getting started with Intel IoT Developer KitGetting started with Intel IoT Developer Kit
Getting started with Intel IoT Developer Kit
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Optimizing NN inference performance on Arm NEON and Vulkan
Optimizing NN inference performance on Arm NEON and VulkanOptimizing NN inference performance on Arm NEON and Vulkan
Optimizing NN inference performance on Arm NEON and Vulkan
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
 
Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear Containers
 
You're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security SoftwareYou're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security Software
 
maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87
 
PGCon 2014 - What Do You Mean my Database Server Core Dumped? - How to Inspec...
PGCon 2014 - What Do You Mean my Database Server Core Dumped? - How to Inspec...PGCon 2014 - What Do You Mean my Database Server Core Dumped? - How to Inspec...
PGCon 2014 - What Do You Mean my Database Server Core Dumped? - How to Inspec...
 
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing WorldCloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
Cloud, Distributed, Embedded: Erlang in the Heterogeneous Computing World
 
Innovation with pcDuino
Innovation with pcDuinoInnovation with pcDuino
Innovation with pcDuino
 

More from David Evans

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Crossing into Kernel Space

  • 1.
  • 2. Plan for Today Between libc and the kernel PS3 Benchmarking Results Project Time 7 November 2013 University of Virginia cs4414 1
  • 3. Rust Runtime Recap run::Process::new(program, argv, options) spawn_process_os(prog, args, env, dir, in_fd, …) fork() Today libc: fork() linux kernel: fork syscall 7 November 2013 University of Virginia cs4414 2
  • 4. libstd/rt/io/native/process.rs #[cfg(unix)] fn spawn_process_os(prog: &str, args: &[~str], env: Option<~[(~str, ~str)]>, dir: Option<&Path>, in_fd: c_int, out_fd: c_int, err_fd: c_int) -> SpawnProcessResult { … #[cfg(not(target_os = "macos"), not(windows))] unsafe fn set_environ(envp: *c_void) { extern { static mut environ: *c_void; } environ = envp; } unsafe { let pid = fork(); if pid < 0 { fail!("failure in fork: {}", os::last_os_error()); } else if pid > 0 { return SpawnProcessResult {pid: pid, handle: ptr::null()}; } … // 25 lines of failure-handing code } 7 November 2013 University of Virginia cs4414 3
  • 5. Test Program use std::libc::funcs::posix88::unistd::fork; #[fixed_stack_segment] fn main() { let pid = unsafe { fork() } ; println(fmt!("pid = %?", pid)); } 7 November 2013 University of Virginia cs4414 > rustc fork.rs > ./fork pid = 0i32 pid = 15039i32 $ ./fork pid = 15043i32 pid = 0i32 4
  • 6. use std::libc::funcs::posix88::unistd::fork; > rustc -O -S fork.rs > wc -l fork.S 72 fork.S #[fixed_stack_segment] fn main() { unsafe { fork() } ; } .section __TEXT,__text,regular,pure_instructio ns .align 4, 0x90 __ZN4main18h8b6694fe33a5855ag4 v0.0E: .cfi_startproc leaq -2097152(%rsp), %r11 cmpq %gs:816, %r11 ja LBB0_2 movabsq $2097152, %r10 movabsq $0, %r11 callq ___morestack ret LBB0_2: pushq %rbp Ltmp2: .cfi_def_cfa_offset 16 Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp 7 November 2013 Ltmp4: .cfi_def_cfa_register %rbp popq %rbp jmp _fork .cfi_endproc .globl _main .align 4, 0x90 _main: .cfi_startproc cmpq %gs:816, %rsp ja LBB1_2 movabsq $8, %r10 movabsq $0, %r11 callq ___morestack ret LBB1_2: pushq %rbp Ltmp7: .cfi_def_cfa_offset 16 Ltmp8: .cfi_offset %rbp, -16 movq %rsp, %rbp University of Virginia cs4414 Ltmp9: .cfi_def_cfa_register %rbp movq %rsi, %rax movq %rdi, %rcx movq %rsi, %rax movq %rdi, %rcx leaq __ZN4main18h8b6694fe33a5855ag4v0.0E(%rip), %rsi xorl %edi, %edi movq %rcx, %rdx movq %rax, %rcx popq %rbp jmp __ZN8unstable4lang5start17hf72eb8b3c3a0a9ac4v0.8E .cfi_endproc .section __DATA,__data .globl __rust_crate_map_toplevel .align 4 __rust_crate_map_toplevel: .long 1 .space 4 .quad __rust_mod_map .quad __rust_crate_map_std_0.8_6c65cf4b443341b1 .quad 0 .zerofill __DATA,__bss,__rust_mod_map,16,3 .section __TEXT,__const .globl _rust_abi_version .align 3 _rust_abi_version: .quad 1 .subsections_via_symbols 5
  • 7. Could actual call to kernel fork be a regular call? 7 November 2013 University of Virginia cs4414 6
  • 8. Rust Runtime Entering the Kernel run::Process::new(program, argv, options) spawn_process_os(prog, args, env, dir, in_fd, …) fork() libc: fork() linux kernel: fork syscall 7 November 2013 University of Virginia cs4414 7
  • 9. Supervisor Mode Kernel code needs (or at least uses) special privileges! What would happen if user-level code could just jump into kernel code? 7 November 2013 University of Virginia cs4414 8
  • 10. Entering the Kernel User-Level Code … movl $SYS_fork,%eax int $0x80 int instruction generates an interrupt 7 November 2013 University of Virginia cs4414 9
  • 11. Traditional PC Design Programmable Interrupt Controller CPU (PIC) Keyboard 7 November 2013 Interval Timer University of Virginia cs4414 10
  • 12. Page 2213 of Intel x86 Manual: http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf Modern x86 Design: “APIC” = “Advanced PIC” 7 November 2013 University of Virginia cs4414 11
  • 13. Page 2213 of Intel x86 Manual: http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf What should generate a “Local Interrupt”? 7 November 2013 What should generate an “External Interrupt”? University of Virginia cs4414 12
  • 14. 7 November 2013 University of Virginia cs4414 13
  • 15. 7 November 2013 University of Virginia cs4414 14
  • 16. 7 November 2013 University of Virginia cs4414 15
  • 17. … movl $SYS_fork,%eax int $0x80 Programmable Interrupt Controller (PIC) 7 November 2013 University of Virginia cs4414 Handling Syscall Interrupts CPU 16
  • 18. 7 November 2013 University of Virginia cs4414 17
  • 19. 7 November 2013 University of Virginia cs4414 18
  • 20. Intel manual, p. 146: 7 November 2013 University of Virginia cs4414 19
  • 21. 7 November 2013 University of Virginia cs4414 20
  • 22. Rust Runtime Running in Supervisor Mode run::Process::new(program, argv, options) spawn_process_os(prog, args, env, dir, in_fd, …) fork() int 0x80 libc: fork() jumps into kernel code sets supervisor mode linux kernel: fork syscall 7 November 2013 University of Virginia cs4414 21
  • 24. 13.2, 5701.3 Average Response Time (milliseconds) 6,000 5,000 9.7, 3908.1 4,000 217.1, 3902.7 reference zhtta 3,000 2,000 44.0, 989.7 39.8, 960.8 1,000 225.2, 531.3 5.5, 0.6 0 0 50 100 150 200 Total Duration (seconds) 5 November 2013 University of Virginia cs4414 23
  • 25. 8pm Friday Rouss/Robertson Hall Room 120 7 November 2013 University of Virginia cs4414 24
  • 26. Decoy Project! 7 November 2013 University of Virginia cs4414 25
  • 27. 7 November 2013 University of Virginia cs4414 26
  • 28. 13.2, 5701.3 6,000 Average Response Time (milliseconds) Kiet, Mark, Tanmoy 5,000 9.7, 3908.1 4,000 217.1, 3902.7 reference zhtta 3,000 2,000 44.0, 989.7 39.8, 960.8 Hong, Jireh, Marshall Chris, Tong, Yicheng 1,000 225.2, 531.3 5.5, 0.6 0 0 Harriet, Kevin, Zeming 50 100 150 200 Total Duration (seconds) 5 November 2013 University of Virginia cs4414 27
  • 29. Charge Find a team and project! Decoy projects are only allowed in security classes. Sneaking around my house is no longer permitted. 7 November 2013 University of Virginia cs4414 28