Top Banner
Can Logic Tame Systems Programs? Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn, Matthew Parkinson,Viktor Vafeiadis, Hongseok Yang
59

Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Jul 23, 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: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Can Logic Tame Systems Programs?

Cristiano CalcagnoImperial College

Wroclaw, July 2007

Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn, Matthew Parkinson, Viktor Vafeiadis, Hongseok Yang

Page 2: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Beginning: Smallfoot

• Toy language

• Symbolic execution over SL fragment

• Annotations: pre/post and loop invariants

• Hard-coded predicates: list segments, trees (complete proof theory no induction)

• Concurrency: explicit || and ccr’s

Page 3: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Systems programs?

• Handling C (current project, using CIL)

• Inferring annotations: shape analysis

• Composite data structures (CAV): predicate discovery, parameterised lists

• Open code/modularity: footprint analysis

• Interprocedural analysis

• (non-blocking) concurrency

Page 4: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack3 5 7 11 13

TOP

Page 5: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

push(e) { local y,n,b; y = new(); y->val = e; b=0; while(b==0) { n = TOP->tl; y->tl = n; b = CAS(TOP->tl,n,y); }}

3 5 7 11 13TOP

Page 6: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

push(e) { local y,n,b; y = new(); y->val = e; b=0; while(b==0) { n = TOP->tl; y->tl = n; b = CAS(TOP->tl,n,y); }}

pop() { local y,z,b; b=0; while(b==0) { atomic when (TOP->tl != 0) { y = TOP->tl; z = y->tl; } b = CAS(TOP->tl,y,z); } ret = y->val; dispose y;}

3 5 7 11 13TOP

Page 7: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

3 5

7 11 13

TOP

Page 8: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

3 5

7 11 13

TOP

y = TOP->tl; z = y->tl;

Page 9: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

3 5

7 11 13

TOP

y z

y = TOP->tl; z = y->tl;

Page 10: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

3 5

7 11 13

TOP

y z

Page 11: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

3 5

7 11 13

TOP

y z

pop();

Page 12: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

5

7 11 13

TOP

y z

pop();

Page 13: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

5

7 11 13

TOP

y z

Page 14: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

5

7 11 13

TOP

y z

pop();

Page 15: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

7 11 13

TOP

y z

pop();

Page 16: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

7 11 13

TOP

y z

Page 17: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

7 11 13

TOP

y z

push(15);

Page 18: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

15

7 11 13

TOP

y z

push(15);

Page 19: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

15

7 11 13

TOP

y z

Page 20: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

15

7 11 13

TOP

y z

b = CAS(TOP->tl,y,z);

Page 21: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

15

7 11 13

TOP

y z

b = CAS(TOP->tl,y,z);

Page 22: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Non-Blocking Stack

15

7 11 13

TOP

y z

b = CAS(TOP->tl,y,z);

DANGLING!

Page 23: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Reasoning

Separation logic: separation

Rely-Guarantee: interference

Parkinson and Vafeiadis: SL + RG

• local and shared state

• actions

Page 24: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Reasoning

Separation logic: separation

Rely-Guarantee: interference

Parkinson and Vafeiadis: SL + RG

• local and shared state

• actions

Tool: SmallfootRG

Page 25: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Operations

Push

TOP TOP

Pop

TOP TOP

Page 26: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference

3 5

7 11 13

TOP

y z

Page 27: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference

3 5

7 11 13

TOP

y z

Page 28: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference

3 5

7 11 13

TOP

y z

TOP

y z

??

Page 29: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Operations (leaks)

Push

TOP TOP

Pop

TOP TOP

Page 30: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference (leaks)

7 11 13

TOP

3 5

y z

Page 31: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference (leaks)

7 11 13

TOP

3 5

y z1 of 2

Page 32: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference (leaks)

7 11 13

TOP

3 5

y z1 of 2

TOP

3

y

z

Page 33: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference (leaks)

7 11 13

TOP

3 5

y z2 of 2

Page 34: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Interference (leaks)

7 11 13

TOP

3 5

y z2 of 2

TOP

3

y z

Page 35: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Fragment

A ::= E = E | E != E | · · ·S ::= E "#E | lseg(E,E) | treeE | · · ·! ::= A1 $ · · · $An

" ::= S1 % · · · % Sn

P,Q ::= ! $ "

Shape Information Only

Page 36: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Symbolic Execution

Safe Preconditions (re-arrangement)

Px:=E

!!!!!!!" x = E[x!/x] # P [x!/x]

P $ E %"Fx:=[E]

