Skip to content

Use a hardcoded constant instead of calling OpenProcessToken. - #119032

Merged
bors merged 2 commits into
rust-lang:masterfrom
smmalis37:patch-1
Feb 17, 2024
Merged

Use a hardcoded constant instead of calling OpenProcessToken.#119032
bors merged 2 commits into
rust-lang:masterfrom
smmalis37:patch-1

Conversation

@smmalis37

Copy link
Copy Markdown
Contributor

Now that Win 7 support is dropped, we can resurrect #90144.

GetCurrentProcessToken is defined in processthreadsapi.h as:

FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
}

Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbotrustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 17, 2023
@rust-log-analyzer

This comment has been minimized.

Comment threadlibrary/std/src/sys/windows/os.rs Outdated
@deltragon

Copy link
Copy Markdown
Contributor

Additionally, windows 7 was re-added as a tier 3 target in #118150, so it might be good to test with that/keep the old code under a cfg for that target.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@smmalis37

Copy link
Copy Markdown
ContributorAuthor

Hmm, doesn't seem to like my cfg for win7 support. What should it be?

@ChrisDenton

Copy link
Copy Markdown
Member

The target is probably too new to be in the bootstrap compiler (which is currently beta 2013-11-13). The bootstrap compiler will next be updated in a week or two. In the meantime, you can put something like this at the top of the file:

#![cfg_attr(bootstrap, allow(unexpected_cfgs))]

This will tell the bootstrap (stage0) compiler to ignore the error while not affecting the newly built (stage1+) compiler.

Comment threadlibrary/std/src/sys/windows/os.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@ChrisDenton

Copy link
Copy Markdown
Member

Ok, this looks good. Could you squish your commits in to one?

@Urgau

Urgau commented Jan 3, 2024

Copy link
Copy Markdown
Member

The target is probably too new to be in the bootstrap compiler (which is currently beta 2013-11-13). The bootstrap compiler will next be updated in a week or two. In the meantime, you can put something like this at the top of the file:

#![cfg_attr(bootstrap, allow(unexpected_cfgs))]

Note that the better and recommended way is to add the exception to the "extra check-cfg list" in bootstrap:

(Some(Mode::Std),"target_env",Some(&["libnx"])),
// (Some(Mode::Std), "target_os", Some(&[])),
(Some(Mode::Std),"target_arch",Some(&["spirv","nvptx","xtensa"])),

@bors

bors commented Jan 13, 2024

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #117285) made this pull request unmergeable. Please resolve the merge conflicts.

@ChrisDenton

Copy link
Copy Markdown
Member

Hi, very sorry for the delay here. This was right around when i was going on holiday and evidently I missed that I hadn't approved it.

Could you rebase on master? The file has moved to library/std/src/sys/pal/windows/os.rs. Also the cfg_attr(bootstrap... line is no longer needed.

@smmalis37

Copy link
Copy Markdown
ContributorAuthor

Yeah, I should be able to get back to this next weekend.

Now that Win 7 support is dropped, we can resurrect rust-lang#90144.
GetCurrentProcessToken is defined in processthreadsapi.h as:
FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
}
Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.
@smmalis37

Copy link
Copy Markdown
ContributorAuthor

Rebase came out clean, think this is ready.

@ChrisDenton

Copy link
Copy Markdown
Member

Thanks for sticking with this and sorry again for the delay.

@bors r+ rollup

@bors

bors commented Feb 17, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 3b63ede has been approved by ChrisDenton

It is now in the queue for this repository.

@borsbors 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 Feb 17, 2024
Nadrieril added a commit to Nadrieril/rust that referenced this pull request Feb 17, 2024
Use a hardcoded constant instead of calling OpenProcessToken.
Now that Win 7 support is dropped, we can resurrect rust-lang#90144.
GetCurrentProcessToken is defined in processthreadsapi.h as:
FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
}
Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.
This was referenced Feb 17, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2024
Rollup of 8 pull requests
Successful merges:
- rust-lang#119032 (Use a hardcoded constant instead of calling OpenProcessToken.)
- rust-lang#120932 (const_mut_refs: allow mutable pointers to statics)
- rust-lang#121059 (Add and use a simple extension trait derive macro in the compiler)
- rust-lang#121135 (coverage: Discard spans that fill the entire function body)
- rust-lang#121187 (Add examples to document the return type of quickselect functions)
- rust-lang#121191 (Add myself to review rotation (and a rustbot ping))
- rust-lang#121192 (Give some intrinsics fallback bodies)
- rust-lang#121197 (Ensure `./configure` works when `configure.py` path contains spaces)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 5f21609 into rust-lang:masterFeb 17, 2024
@rustbotrustbot added this to the 1.78.0 milestone Feb 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2024
Rollup merge of rust-lang#119032 - smmalis37:patch-1, r=ChrisDenton
Use a hardcoded constant instead of calling OpenProcessToken.
Now that Win 7 support is dropped, we can resurrect rust-lang#90144.
GetCurrentProcessToken is defined in processthreadsapi.h as:
FORCEINLINE
HANDLE
GetCurrentProcessToken (
VOID
)
{
return (HANDLE)(LONG_PTR) -4;
}
Since it's very unlikely that this constant will ever change, let's just use it instead of making calls to get the same information.
@smmalis37
smmalis37 deleted the patch-1 branch February 18, 2024 00:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windowsOperating system: WindowsS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant 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.

8 participants

@smmalis37@rustbot@rust-log-analyzer@deltragon@ChrisDenton@Urgau@bors@thomcc