Skip to content

Commit 962b36b

Browse files
authored
Challenge proposal: NonNull (#52)
1 parent 957d2bb commit 962b36b

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

doc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
- [Pointer Arithmetic](./challenges/0003-pointer-arithmentic.md)
1919
- [Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md)
2020
- [Inductive data type](./challenges/0005-linked-list.md)
21+
- [Safety of NonNull](./challenges/0006-nonnull.md)
2122
- [Contracts for SmallSort](./challenges/0008-smallsort.md)
2223
- [Memory safety of String](./challenges/0010-string.md)

doc/src/challenges/0006-nonnull.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Challenge 6: Safety of NonNull
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/53)
5+
- **Start date:** *2024-08-16*
6+
- **End date:** *2024-12-10*
7+
8+
-------------------
9+
10+
11+
## Goal
12+
13+
Verify absence of undefined behavior of the [`ptr::NonNull` module](https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/non_null.rs).
14+
Most of its functions are marked `unsafe`, yet they are used in 62 other modules
15+
of the standard library.
16+
17+
### Success Criteria
18+
19+
Prove absence of undefined behavior of the following 48 public functions. You
20+
may wish to do so by attaching pre- and postconditions to these, and then (if
21+
needed by the tooling that you choose to use) adding verification harnesses.
22+
23+
1. `NonNull<T>::add`
24+
2. `NonNull<T>::addr`
25+
3. `NonNull<T>::align_offset`
26+
4. `NonNull<T>::as_mut<'a>`
27+
5. `NonNull<T>::as_mut_ptr`
28+
6. `NonNull<T>::as_non_null_ptr`
29+
7. `NonNull<T>::as_ptr`
30+
8. `NonNull<T>::as_ref<'a>`
31+
9. `NonNull<T>::as_uninit_mut<'a>`
32+
10. `NonNull<T>::as_uninit_ref<'a>`
33+
11. `NonNull<T>::as_uninit_slice<'a>`
34+
12. `NonNull<T>::as_uninit_slice_mut<'a>`
35+
13. `NonNull<T>::byte_add`
36+
14. `NonNull<T>::byte_offset_from<U: ?Sized>`
37+
15. `NonNull<T>::byte_offset`
38+
16. `NonNull<T>::byte_sub`
39+
17. `NonNull<T>::cast<U>`
40+
18. `NonNull<T>::copy_from_nonoverlapping`
41+
19. `NonNull<T>::copy_from`
42+
20. `NonNull<T>::copy_to_nonoverlapping`
43+
21. `NonNull<T>::copy_to`
44+
22. `NonNull<T>::dangling`
45+
23. `NonNull<T>::drop_in_place`
46+
24. `NonNull<T>::from_raw_parts`
47+
25. `NonNull<T>::get_unchecked_mut<I>`
48+
26. `NonNull<T>::is_aligned_to`
49+
27. `NonNull<T>::is_aligned`
50+
28. `NonNull<T>::is_empty`
51+
29. `NonNull<T>::len`
52+
30. `NonNull<T>::map_addr`
53+
31. `NonNull<T>::new_unchecked`
54+
32. `NonNull<T>::new`
55+
33. `NonNull<T>::offset_from`
56+
34. `NonNull<T>::offset`
57+
35. `NonNull<T>::read_unaligned`
58+
36. `NonNull<T>::read_volatile`
59+
37. `NonNull<T>::read`
60+
38. `NonNull<T>::replace`
61+
39. `NonNull<T>::slice_from_raw_parts`
62+
40. `NonNull<T>::sub_ptr`
63+
41. `NonNull<T>::sub`
64+
42. `NonNull<T>::swap`
65+
43. `NonNull<T>::to_raw_parts`
66+
44. `NonNull<T>::with_addr`
67+
45. `NonNull<T>::write_bytes`
68+
46. `NonNull<T>::write_unaligned`
69+
47. `NonNull<T>::write_volatile`
70+
48. `NonNull<T>::write`
71+
72+
### List of UBs
73+
74+
In addition to any properties called out as `SAFETY` comments in the source
75+
code,
76+
all proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
77+
78+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
79+
* Reading from uninitialized memory.
80+
* Mutating immutable bytes.
81+
* Producing an invalid value
82+
83+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
84+
in addition to the ones listed above.

0 commit comments

Comments
 (0)