SlideShare a Scribd company logo
cs4414 Fall 2013
University of Virginia
David Evans
Plan for Today
Some early comments on PS2 (how many
processes?)
Explicit vs. implicit memory management
Pointers in Rust
21 September 2013 University of Virginia cs4414 1
Notes for today will be posted later today.
21 September 2013 University of Virginia cs4414 2
How many processes should a
browser create?
21 September 2013 University of Virginia cs4414 3
New challenge for Exercise 1 & 2: what is the fewest number of processes you can
have running on your machine?
21 September 2013 University of Virginia cs4414 4
1990’s answer:
1 process since
processes waste
memory and CPU
which are expensive
and limited
21 September 2013 University of Virginia cs4414 5
2000s answer:
http://www.google.com/googlebooks/chrome/
21 September 2013 University of Virginia cs4414 6
21 September 2013 University of Virginia cs4414 7
21 September 2013 University of Virginia cs4414 8
“Start from Scratch” = start from scratch
constrained by using programming tools
and methods developed in the 1960s
What should the 2010s answer be?
21 September 2013 University of Virginia cs4414 9
21 September 2013 University of Virginia cs4414 10
Only two colors, but 4-8 cores!
(+ loads of GPU cores)
Samsung Galaxy S4
Apple iPhone 5C
Five colors, 2 cores!
Note: the colors vs. cores tradeoff can probably be overcome by good engineering,
but addressing the energy vs. cores tradeoffs require some theoretical advances also.
21 September 2013 University of Virginia cs4414 11
Humans should not
be getting bored and
grumpy waiting for
their browser to
render a page while
cores are sitting idle!
21 September 2013 University of Virginia cs4414 12
“Start from Scratch” = start from scratch
constrained by using programming tools
and methods developed in the 1960s
2010s answer:
21 September 2013 University of Virginia cs4414 13
A modern browser should have enough
processes to efficiently use all the machine
resources available to provide human users
with a good browsing experience!
Unfortunately, it is not
(humanly) possible to build such
a browser (in a way that will
also be secure, robust, and
reliable) using languages whose
primary design goal was to fit
on a 4K machine.
21 September 2013 University of Virginia cs4414 14
Why do our
Rust stickers
have a gear
on them?
Servo: the main reason
Rust is being developed is
so Mozilla can build a
better browser!
21 September 2013 University of Virginia cs4414 15
Really starting from
scratch is really hard…
this is why getting
Servo to the point
where it can render a
static page is cake-
worthy!
What Dave was doing when you
were learning to crawl…
21 September 2013 University of Virginia cs4414 16
21 September 2013 University of Virginia cs4414 17
ACM Foundations in Software Engineering, 1994
21 September 2013 University of Virginia cs4414 18
comp.os.linux post, August 1994
$ man malloc # on my Macbook Air
MALLOC(3) BSD Library Functions Manual
SYNOPSIS
...
void free(void *ptr);
void *malloc(size_t size);
...
DESCRIPTION
The malloc(), calloc(), valloc(), realloc(), and reallocf() functions
allocate memory. The allocated memory is aligned such that it can
be used for any data type, …. The free() function frees allocations
that were created via the preceding allocation functions.
The malloc() function allocates size bytes of memory and returns a
pointer to the allocated memory.
MemorymanagementinC
21 September 2013 University of Virginia cs4414 19
21 September 2013 University of Virginia cs4414 20
# include <stdlib.h>
# include <stdio.h>
int main(int _argc, char **_argv) {
int *x = (int *) malloc (sizeof(*x));
*x = 4414;
printf("x = %dn", *x);
return 0;
}
gash> gcc -Wall toofree.c
gash> ./a.out
x = 4414
21 September 2013 University of Virginia cs4414 21
# include <stdlib.h>
# include <stdio.h>
int main(int _argc, char **_argv) {
int *x = (int *) malloc (sizeof(*x));
*x = 4414;
free(x);
printf("x = %dn", *x);
return 0;
}
gash> gcc -Wall toofree.c
gash> ./a.out
x = 4414
21 September 2013 University of Virginia cs4414 22
# include <stdlib.h>
# include <stdio.h>
int main(int _argc, char **_argv) {
int *x = (int *) malloc (sizeof(*x));
*x = 4414;
free(x);
free(x);
printf("x = %dn", *x);
return 0;
}
gash> gcc -Wall toofree.c
gash> ./a.out
a.out(23685) malloc: *** error for object 0x10a1008d0:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Note: this is what happens to
happen on my computer, but the C
behavior is undefined. It would be
“correct” for a C program like this
to do absolutely anything!
This gets
tricky…
21 September 2013 University of Virginia cs4414 23
(from locale.h)
struct lconv
{
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
… } ;
// in my code…
struct lconv *local = localeconv (void);
…
free(local->decimal_point); // ?
free(local); // ?
Should we really care?
21 September 2013 University of Virginia cs4414 24
November 2009
21 September 2013 University of Virginia cs4414 25
21 September 2013 University of Virginia cs4414 26
21 September 2013 University of Virginia cs4414 27
http://www.phrack.org/issues.html?issue=61&id=6
(Why) Doesn’t C++ solve this?
21 September 2013 University of Virginia cs4414 28
new = malloc
delete = free
Doesn’t Java solve this?
21 September 2013 University of Virginia cs4414 29
21 September 2013 University of Virginia cs4414 30
21 September 2013 University of Virginia cs4414 31
(Advanced “comic book” version of GC)
21 September 2013 University of Virginia cs4414 32
Getting back to my story…
“Willy-Nilly” Memory Management
21 September 2013 University of Virginia cs4414 33
Systematic Memory Management
21 September 2013 University of Virginia cs4414 34
Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
21 September 2013 University of Virginia cs4414 35
Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
21 September 2013 University of Virginia cs4414 36
Note: these are “compile-time” errors (just produced by a separate tool).
Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
21 September 2013 University of Virginia cs4414 37
Annotations?
Where we are going,
we don’t need
annotations!
21 September 2013 University of Virginia cs4414 38
A box is a reference to a heap allocation holding another value.
There are two kinds of boxes: managed boxes and owned boxes.
An owned box type or value is constructed by the prefix tilde sigil ~.
Rust Manual, Section 9.1.4
extern /*@only@*/ char *gname;
void setName(/*@temp@*/ char *pname) {
gname = pname;
}
21 September 2013 University of Virginia cs4414 39
A box is a reference to a heap allocation holding another value.
There are two kinds of boxes: managed boxes and owned boxes.
An owned box type or value is constructed by the prefix tilde sigil ~.
Rust Manual, Section 9.1.4
extern /*@only@*/ char *gname;
void setName(/*@temp@*/ char *pname) {
gname = pname;
}
static gname : ~str = ~"";
fn set_name(pname : &str) {
gname = pname;
}
*Note: we can’t really have a global, owned string like this in Rust.+
21 September 2013 University of Virginia cs4414 40
extern /*@only@*/ char *gname;
void setName(/*@temp@*/ char *pname) {
gname = pname;
}
gash> splint sample.c
sample.c:5: Only storage gname not released before assignment:
gname = pname
sample.c:1: Storage gname becomes only
sample.c:5: Temp storage pname assigned to only: gname = pname
sample.c:3: Storage pname becomes temp
static gname : ~str = ~"Where we're going, we don't need roads!”;
fn set_name(pname : &str) {
gname = pname;
}
gash> rustc sample.rs
sample.rs:4:12: 4:17 error: mismatched types: expected `~str` but found `&str`
(str storage differs: expected ~ but found &)
sample.rs:4 gname = pname;
21 September 2013 University of Virginia cs4414 41
static gname : ~str = ~"annotations";
fn set_name(pname : ~str) {
gname = pname;
}
fn main() {
set_name("roads");
}
gash> rustc sample2.rs
sample2.rs:8:13: 8:20 error: mismatched types: expected
`~str` but found `&'static str` (str storage differs: expected ~
but found &'static )
sample2.rs:8 set_name("roads");
21 September 2013 University of Virginia cs4414 42
fn set_name(gname : &mut ~str, pname : ~str) {
*gname = pname;
}
fn main() {
let mut gname : ~str = ~"annotations";
println(fmt!("gname = %s", gname));
set_name(&mut gname, ~"frees");
println(fmt!("gname = %s", gname));
}
gash> rust run good.rs
gname = annotations
gname = frees
21 September 2013 University of Virginia cs4414 43
Why doesn’t Rust complain about the missing free?
fn set_name(gname : &mut ~str, pname : ~str) {
*gname = pname;
}
21 September 2013 University of Virginia cs4414 44
Free()s?
Where we are going,
we don’t need free()s!
21 September 2013 University of Virginia cs4414 45
PS2 is due Monday Sept 30.
You can use any language you want for this, but if
your submission has any double-free vulnerabilities,
buffer overflow vulnerabilities, or memory leaks you
get a -10 on this assignment.
Managing memory safely and explicitly gets really
complicated since we often do want to share
objects. We’ll talk about pointer types Rust
provides for more complex sharing next class.
Charge
Next class: complexities of memory
management
PS2 is due Monday, 30 September
21 September 2013 University of Virginia cs4414 46
https://botbot.me/mozilla/rust/

More Related Content

Viewers also liked

OOP in Rust
OOP in RustOOP in Rust
OOP in Rust
KENZ_gelsoft
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engine
Bruno Abinader
 
Kernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtKernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring Naught
David Evans
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
Kel Cecil
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Julien Fitzpatrick
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
pramode_ce
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzz
Franklin Chen
 
RUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming RuminationsRUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming Ruminations
Angelo Corsaro
 
Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems Programming
C4Media
 

Viewers also liked (9)

OOP in Rust
OOP in RustOOP in Rust
OOP in Rust
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engine
 
Kernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtKernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring Naught
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzz
 
RUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming RuminationsRUSTing -- Partially Ordered Rust Programming Ruminations
RUSTing -- Partially Ordered Rust Programming Ruminations
 
Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems Programming
 

Similar to What the &~#@&lt;!? (Memory Management in Rust)

Virtual Memory (Making a Process)
Virtual Memory (Making a Process)Virtual Memory (Making a Process)
Virtual Memory (Making a Process)
David Evans
 
Once Upon a Process
Once Upon a ProcessOnce Upon a Process
Once Upon a Process
David Evans
 
Managing Memory
Managing MemoryManaging Memory
Managing Memory
David Evans
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel Space
David Evans
 
Access Control
Access ControlAccess Control
Access Control
David Evans
 
Storage Systems
Storage SystemsStorage Systems
Storage Systems
David Evans
 
Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)
David Evans
 
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxeSFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
South Tyrol Free Software Conference
 
RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)
Daniel Nüst
 
Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1ArangoDB Database
 
Fundamentals of Computing
Fundamentals of ComputingFundamentals of Computing
Fundamentals of Computing
Jan Wedekind
 
Benchmarking
BenchmarkingBenchmarking
Benchmarking
David Evans
 
Infrastructure as Software - PuppetConf 2014
Infrastructure as Software - PuppetConf 2014Infrastructure as Software - PuppetConf 2014
Infrastructure as Software - PuppetConf 2014
Puppet
 
Lessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet AgentsLessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet Agents
Puppet
 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)
kim.mens
 
Bridging the gap between designers and developers at the Guardian
Bridging the gap between designers and developers at the GuardianBridging the gap between designers and developers at the Guardian
Bridging the gap between designers and developers at the Guardian
Kaelig Deloumeau-Prigent
 
Taming AEM deployments
Taming AEM deploymentsTaming AEM deployments
Taming AEM deployments
Jakub Wadolowski
 
Scikit-learn: the state of the union 2016
Scikit-learn: the state of the union 2016Scikit-learn: the state of the union 2016
Scikit-learn: the state of the union 2016
Gael Varoquaux
 
Trick-or-Treat Protocols
Trick-or-Treat ProtocolsTrick-or-Treat Protocols
Trick-or-Treat Protocols
David Evans
 

