Skip to content

Commit ed570af

Browse files
committed
reorganized active discussions
1 parent e0de5d2 commit ed570af

12 files changed

+113
-0
lines changed

active_discussion.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Areas of active discussion

active_discussion/aliasing.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Aliasing and memory model
2+
3+
## Brief Summary
4+
5+
Rust's borrow checker enforces some particular aliasing
6+
requirements. For example, an `&u32` reference is always guaranteed to
7+
be valid (dereferenceable) and immutable while it is in active
8+
use. Similarly, an `&mut` reference cannot alias any other active
9+
reference. It is less clear how those invariants translate to unsafe
10+
code that is using raw pointers.
11+
12+
## See also
13+
14+
- ACA model https://github.com/nikomatsakis/rust-memory-model/issues/26
15+
- Capability-based model https://github.com/nikomatsakis/rust-memory-model/issues/28
16+
- A formal C memory model supporting integer-pointer casts https://github.com/nikomatsakis/rust-memory-model/issues/30
17+
- Promising semantics for relaxed-memory concurrency https://github.com/nikomatsakis/rust-memory-model/issues/32
18+
- Tootsie Pop model https://github.com/nikomatsakis/rust-memory-model/issues/21

active_discussion/crypto_concerns.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Cryptographic concerns
2+
3+
There are a number of concerns that arise when writing cryptographic
4+
code. This chapter summarizes some of them.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Constant time code
2+
3+
It is often important to be able to turn off optimizations and
4+
guarantee that code executes in constant time to prevent side-channel
5+
attacks based on timing.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Keeping secrets
2+
3+
When storing cryptographic keys, crypto code wants to be sure that the
4+
compiler will not insert loads or stores that were not present in the
5+
source. Moreover, it wants to be able to zero memory and know that no
6+
bits from that memory "escape" into registers etc.
7+
8+
## See also
9+
10+
- https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188
11+
- https://github.com/nikomatsakis/rust-memory-model/issues/16

active_discussion/representation.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Data structure representation
2+
3+
In general, Rust makes few guarantees about memory layout, unless you
4+
define your structs as `#[repr(rust)]`. But there are some things that
5+
we do guarantee. Let's write about them.
6+
7+
TODO:
8+
9+
- Find and link to the various RFCs
10+
- Enumerate things that we *might* in fact guarantee, even for non-C types:
11+
- e.g., `&T` and `Option<&T>` are both pointer sized
12+
- size of `extern fn` etc (at least on some platforms)?
13+
- For which `T` is `None` represented as a "null pointer" etc?
14+
- (Which "niche" optimizations can we rely on)

active_discussion/stable_addresses.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Stable addresses
2+
3+
Clearly, if you have a `&T` reference, the actual pointer address of
4+
that memory must remain valid while **that reference** is in active
5+
use. But how stable are the memory addresses of local variables in
6+
between borrows? Consider:
7+
8+
```rust
9+
let x = 22;
10+
foo(&x);
11+
foo(&x);
12+
13+
fn foo(y: &usize) { .. }
14+
```
15+
16+
Is `foo` guaranteed to be given the same pointer each time? Note that
17+
safe code can observe the pointer value by doing `y as *const usize as
18+
usize`. If, however, the answer is no, that is helpful to the compiler
19+
since it can spill `x` only while it is borrowed but otherwise simply
20+
store `x` in a register.
21+
22+
**Range of possible answers:**
23+
24+
- local variables have stable addresses (de facto true today)
25+
- local variables have stable addresses while borrowed, but may change betwen borrows (would be nice)

active_discussion/storage_liveness.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Storage liveness
2+
3+
If you move out from a variable, can you still use the underlying stack space?
4+
5+
```rust
6+
{
7+
let mut x: Vec<u32> = ....;
8+
let p: *mut Vec<u32> = &mut x;
9+
drop(x); // compiler can see `x` is uninitialized
10+
11+
// what happens if you use `p` here?
12+
} // StorageDead(x)
13+
```
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Uninhabited types like `!` and exhaustiveness
2+
3+
TBD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Uninitialized memory
2+
3+
TBD

active_discussion/unions.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unions
2+
3+
TBD

projects.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Projects related to Unsafe Code Guidelines
2+
3+
## Blogs and other related discussions
4+
* [Stacked Borrows: An Aliasing Model for Rust](https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html)
5+
* [Two Kinds of Invariants: Safety and Validity](https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html)
6+
* [An alias-based formulation of the borrow checker](http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/)
7+
8+
9+
## Code and Tools
10+
11+
Any code projects related to the effort should be included here:
12+
* [Miri](https://github.com/solson/miri)
13+
* [unsafe-unicorn](https://github.com/avadacatavra/unsafe-unicorn): naive text-based analysis for unsafe usage

0 commit comments

Comments
 (0)