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

Open a BCrypt algorithm handle #101476

Merged
merged 2 commits into from
Sep 7, 2022
Merged

Conversation

ChrisDenton
Copy link
Member

Fixes #101474, supplants #101456.

Replaces use of a pseduo handle with manually opening a algorithm handle.

Most interesting thing here is the atomics.

r? @thomcc

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 6, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 6, 2022
library/std/src/sys/windows/rand.rs Outdated Show resolved Hide resolved
library/std/src/sys/windows/rand.rs Show resolved Hide resolved
@thomcc
Copy link
Member

thomcc commented Sep 7, 2022

Thanks, looks great!

@bors r+

@bors
Copy link
Contributor

bors commented Sep 7, 2022

📌 Commit b2e4f9d has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 7, 2022
@ChrisDenton
Copy link
Member Author

@bors p=1 so the fix is sure to be in the next nightly

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 7, 2022
…omcc

Open a BCrypt algorithm handle

Fixes rust-lang#101474, supplants rust-lang#101456.

Replaces use of a pseduo handle with manually opening a algorithm handle.

Most interesting thing here is the atomics.

r? `@thomcc`
@RalfJung RalfJung mentioned this pull request Sep 7, 2022
@ChrisDenton
Copy link
Member Author

@bors r-
@bors r=thomcc

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 7, 2022
@bors
Copy link
Contributor

bors commented Sep 7, 2022

📌 Commit a68ba39e7733dbb427708ef164164c2c55705a3c has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 7, 2022
@ChrisDenton
Copy link
Member Author

@thomcc I pushed small commit so that miri won't be broken by this. The weirdness is a little hack to avoid having to use a bunch of #[cfg(not(miri))]. Feel free r- if this is not ok. Should have a few hours before it's next in the queue.

@bors
Copy link
Contributor

bors commented Sep 7, 2022

⌛ Testing commit a68ba39e7733dbb427708ef164164c2c55705a3c with merge d27cb8dad98c06b510106bd299076341741ca0e1...

@bors
Copy link
Contributor

bors commented Sep 7, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 7, 2022
@ChrisDenton
Copy link
Member Author

fixed formatting

@bors r=thomcc

@bors
Copy link
Contributor

bors commented Sep 7, 2022

📌 Commit 832c7af has been approved by thomcc

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 7, 2022

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 7, 2022
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Sep 7, 2022

⌛ Testing commit 832c7af with merge 9682b5d...

@bors
Copy link
Contributor

bors commented Sep 7, 2022

☀️ Test successful - checks-actions
Approved by: thomcc
Pushing 9682b5d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 7, 2022
@bors bors merged commit 9682b5d into rust-lang:master Sep 7, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 7, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9682b5d): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
2.5% [2.5%, 2.5%] 1
Regressions ❌
(secondary)
0.4% [0.4%, 0.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.5% [2.5%, 2.5%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.6% [-3.0%, -2.2%] 2
Improvements ✅
(secondary)
-4.3% [-5.2%, -3.5%] 2
All ❌✅ (primary) -2.6% [-3.0%, -2.2%] 2

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

Comment on lines +41 to +51
#[cfg(miri)]
fn open() -> Result<Self, c::NTSTATUS> {
const BCRYPT_RNG_ALG_HANDLE: c::BCRYPT_ALG_HANDLE = ptr::invalid_mut(0x81);
let _ = (
c::BCryptOpenAlgorithmProvider,
c::BCryptCloseAlgorithmProvider,
c::BCRYPT_RNG_ALGORITHM,
c::STATUS_NOT_SUPPORTED,
);
Ok(Self(BCRYPT_RNG_ALG_HANDLE))
}
Copy link
Member

@RalfJung RalfJung Sep 8, 2022

Choose a reason for hiding this comment

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

I am surprised to see a Miri special path here; usually we try to execute the real thing where feasible (and BCryptOpenAlgorithmProvider looks easy enough to fake). Also please Cc @rust-lang/miri when adding such a codepath, and always add a comment explaining why Miri uses a different codepath.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, for this I'd say it's better to just add the shims to miri.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry! My intent was for this to be temporary until I was confident that the crash issue was addressed. Then we can go back to using BCRYPT_USE_SYSTEM_PREFERRED_RNG as the default and BCryptOpenAlgorithmProvider would be the fallback. I can submit a PR to undo tho.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, if this is just temporary then implementing the shims in Miri would indeed not be worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hashbrown tests crash on wine
9 participants