rocq/theories/GetoptLogic.v
Reading getopt's libc cells
A program reads optarg and optind straight from libc's cells, which getopt rewrites at every call. The program owns neither cell: it owns a ghost token, getopt_ps, naming the values getopt last left there, and the world interpretation ties the token to the world's getopt state and the cells' memory (getopt_current, Campaign 4's getopt_state_at). A read of either cell is then an instruction whose result the world interpretation fixes (wp_world_let_with).
The key of the getopt token: no locale category's, not the codec's (-1), and no stream's (below -1).
The getopt token: optarg a and optind i.
The getopt token of h, if any, holds the getopt state g's optarg and optind.
A read access that passes at some alignment passes at alignment 1.
Explore proof 2 tactics
Initial goal
unfold access_res , cap_access_res , readonly_access_res , aligned_res
destruct c as | b | b | g | g ; try discriminate ; destruct object_regionb m_regionsm ; try discriminate ; destruct _ && _ ; try discriminate ; rewrite Z.mod_1_r ; reflexivity
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
Sign extension, cut back to its width, is the value cut to it.
Explore proof 9 tactics
Initial goal
intros Hm
unfold sign_extension
destruct hf ≤? x mod md
2 openfocused goal
–replace x mod md − md with x mod md + −1 × md by lia
2 opendeferred goal
rewrite Z.mod_add ; | lia
2 opendeferred goal
apply Z.mod_mod
2 opendeferred goal
lia
deferred goal
–apply Z.mod_mod
lia
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
A raw signed 32-bit load at offset off from the proven pointer p, whose read access passes: the four bytes there, as a W word.
Explore proof 10 tactics
Initial goal
intros H
assert E : op_resRawLoadLdNarrowSw off W WPtrp m = op_res_intRawLoadLdNarrowSw off W WPtrp m by reflexivity
rewrite E
cbn - [ access_res raw_address load_bytes extended ]
unfold int_load_res
cbn - [ access_res raw_address load_bytes extension ]
rewrite H
cbn - [ raw_address load_bytes extension ]
rewrite sign_extension_mod ; | lia
reflexivity
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
A pointer cell whose pieces agree with the memory, in a live object, holding a word-sized address whose capability's object is not freed, is a pointer_slot there: Campaign 4's reading of a stored pointer.
Explore proof 8 tactics
Initial goal
intros Hlv Hax Hcl Hr Hf
split ; exact Hr |
split
2 open–rewrite cell_loadm b reg o ptr_addrx b + o Hlv Hcl eq_refl
2 openapply Z.mod_small
2 openexact Hr
–destruct cell_bounds_ _ _ _ _ Hlv Hcl as Ho He
apply aux_holds_kept ; exact aux_piece_holds_ _ _ _ _ Hlv Hax | exact Hf
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
Reading getopt's cells over any runtime R and Logic instance.
The Iris instance of the registry and wi.
The expressions of the language.
The world's getopt state, through the projection view, is in the memory at the cells optarg_cell and optind_cell, whose addresses are words, and the getopt token is current.
The check of optarg's cell for an 8-byte read passes.
Explore proof 16 tactics
Initial goal
intros Hc Hx
iIntros HK
iAssert pts[ ] as Hn ; rewrite / pts ; done |
iApply wp_world_let_withregistry wi ge [ ] with Hn [HK] ; reflexivity | exact Hc | exact Hx | |
3 openfocused goal
shelved goal
–intros m w h Hw _
3 opendeferred goal
shelved goal
destruct Hgetopt_wi_ _ _ Hw as Hpc & _ & Hoc & _ & _
3 opendeferred goal
shelved goal
apply op_check
2 opendeferred goal
unfold raw_address
2 opendeferred goal
rewrite Z.add_0_r Z.mod_small ; | lia
2 opendeferred goal
cbn
2 opendeferred goal
destruct Hpc as _ & Hacc & _
2 opendeferred goal
rewrite Hoc in Hacc
2 opendeferred goal
exact Hacc
deferred goal
–iNext
iIntros _
iExact HK
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
The plain pointer load of optarg's cell: optarg a, as the token names it.
Explore proof 16 tactics
Initial goal
intros Hc Hx
iIntros Ht HK
iApply wp_world_let_with with Ht HK ; reflexivity | exact Hc | exact Hx |
intros m w h Hw Hl
destruct Hgetopt_wi_ _ _ Hw as Hpc & _ & Hoc & _ & Hcur
destruct Hcura i Hl_ _ ltac:left as Ha _
rewrite Hoc Ha in Hpc
assert Er : raw_addressptr_addroptarg_cell 0 = ptr_addroptarg_cell
2 openfocused goal
{unfold raw_address
2 opendeferred goal
rewrite Z.add_0_r
2 opendeferred goal
apply Z.mod_small
2 opendeferred goal
lia
deferred goal
apply op_raw_load_pointer ; rewrite Er
2 openfocused goal
–destruct Hpc as _ & Hacc & _
2 opendeferred goal
exact Hacc
deferred goal
–exact exposed_pointer_load_ _ _ Hpc
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
The check of optind's cell for a 4-byte read at alignment 1 passes.
Explore proof 16 tactics
Initial goal
intros Hc Hx
iIntros HK
iAssert pts[ ] as Hn ; rewrite / pts ; done |
iApply wp_world_let_withregistry wi ge [ ] with Hn [HK] ; reflexivity | exact Hc | exact Hx | |
3 openfocused goal
shelved goal
–intros m w h Hw _
3 opendeferred goal
shelved goal
destruct Hgetopt_wi_ _ _ Hw as _ & Hic & _ & _ & Hoc & _
3 opendeferred goal
shelved goal
apply op_check
2 opendeferred goal
unfold raw_address
2 opendeferred goal
rewrite Z.add_0_r Z.mod_small ; | lia
2 opendeferred goal
cbn
2 opendeferred goal
destruct Hic as _ & _ & Hacc & _
2 opendeferred goal
rewrite Hoc in Hacc
2 opendeferred goal
exact access_read_align1_ _ _ _ _ Hacc
deferred goal
–iNext
iIntros _
iExact HK
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
The signed 32-bit load of optind's cell: optind i, as the token names it, as a W word.
Explore proof 15 tactics
Initial goal
intros Hc Hx
iIntros Ht HK
iApply wp_world_let_with with Ht HK ; reflexivity | exact Hc | exact Hx |
intros m w h Hw Hl
destruct Hgetopt_wi_ _ _ Hw as _ & Hic & _ & _ & Hoc & Hcur
destruct Hcura i Hl_ _ ltac:left as _ Hi
rewrite Hoc Hi in Hic
destruct Hic as _ & _ & Hacc & _ & Hload
assert Er : raw_addressptr_addroptind_cell 0 = ptr_addroptind_cell
2 openfocused goal
{unfold raw_address
2 opendeferred goal
rewrite Z.add_0_r
2 opendeferred goal
apply Z.mod_small
2 opendeferred goal
lia
deferred goal
rewrite op_raw_load_sw ; rewrite Er ; | exact access_read_align1_ _ _ _ _ Hacc
rewrite Hload Z.mod_mod ; reflexivity | lia
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.