Skip to content

fix unsoundness in Exception code FFI conversion#27

Merged
sonodima merged 1 commit into
sonodima:masterfrom
smichaku:fix-unsound-exception
May 4, 2026
Merged

fix unsoundness in Exception code FFI conversion#27
sonodima merged 1 commit into
sonodima:masterfrom
smichaku:fix-unsound-exception

Conversation

@smichaku

@smichaku smichaku commented May 3, 2026

Copy link
Copy Markdown
Contributor

The C stub previously wrote a u32 directly into a #[repr(u32)] enum field, which is undefined behavior when the raised exception code is not covered by ExceptionCode's 24 variants.

Store the raw u32 in Exception and convert via a safe match in From, mapping unknown codes to ExceptionCode::Invalid. Expose Exception::raw_code() so callers can still inspect the raw value when the kernel produces a code outside the enum.

The C stub previously wrote a u32 directly into a #[repr(u32)] enum
field, which is undefined behavior when the raised exception code is
not covered by ExceptionCode's 24 variants.

Store the raw u32 in Exception and convert via a safe match in
From<u32>, mapping unknown codes to ExceptionCode::Invalid. Expose
Exception::raw_code() so callers can still inspect the raw value when
the kernel produces a code outside the enum.
@sonodima sonodima merged commit 8f6d891 into sonodima:master May 4, 2026
2 checks passed
@sonodima

sonodima commented May 4, 2026

Copy link
Copy Markdown
Owner

lgtm, thank you! 🚀

@smichaku

smichaku commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Great. Thanks! Do intend to bump the version anytime soon?

@sonodima

sonodima commented May 5, 2026

Copy link
Copy Markdown
Owner

Yes, I'll release the update on Cargo as soon as I have my hands on a Windows machine :)

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.

2 participants