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

safety(neon): Improve safety of JsBox on Node-API >= 8 #907

Merged
merged 1 commit into from
Aug 25, 2022
Merged

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Jun 10, 2022

Generate a unique type id for the crate and tag externals. This is done at runtime instead of compile time to help with reproducible builds.

This requires that the module be built for Node-API 8+. In the future, we may want to do optional symbol loading for internal code that makes runtime decisions. That way we could provide this additional safety guarantee on newer versions of Node even if it was compiled for an older version.

crates/neon/src/lib.rs Outdated Show resolved Hide resolved
crates/neon/build.rs Outdated Show resolved Hide resolved
crates/neon/src/lib.rs Outdated Show resolved Hide resolved
@kjvalencik kjvalencik force-pushed the kv/type-tag branch 4 times, most recently from 74b9f3e to 5bab5e5 Compare July 11, 2022 20:04
Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and I agree with the design decision you made.

It would be great to capture the rationale you explained to me somewhere (a short RFC?). And we should add to the JsBox docs information about (lack of) interoperability between module instances. But that could be done as followup.


#[cfg(feature = "napi-8")]
static MODULE_TAG: once_cell::sync::Lazy<crate::sys::TypeTag> = once_cell::sync::Lazy::new(|| {
let mut lower = [0; std::mem::size_of::<u64>()];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to say we aren't using this 64 bits so for now it's just reserved for future use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this. FYI, we're using 64-bits and not the full 128-bits.

Generate a unique type id for the crate and tag externals
@kjvalencik kjvalencik merged commit e7ac0a4 into main Aug 25, 2022
@kjvalencik kjvalencik deleted the kv/type-tag branch August 25, 2022 15:42
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.

3 participants