You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
But since r0 will fill the entire memory range between the pointers, it ends up calling offset with values that create pointers well beyond the u32 the static is declared to contain. According to the docs of offset, this is UB:
Both the starting and resulting pointer must be either in bounds or one byte past the end of the same allocated object. Note that in Rust, every (stack-allocated) variable is considered a separate allocated object.
(every static also counts as its own "allocated object", I believe)
Moreover, the ptr::write and ptr::write_volatile calls in r0 also cause UB, because this invariant is violated:
For a pointer to be valid, it is necessary, but not always sufficient, that the pointer be dereferenceable: the memory range of the given size starting at the pointer must all be within the bounds of a single allocated object. Note that in Rust, every (stack-allocated) variable is considered a separate allocated object.
...but again, we are crossing between potentially many allocated objects (every static in the .data/.bss section).
Furthermore, writing to a static through a pointer not derived from that static might violate aliasing rules, but it isn't yet clear if this is the case today (I've asked the folks working on the unsafe code guidelines for clarification / guidance).
The most robust solution for this issue is to write the RAM init code in assembly instead of Rust, and run no Rust code at all until RAM is initialized.
(this issue was recently discovered to affect most -rt crates in the ecosystem; we do not believe it to cause practical issues at the moment)
The text was updated successfully, but these errors were encountered:
RAM initialization currently passes pointers to these
static
s:riscv-rt/src/lib.rs
Lines 346 to 355 in 47ece5f
...to
r0
:riscv-rt/src/lib.rs
Lines 381 to 382 in 47ece5f
But since r0 will fill the entire memory range between the pointers, it ends up calling
offset
with values that create pointers well beyond theu32
the static is declared to contain. According to the docs ofoffset
, this is UB:(every
static
also counts as its own "allocated object", I believe)Moreover, the
ptr::write
andptr::write_volatile
calls in r0 also cause UB, because this invariant is violated:Where the validity of a pointer requires this:
...but again, we are crossing between potentially many allocated objects (every
static
in the.data
/.bss
section).Furthermore, writing to a static through a pointer not derived from that static might violate aliasing rules, but it isn't yet clear if this is the case today (I've asked the folks working on the unsafe code guidelines for clarification / guidance).
The most robust solution for this issue is to write the RAM init code in assembly instead of Rust, and run no Rust code at all until RAM is initialized.
(this issue was recently discovered to affect most -rt crates in the ecosystem; we do not believe it to cause practical issues at the moment)
The text was updated successfully, but these errors were encountered: