Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt: Add framework for creating heap statics #64

Open
str4d opened this issue May 10, 2023 · 5 comments
Open

rt: Add framework for creating heap statics #64

str4d opened this issue May 10, 2023 · 5 comments

Comments

@str4d
Copy link
Contributor

str4d commented May 10, 2023

Normal Rust binaries will initialize heap statics on start, and then essentially leak the memory. This works fine because the memory is cleaned up during process exit. We can't assume the same with a FAP, so if we want to support "statics", we should provide a way in the runtime for initializing them before the user's app code runs, and freeing them after it exits.

@str4d str4d mentioned this issue May 10, 2023
@dcoles
Copy link
Collaborator

dcoles commented May 10, 2023

In this case you're talking about statics that are stored on the heap (from lazy_static, once_cell), rather than static data stored in the .rodata right?

@str4d
Copy link
Contributor Author

str4d commented May 10, 2023

Yep. People could still use one of those crates, but I believe it would get reported as a memory leak by the FZ tooling.

@str4d str4d changed the title rt: Add framework for creating statics rt: Add framework for creating heap statics May 10, 2023
@dcoles
Copy link
Collaborator

dcoles commented May 27, 2023

It might be possible to provide a factory function for OnceCell that registers the static for cleanup. Calling the take method takes ownership of the inner value allowing them to be dropped.

@str4d
Copy link
Contributor Author

str4d commented May 28, 2023

We can't use once_cell because it requires std for Mutex. I'm instead planning on using generic_once_cell, which works for any mutex that implements lock_api::RawMutex. I've implemented the latter locally, and opened #74 with an Instant impl that I need.

@dcoles
Copy link
Collaborator

dcoles commented May 29, 2023

We can't use once_cell because it requires std for Mutex.

I think it's possible to use with #[no-std] as long as you provide a critical-section implementation. I might take a look at that today, since a number of embedded crates are based around it.

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

No branches or pull requests

2 participants