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

Move __getrandom_custom definition into a const block #344

Merged
merged 2 commits into from Mar 10, 2023
Merged

Conversation

josephlr
Copy link
Member

@josephlr josephlr commented Mar 9, 2023

This supersedes #341 (and depends on #343)

  • All the code for implementing __getrandom_custom is now in an
    named const block (unnamed consts require Rust 1.37)
    • I found this approch here
    • Nothing inside the block can be referenced outside of it
  • __getrandom_custom is marked unsafe
    • It can't be accessed externally, but is "logically" unsafe as it
      dereferences raw pointers
  • The type of the function is moved to a typedef, so we can check that
    the defined type matches that of getrandom:getrandom.
  • Use ::core::result::Result instead of Result
    • Similar to use use of from_raw_parts_mut this prevents
      compilation errors if Result is redefined.

I checked that our custom test still worked, and that the __getrandom_custom function was no longer directly accessible from Rust code.

Signed-off-by: Joe Richey joerichey@google.com

The target triple name was changed in rust-lang/rust#106429

While `rustc` known the old spelling of the triple, `rustup` does not,
so the toolchain download was not working.

Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr josephlr requested a review from newpavlov March 9, 2023 23:09
@josephlr josephlr changed the title Move __getrandom_custom definition into an unnamed block Move __getrandom_custom definition into a const block Mar 9, 2023
This supersedes #341, and makes the following changes
  - All the code for implementing `__getrandom_custom` is now in an
    **named** `const` block (unnamed consts require Rust 1.37)
    - I found this approch [here](https://internals.rust-lang.org/t/anonymous-modules/15441)
    - Nothing inside the block can be referenced outside of it
  - `__getrandom_custom` is marked `unsafe`
    - It can't be accessed externally, but is "logically" unsafe as it
      dereferences raw pointers
  - The type of the function is moved to a typedef, so we can check that
    the defined type matches that of `getrandom:getrandom`.
  - Use `::core::result::Result` instead of `Result`
    - Similar to use use of `from_raw_parts_mut` this prevents
      compilation errors if `Result` is redefined.

Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr josephlr merged commit 2f9989f into master Mar 10, 2023
47 checks passed
@josephlr josephlr deleted the custom_unsafe branch March 10, 2023 04:36
@newpavlov newpavlov mentioned this pull request Apr 2, 2023
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.

None yet

2 participants