@ -308,14 +308,14 @@ Definition interval_to_set_def:
End
End
Definition interval_ok_def :
Definition interval_ok_def :
interval_ok ( _, i1 , i2 ) ⇔
interval_ok ( ( _: bool ) , i1 , i2 ) ⇔
i1 ≤ i2 ∧ i2 < 2 ** 64
i1 ≤ i2 ∧ i2 < 2 ** 64
End
End
Definition is_allocated_def :
Definition is_allocated_def :
is_allocated b1 allocs ⇔
is_allocated b1 allocs ⇔
interval_ok b1 ∧
interval_ok b1 ∧
∃b2. b2 ∈ allocs ∧ interval_to_set b1 ⊆ interval_to_set b2
∃b2. b2 ∈ allocs ∧ fst b1 = fst b2 ∧ interval_to_set b1 ⊆ interval_to_set b2
End
End
Definition is_free_def :
Definition is_free_def :
@ -324,23 +324,29 @@ Definition is_free_def:
∀b2. b2 ∈ allocs ⇒ interval_to_set b1 ∩ interval_to_set b2 = ∅
∀b2. b2 ∈ allocs ⇒ interval_to_set b1 ∩ interval_to_set b2 = ∅
End
End
Definition set_bytes_def :
( set_bytes p [ ] n h = h ) ∧
( set_bytes p ( b :: bs ) n h =
set_bytes p bs ( Suc n ) ( h |+ ( A n , ( p , b ) ) ) )
End
(* A l l o c a t e a f r e e c h u n k o f m e m o r y , a n d w r i t e n o n - d e t e r m i n i s t i c b y t e s i n t o i t *)
Inductive allocate :
Inductive allocate :
( v2n v. value = Some m ∧
v2n v. value = Some m ∧
b = ( T , w2n w , w2n w + m * len ) ∧
b = ( T , w2n w , w2n w + m * len ) ∧
is_free b s. allocations
is_free b s. allocations ∧
length bytes = m * len
⇒
⇒
allocate s v len
allocate s v len
( <| poison := v. poison ; value := PtrV w |> ,
( <| poison := v. poison ; value := PtrV w |> ,
s with allocations := { b } ∪ s. allocations ) )
s with <| allocations := { b } ∪ s. allocations ;
heap := set_bytes v. poison bytes ( w2n w ) s. heap |> )
End
End
Definition deallocate_def :
Definition deallocate_def :
( deallocate ( A n ) ( Some allocs ) =
deallocate addrs allocs h =
if ∃m. ( T , n , m ) ∈ allocs then
let to_remove = { ( T , n , stop ) | A n ∈ set addrs ∧ ( T , n , stop ) ∈ allocs } in
Some { ( b , start , stop ) | ( b , start , stop ) ∈ allocs ∧ start ≠ n }
( allocs DIFF to_remove , fdiff h ( image A ( bigunion ( image interval_to_set to_remove ) ) ) )
else
None ) ∧
( deallocate _ None = None )
End
End
Definition get_bytes_def :
Definition get_bytes_def :
@ -406,12 +412,6 @@ Termination
decide_tac
decide_tac
End
End
Definition set_bytes_def :
( set_bytes p [ ] n h = h ) ∧
( set_bytes p ( b :: bs ) n h =
set_bytes p bs ( Suc n ) ( h |+ ( A n , ( p , b ) ) ) )
End
Definition do_sub_def :
Definition do_sub_def :
do_sub ( nuw : bool ) ( nsw : bool ) ( v1 : pv ) ( v2 : pv ) =
do_sub ( nuw : bool ) ( nsw : bool ) ( v1 : pv ) ( v2 : pv ) =
let ( diff , u_overflow , s_overflow ) =
let ( diff , u_overflow , s_overflow ) =
@ -476,16 +476,17 @@ End
Inductive step_instr :
Inductive step_instr :
( s. stack = fr :: st ∧
( s. stack = fr :: st ∧
FOLDR deallocate ( Some s. allocations ) fr. stack_allocs = Some new_allocs
deallocate fr. stack_allocs s. allocations s. heap = ( new_allocs , new_h )
⇒
⇒
step_instr prog s
step_instr prog s
( Ret ( t , a ) )
( Ret ( t , a ) )
( update_result fr. result_var ( eval s a )
( update_result fr. result_var ( eval s a )
<| ip := fr. ret ;
<| ip := fr. ret ;
globals := s. globals ;
locals := fr. saved_locals ;
locals := fr. saved_locals ;
stack := st ;
stack := st ;
allocations := new_allocs ;
allocations := new_allocs ;
heap := heap |> ) ) ∧
heap := new_ h |> ) ) ∧
(* D o t h e p h i a s s i g n m e n t s i n p a r a l l e l . T h e m a n u a l s a y s " F o r t h e p u r p o s e s o f t h e
(* D o t h e p h i a s s i g n m e n t s i n p a r a l l e l . T h e m a n u a l s a y s " F o r t h e p u r p o s e s o f t h e
* SSA form , the use of each incoming value is deemed to occur on the edge from
* SSA form , the use of each incoming value is deemed to occur on the edge from
@ -542,7 +543,7 @@ Inductive step_instr:
( inc_pc ( update_result r v2 s2 ) ) ) ∧
( inc_pc ( update_result r v2 s2 ) ) ) ∧
( eval s a1 = <| poison := p1 ; value := PtrV w |> ∧
( eval s a1 = <| poison := p1 ; value := PtrV w |> ∧
interval = ( b, w2n w , w2n w + sizeof t ) ∧
interval = ( freea ble , w2n w , w2n w + sizeof t ) ∧
is_allocated interval s. allocations ∧
is_allocated interval s. allocations ∧
pbytes = get_bytes s. heap interval
pbytes = get_bytes s. heap interval
⇒
⇒
@ -553,7 +554,7 @@ Inductive step_instr:
s ) ) ) ∧
s ) ) ) ∧
( eval s a2 = <| poison := p2 ; value := PtrV w |> ∧
( eval s a2 = <| poison := p2 ; value := PtrV w |> ∧
interval = ( b, w2n w , w2n w + sizeof t ) ∧
interval = ( freea ble , w2n w , w2n w + sizeof t ) ∧
is_allocated interval s. allocations ∧
is_allocated interval s. allocations ∧
bytes = value_to_bytes ( eval s a1 ) .value ∧
bytes = value_to_bytes ( eval s a1 ) .value ∧
length bytes = sizeof t
length bytes = sizeof t
@ -642,13 +643,12 @@ Definition allocations_ok_def:
i1 ∈ s. allocations ∧ i2 ∈ s. allocations
i1 ∈ s. allocations ∧ i2 ∈ s. allocations
⇒
⇒
interval_ok i1 ∧ interval_ok i2 ∧
interval_ok i1 ∧ interval_ok i2 ∧
( interval_to_set i1 ∩ interval_to_set i2 ≠ ∅ ⇒
( interval_to_set i1 ∩ interval_to_set i2 ≠ ∅ ⇒ i1 = i2 )
interval_to_set i1 = interval_to_set i2 )
End
End
Definition heap_ok_def :
Definition heap_ok_def :
heap_ok s ⇔
heap_ok s ⇔
∀ i n. i ∈ s. allocations ∧ n ∈ interval_to_set i ⇒ flookup s. heap ( A n ) ≠ None
∀ n. flookup s. heap ( A n ) ≠ None ⇔ ∃i. i ∈ s. allocations ∧ n ∈ interval_to_set i
End
End
Definition globals_ok_def :
Definition globals_ok_def :
@ -702,7 +702,8 @@ End
Definition stack_ok_def :
Definition stack_ok_def :
stack_ok p s ⇔
stack_ok p s ⇔
every ( frame_ok p s ) s. stack
every ( frame_ok p s ) s. stack ∧
all_distinct ( flat ( map ( λf. f. stack_allocs ) s. stack ) )
End
End
Definition state_invariant_def :
Definition state_invariant_def :