Skip to content

Document the safety assumptions in use of Weak - #429

Closed
briansmith wants to merge 1 commit into
rust-random:masterfrom
briansmith:b/cast-transmute
Closed

briansmith wants to merge 1 commit into
rust-random:masterfrom
briansmith:b/cast-transmute

Conversation

@briansmith

@briansmith briansmith commented May 21, 2024 •

Copy link
Copy Markdown
Contributor

Make the conversion from NonNull<c_void> to a function pointer more explicit and document the safety assumptions.

@briansmith
briansmith force-pushed the b/cast-transmute branch 2 times, most recently from d98896b to 1d37e84 Compare May 21, 2024 03:37
Comment thread src/netbsd.rs Resolved
Comment thread src/netbsd.rs Outdated
//
// Cryptographic security: We assume any implementation of `getrandom`
// we find is libc's `getrandom` though this isn't guaranteed.
let func: &'static GetRandomFn = unsafe { func.as_ref() };

@newpavlov newpavlov May 21, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my understanding, this variant is also incorrect. You have transformed "function pointer" to "reference to function pointer".

@josephlr

Copy link
Copy Markdown
Member

I don't think it's possible to cast to a function pointer without transmute, here are the docs: https://doc.rust-lang.org/std/primitive.fn.html#casting-to-and-from-integers

@briansmith
briansmith force-pushed the b/cast-transmute branch 3 times, most recently from 13c6afb to 8f1115b Compare May 21, 2024 04:51
@briansmith briansmith changed the title Use fptr.cast<T>() and dereference instead of mem::transmute(fptr). Document the safety assumptions in use of Weak May 21, 2024
Make the conversion from `NonNull<c_void>` to a function pointer more
explicit and document the safety assumptions.
@briansmith

Copy link
Copy Markdown
Contributor Author

Just to reiterate: It is concerning that we only use Weak on a platform for which we don't run tests in CI.

@newpavlov

newpavlov commented May 21, 2024 •

Copy link
Copy Markdown
Member

Yes, right now we have built-only CI jobs for many targets. We probably will need to use VMs for targets like NetBSD (I don't think self-hosted runners will be a practical option for us). Looking into https://github.com/vmactions can be a good starting point. It's probably better to discuss it in a separate issue.

@newpavlov

Copy link
Copy Markdown
Member

@briansmith
Could you please rebase or open a new PR with this change?

@briansmith

Copy link
Copy Markdown
Contributor Author

Yes, I will revisit this when we have a testing solution for it.

@briansmith briansmith closed this May 22, 2024
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