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

Rollup of 7 pull requests #121222

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
81c068a
install tools documentations
onur-ozkan Feb 14, 2024
e4a15d4
don't use entire sysroot binary path for rustc tarballs
onur-ozkan Feb 14, 2024
75af3c5
coverage: Regression test for a span extraction inconsistency
Zalathar Feb 15, 2024
cd9021e
coverage: Discard spans that fill the entire function body
Zalathar Feb 15, 2024
9b3fcf9
Detect when method call on argument could be removed to fulfill faile…
estebank Feb 14, 2024
cd1f608
const_mut_refs: allow mutable refs to statics
RalfJung Feb 11, 2024
b49bd0b
Add examples to document the return type of `select_nth_unstable`, `s…
Takashiidobe Feb 16, 2024
3250e95
Add a simple extension trait derive
compiler-errors Feb 13, 2024
9c25823
Use extension trait derive
compiler-errors Feb 13, 2024
a9dbf63
Move trait into attr so it's greppable
compiler-errors Feb 14, 2024
f624d55
Nits
compiler-errors Feb 16, 2024
4071938
Use a hardcoded constant instead of calling OpenProcessToken.
smmalis37 Dec 17, 2023
3b63ede
Remove cfg_attr
smmalis37 Feb 16, 2024
53239d8
Rollup merge of #119032 - smmalis37:patch-1, r=ChrisDenton
Nadrieril Feb 17, 2024
c5ffa54
Rollup merge of #120932 - RalfJung:mut-ptr-to-static, r=oli-obk
Nadrieril Feb 17, 2024
9ccabc8
Rollup merge of #121059 - compiler-errors:extension, r=davidtwco,Nils…
Nadrieril Feb 17, 2024
c2b02e4
Rollup merge of #121079 - onur-ozkan:install-conflicts, r=albertlarsan68
Nadrieril Feb 17, 2024
7fedf99
Rollup merge of #121100 - estebank:issue-71252, r=compiler-errors
Nadrieril Feb 17, 2024
134d9d0
Rollup merge of #121135 - Zalathar:no-whole-body-span, r=wesleywiser
Nadrieril Feb 17, 2024
45bcbfb
Rollup merge of #121187 - Takashiidobe:takashi/examples-for-quicksele…
Nadrieril Feb 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a hardcoded constant instead of calling OpenProcessToken.
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.
  • Loading branch information
smmalis37 committed Feb 16, 2024
commit 40719384e1da64776d0ee67a84ffdfacc67816b0
31 changes: 26 additions & 5 deletions library/std/src/sys/pal/windows/os.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Implementation of `std::os` functionality for Windows.

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

#[cfg(test)]
@@ -318,13 +319,33 @@ pub fn temp_dir() -> PathBuf {
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
}

#[cfg(not(target_vendor = "uwp"))]
#[cfg(all(not(target_vendor = "uwp"), not(target_vendor = "win7")))]
fn home_dir_crt() -> Option<PathBuf> {
unsafe {
// Defined in processthreadsapi.h.
const CURRENT_PROCESS_TOKEN: usize = -4_isize as usize;

super::fill_utf16_buf(
|buf, mut sz| {
match c::GetUserProfileDirectoryW(
ptr::invalid_mut(CURRENT_PROCESS_TOKEN),
buf,
&mut sz,
) {
0 if api::get_last_error().code != c::ERROR_INSUFFICIENT_BUFFER => 0,
0 => sz,
_ => sz - 1, // sz includes the null terminator
}
},
super::os2path,
)
.ok()
}
}

#[cfg(target_vendor = "win7")]
fn home_dir_crt() -> Option<PathBuf> {
unsafe {
// The magic constant -4 can be used as the token passed to GetUserProfileDirectoryW below
// instead of us having to go through these multiple steps to get a token. However this is
// not implemented on Windows 7, only Windows 8 and up. When we drop support for Windows 7
// we can simplify this code. See #90144 for details.
use crate::sys::handle::Handle;

let me = c::GetCurrentProcess();