!!!!!!!" x = F [x!/x] # (P $ E %"F )[x!/x]

P $ E %"F[E]:=F !

!!!!!!!" P $ E %"F !

Px:=new()!!!!!!!" P $ x%"!

P $ E %"Fdispose E!!!!!!!" P

Page 37: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

Page 38: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule

Page 39: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

Page 40: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

Page 41: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}{x!"l, r # tree(l) # tree(r)}

Page 42: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}{x!"l, r # tree(l) # tree(r)}

Page 43: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{x!"l, r # tree(l) # emp}{x!"l, r # tree(l) # tree(r)}

Page 44: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{x!"l, r # tree(l) # emp}{x!"l, r # tree(l) # tree(r)}

Page 45: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{x!"l, r # tree(l) # emp}{x!"l, r # emp # emp}

{x!"l, r # tree(l) # tree(r)}

Page 46: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{x!"l, r # tree(l) # emp}{x!"l, r # emp # emp}

{x!"l, r # tree(l) # tree(r)}

Page 47: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{emp ! emp ! emp}

{x!"l, r # tree(l) # emp}{x!"l, r # emp # emp}

{x!"l, r # tree(l) # tree(r)}

Page 48: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Frame Inference

{P}C{Q}{P ! R}C{Q ! R}

Frame Rule Frame Inference

P ! P ! " F

...dispose_tree(r);dispose_tree(l);dispose x;...

{tree(x)}dispose tree(x){emp}

{emp}

{x!"l, r # tree(l) # emp}{x!"l, r # emp # emp}

{x!"l, r # tree(l) # tree(r)}

Page 49: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Parallel

{P1}C1{Q1}{P2}C2{Q2}

{P1 ! P2}C1"C2{Q1 ! Q2}Parallel rule

Page 50: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Parallel

{P1}C1{Q1}{P2}C2{Q2}

{P1 ! P2}C1"C2{Q1 ! Q2}Parallel rule

Symbolic execution

{P1}proc1(){Q1}{P2}proc2(){Q2}X ! P1 " P2 " F

Xproc1();! proc2();#############$ Q1 "Q2 " F

Page 51: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Parallel

{P1}C1{Q1}{P2}C2{Q2}

{P1 ! P2}C1"C2{Q1 ! Q2}Parallel rule

No interleavings

Symbolic execution

{P1}proc1(){Q1}{P2}proc2(){Q2}X ! P1 " P2 " F

Xproc1();! proc2();#############$ Q1 "Q2 " F

Page 52: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Atomic

X ! S " X ! P ! F

X ! PC

##$ X !

X ! " Q ! Ystab(Q ! F ) = R

X ! Satomic C as Act;

#############$ Y ! R

where Act is P ! Q

Page 53: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Atomic

X ! S " X ! P ! F

X ! PC

##$ X !

X ! " Q ! Ystab(Q ! F ) = R

X ! Satomic C as Act;

#############$ Y ! R

where Act is P ! Q

Must be stable

Page 54: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Stability Inference

Stable assertion calculation:Sn+1 = ((P !! Sn) "Q) # Sn

Page 55: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Stability Inference

Stable assertion calculation:

Abstract domain: [Distefano et al.]Sn+1 = !((P !! Sn) "Q) # Sn

Sn+1 = ((P !! Sn) "Q) # Sn

Page 56: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Stability Inference

Stable assertion calculation:

Abstract domain: [Distefano et al.]

Septraction Elimination Procedure

Sn+1 = !((P !! Sn) "Q) # Sn

Sn+1 = ((P !! Sn) "Q) # Sn

Page 57: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Summary

Mechanisms:

• Symbolic execution

• Frame inference

• Abstraction

• Stability

Inferring actions?

Page 58: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Questions?

Page 59: Can Logic Tame Systems Programs?pkowa/slides/calcagno.pdf · Cristiano Calcagno Imperial College Wroclaw, July 2007 Joint work with Josh Berdine, Dino Distefano, Peter O’Hearn,

Septraction Elimination

(E !"E!) !F #$ F %= E & (E !"E!)(P &Q) !E #$ P !E &Q !E

(P 'Q) !E #$ P !E 'Q !E

(E !"E!)#! (F !"F !) $% E=F & E!=F ! & emp(E !"E!)#! (P 'Q) $% P "E '(E !"E! #! Q)

( (E !"E! #! P ) 'Q"E

(E !"E!)#! (P (Q) $% (E !"E! #! P ) ( (E !"E! #! Q)(P 'Q)#! R $% P #! (Q#! R)(P (Q)#! R $% (P #! R) ( (Q#! R)