Similar to What the &~#@&lt;!? (Memory Management in Rust) (20)

Virtual Memory (Making a Process)
Virtual Memory (Making a Process)Virtual Memory (Making a Process)
Virtual Memory (Making a Process)
 
Once Upon a Process
Once Upon a ProcessOnce Upon a Process
Once Upon a Process
 
Managing Memory
Managing MemoryManaging Memory
Managing Memory
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel Space
 
Access Control
Access ControlAccess Control
Access Control
 
Storage Systems
Storage SystemsStorage Systems
Storage Systems
 
Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)
 
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxeSFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
 
RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)
 
Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1
 
Fundamentals of Computing
Fundamentals of ComputingFundamentals of Computing
Fundamentals of Computing
 
Benchmarking
BenchmarkingBenchmarking
Benchmarking
 
Infrastructure as Software - PuppetConf 2014
Infrastructure as Software - PuppetConf 2014Infrastructure as Software - PuppetConf 2014
Infrastructure as Software - PuppetConf 2014
 
Lessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet AgentsLessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet Agents
 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)
 
Bridging the gap between designers and developers at the Guardian
Bridging the gap between designers and developers at the GuardianBridging the gap between designers and developers at the Guardian
Bridging the gap between designers and developers at the Guardian
 
Taming AEM deployments
Taming AEM deploymentsTaming AEM deployments
Taming AEM deployments
 
Text adventure
Text adventureText adventure
Text adventure
 
Scikit-learn: the state of the union 2016
Scikit-learn: the state of the union 2016Scikit-learn: the state of the union 2016
Scikit-learn: the state of the union 2016
 
Trick-or-Treat Protocols
Trick-or-Treat ProtocolsTrick-or-Treat Protocols
Trick-or-Treat Protocols
 

More from David Evans

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

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

What the &~#@&lt;!? (Memory Management in Rust)

  • 1. cs4414 Fall 2013 University of Virginia David Evans
  • 2. Plan for Today Some early comments on PS2 (how many processes?) Explicit vs. implicit memory management Pointers in Rust 21 September 2013 University of Virginia cs4414 1 Notes for today will be posted later today.
  • 3. 21 September 2013 University of Virginia cs4414 2
  • 4. How many processes should a browser create? 21 September 2013 University of Virginia cs4414 3 New challenge for Exercise 1 & 2: what is the fewest number of processes you can have running on your machine?
  • 5. 21 September 2013 University of Virginia cs4414 4 1990’s answer: 1 process since processes waste memory and CPU which are expensive and limited
  • 6. 21 September 2013 University of Virginia cs4414 5 2000s answer: http://www.google.com/googlebooks/chrome/
  • 7. 21 September 2013 University of Virginia cs4414 6
  • 8. 21 September 2013 University of Virginia cs4414 7
  • 9. 21 September 2013 University of Virginia cs4414 8 “Start from Scratch” = start from scratch constrained by using programming tools and methods developed in the 1960s
  • 10. What should the 2010s answer be? 21 September 2013 University of Virginia cs4414 9
  • 11. 21 September 2013 University of Virginia cs4414 10 Only two colors, but 4-8 cores! (+ loads of GPU cores) Samsung Galaxy S4 Apple iPhone 5C Five colors, 2 cores! Note: the colors vs. cores tradeoff can probably be overcome by good engineering, but addressing the energy vs. cores tradeoffs require some theoretical advances also.
  • 12. 21 September 2013 University of Virginia cs4414 11 Humans should not be getting bored and grumpy waiting for their browser to render a page while cores are sitting idle!
  • 13. 21 September 2013 University of Virginia cs4414 12 “Start from Scratch” = start from scratch constrained by using programming tools and methods developed in the 1960s
  • 14. 2010s answer: 21 September 2013 University of Virginia cs4414 13 A modern browser should have enough processes to efficiently use all the machine resources available to provide human users with a good browsing experience! Unfortunately, it is not (humanly) possible to build such a browser (in a way that will also be secure, robust, and reliable) using languages whose primary design goal was to fit on a 4K machine.
  • 15. 21 September 2013 University of Virginia cs4414 14 Why do our Rust stickers have a gear on them? Servo: the main reason Rust is being developed is so Mozilla can build a better browser!
  • 16. 21 September 2013 University of Virginia cs4414 15 Really starting from scratch is really hard… this is why getting Servo to the point where it can render a static page is cake- worthy!
  • 17. What Dave was doing when you were learning to crawl… 21 September 2013 University of Virginia cs4414 16
  • 18. 21 September 2013 University of Virginia cs4414 17 ACM Foundations in Software Engineering, 1994
  • 19. 21 September 2013 University of Virginia cs4414 18 comp.os.linux post, August 1994
  • 20. $ man malloc # on my Macbook Air MALLOC(3) BSD Library Functions Manual SYNOPSIS ... void free(void *ptr); void *malloc(size_t size); ... DESCRIPTION The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The allocated memory is aligned such that it can be used for any data type, …. The free() function frees allocations that were created via the preceding allocation functions. The malloc() function allocates size bytes of memory and returns a pointer to the allocated memory. MemorymanagementinC 21 September 2013 University of Virginia cs4414 19
  • 21. 21 September 2013 University of Virginia cs4414 20 # include <stdlib.h> # include <stdio.h> int main(int _argc, char **_argv) { int *x = (int *) malloc (sizeof(*x)); *x = 4414; printf("x = %dn", *x); return 0; } gash> gcc -Wall toofree.c gash> ./a.out x = 4414
  • 22. 21 September 2013 University of Virginia cs4414 21 # include <stdlib.h> # include <stdio.h> int main(int _argc, char **_argv) { int *x = (int *) malloc (sizeof(*x)); *x = 4414; free(x); printf("x = %dn", *x); return 0; } gash> gcc -Wall toofree.c gash> ./a.out x = 4414
  • 23. 21 September 2013 University of Virginia cs4414 22 # include <stdlib.h> # include <stdio.h> int main(int _argc, char **_argv) { int *x = (int *) malloc (sizeof(*x)); *x = 4414; free(x); free(x); printf("x = %dn", *x); return 0; } gash> gcc -Wall toofree.c gash> ./a.out a.out(23685) malloc: *** error for object 0x10a1008d0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap: 6 Note: this is what happens to happen on my computer, but the C behavior is undefined. It would be “correct” for a C program like this to do absolutely anything!
  • 24. This gets tricky… 21 September 2013 University of Virginia cs4414 23 (from locale.h) struct lconv { char *decimal_point; char *thousands_sep; char *grouping; char *int_curr_symbol; char *currency_symbol; … } ; // in my code… struct lconv *local = localeconv (void); … free(local->decimal_point); // ? free(local); // ?
  • 25. Should we really care? 21 September 2013 University of Virginia cs4414 24 November 2009
  • 26. 21 September 2013 University of Virginia cs4414 25
  • 27. 21 September 2013 University of Virginia cs4414 26
  • 28. 21 September 2013 University of Virginia cs4414 27 http://www.phrack.org/issues.html?issue=61&id=6
  • 29. (Why) Doesn’t C++ solve this? 21 September 2013 University of Virginia cs4414 28 new = malloc delete = free
  • 30. Doesn’t Java solve this? 21 September 2013 University of Virginia cs4414 29
  • 31. 21 September 2013 University of Virginia cs4414 30
  • 32. 21 September 2013 University of Virginia cs4414 31 (Advanced “comic book” version of GC)
  • 33. 21 September 2013 University of Virginia cs4414 32 Getting back to my story…
  • 34. “Willy-Nilly” Memory Management 21 September 2013 University of Virginia cs4414 33 Systematic Memory Management
  • 35. 21 September 2013 University of Virginia cs4414 34 Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
  • 36. 21 September 2013 University of Virginia cs4414 35 Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
  • 37. 21 September 2013 University of Virginia cs4414 36 Note: these are “compile-time” errors (just produced by a separate tool). Static Detection of Dynamic Memory Errors, David Evans, PLDI May 1996
  • 38. 21 September 2013 University of Virginia cs4414 37 Annotations? Where we are going, we don’t need annotations!
  • 39. 21 September 2013 University of Virginia cs4414 38 A box is a reference to a heap allocation holding another value. There are two kinds of boxes: managed boxes and owned boxes. An owned box type or value is constructed by the prefix tilde sigil ~. Rust Manual, Section 9.1.4 extern /*@only@*/ char *gname; void setName(/*@temp@*/ char *pname) { gname = pname; }
  • 40. 21 September 2013 University of Virginia cs4414 39 A box is a reference to a heap allocation holding another value. There are two kinds of boxes: managed boxes and owned boxes. An owned box type or value is constructed by the prefix tilde sigil ~. Rust Manual, Section 9.1.4 extern /*@only@*/ char *gname; void setName(/*@temp@*/ char *pname) { gname = pname; } static gname : ~str = ~""; fn set_name(pname : &str) { gname = pname; } *Note: we can’t really have a global, owned string like this in Rust.+
  • 41. 21 September 2013 University of Virginia cs4414 40 extern /*@only@*/ char *gname; void setName(/*@temp@*/ char *pname) { gname = pname; } gash> splint sample.c sample.c:5: Only storage gname not released before assignment: gname = pname sample.c:1: Storage gname becomes only sample.c:5: Temp storage pname assigned to only: gname = pname sample.c:3: Storage pname becomes temp static gname : ~str = ~"Where we're going, we don't need roads!”; fn set_name(pname : &str) { gname = pname; } gash> rustc sample.rs sample.rs:4:12: 4:17 error: mismatched types: expected `~str` but found `&str` (str storage differs: expected ~ but found &) sample.rs:4 gname = pname;
  • 42. 21 September 2013 University of Virginia cs4414 41 static gname : ~str = ~"annotations"; fn set_name(pname : ~str) { gname = pname; } fn main() { set_name("roads"); } gash> rustc sample2.rs sample2.rs:8:13: 8:20 error: mismatched types: expected `~str` but found `&'static str` (str storage differs: expected ~ but found &'static ) sample2.rs:8 set_name("roads");
  • 43. 21 September 2013 University of Virginia cs4414 42 fn set_name(gname : &mut ~str, pname : ~str) { *gname = pname; } fn main() { let mut gname : ~str = ~"annotations"; println(fmt!("gname = %s", gname)); set_name(&mut gname, ~"frees"); println(fmt!("gname = %s", gname)); } gash> rust run good.rs gname = annotations gname = frees
  • 44. 21 September 2013 University of Virginia cs4414 43 Why doesn’t Rust complain about the missing free? fn set_name(gname : &mut ~str, pname : ~str) { *gname = pname; }
  • 45. 21 September 2013 University of Virginia cs4414 44 Free()s? Where we are going, we don’t need free()s!
  • 46. 21 September 2013 University of Virginia cs4414 45 PS2 is due Monday Sept 30. You can use any language you want for this, but if your submission has any double-free vulnerabilities, buffer overflow vulnerabilities, or memory leaks you get a -10 on this assignment. Managing memory safely and explicitly gets really complicated since we often do want to share objects. We’ll talk about pointer types Rust provides for more complex sharing next class.
  • 47. Charge Next class: complexities of memory management PS2 is due Monday, 30 September 21 September 2013 University of Virginia cs4414 46 https://botbot.me/mozilla/rust/