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

Always panics on assertion failed. #19

Open
hollmmax opened this issue Dec 27, 2022 · 2 comments
Open

Always panics on assertion failed. #19

hollmmax opened this issue Dec 27, 2022 · 2 comments

Comments

@hollmmax
Copy link

A panic occurs in this crate when using constellation-rs. The crate panics immediately, which makes constellation unusable.
The panic occurs in the assertion in timer.rs:98:13, as reported by backtrace.
After digging a bit I believe this is caused by the cast from time::Instant to timer::Instant, because time::Instant is defined as { i64, u32 }, whereas libc::timespec is defined as { i64, i64 }. This results in garbage data being read in the upper 32 bits of timer::Instant.t.t.tv_nsec. Comparing the mismatched values which triggered the assertion confirms the they do have the same lower 32 bits and the upper 32 bits of tv_nsec are non-zero.

@alecmocatta
Copy link
Owner

Thanks for surfacing this @hollmmax. I saw this a while back in TWIR and forgot I'd written (horrible) code depending on the layout of Instant.

Do you think there's a way to do this safely? Do we have to forego std::time::Instant compatibility? Or shall we continue the casting hack, and just update to the below?

https://github.com/rust-lang/rust/blob/0c0b403f19fc6febcd1e36a83fc307ecc11de943/library/std/src/sys/unix/time.rs#L12-L27

@hollmmax
Copy link
Author

I didn't dig deeper into why and how std::time::Instant compatibility is used, but it is, so I'll assume that dropping support for it would be more work elsewhere.
I'm also not sure what you mean by updating to the current std::time::Instant, because the problem comes from the difference between std::time::Instant and nix::libc::timespec.

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