Skip to content

WIP Remove static muts from examples#513

Closed
tlevora wants to merge 3 commits into
stm32-rs:masterfrom
tlevora:remove-static-muts
Closed

WIP Remove static muts from examples#513
tlevora wants to merge 3 commits into
stm32-rs:masterfrom
tlevora:remove-static-muts

Conversation

@tlevora

@tlevora tlevora commented Dec 7, 2024

Copy link
Copy Markdown
Contributor

No description provided.

richardeoin and others added 3 commits December 7, 2024 09:19
For the future, need to investigate:
* How to implement DMA without requiring the lifetime of the buffer to be
'static
* How to specific the link_section of non-static buffers
@richardeoin

Copy link
Copy Markdown
Member

As discussed in #512, dereferencing a static of type StaticCell with #[link_section = ".."] is UB if the runtime doesn't initialise the memory area specified by link_section.

I think it should be something like

#[link_section = ".axisram.eth"]
static DES_RING: MaybeUninit<SomeKindOfUnsafeCell<ethernet::DesRing<4, 4>>> = MaybeUninit::uninit();

but need to work out what SomeKindOfUnsafeCell is exactly

@usbalbin

Copy link
Copy Markdown
Member

Also related rust-embedded/cortex-m#538

@Joker2770

Joker2770 commented Dec 17, 2024

Copy link
Copy Markdown

Is it OK to use core::mem::transmute?

unsafe { mem::transmute(buf) }

@tlevora

tlevora commented Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

I am sorry I haven't replied here for a long time.

I like #518 and do not have a better solution, so that closing this PR. In specific situations I would use something like https://crates.io/crates/linker-sections, but probably not here.

@tlevora tlevora closed this Feb 19, 2025
@tlevora
tlevora deleted the remove-static-muts branch February 19, 2025 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants