From 64d51c261f69e8e3d2cd354c211f734bfde9c115 Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Thu, 21 Oct 2021 16:38:08 -0400 Subject: [PATCH] Use a hardcoded constant instead of calling OpenProcessToken. --- library/std/src/sys/windows/c.rs | 13 ++----------- library/std/src/sys/windows/os.rs | 10 +--------- src/bootstrap/dist.rs | 1 - src/test/run-make-fulldeps/tools.mk | 2 +- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index e5c550802a7ab..45790378aee5b 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -676,17 +676,8 @@ if #[cfg(not(target_vendor = "uwp"))] { pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; - pub const TOKEN_READ: DWORD = 0x20008; - - #[link(name = "advapi32")] - extern "system" { - // Allowed but unused by UWP - pub fn OpenProcessToken( - ProcessHandle: HANDLE, - DesiredAccess: DWORD, - TokenHandle: *mut HANDLE, - ) -> BOOL; - } + // This value is hardcoded in processthreadsapi.h GetCurrentProcessToken() + pub const CURRENT_PROCESS_TOKEN: HANDLE = (-4isize) as HANDLE; #[link(name = "userenv")] extern "system" { diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs index 883690c483167..936c63f97f4f3 100644 --- a/library/std/src/sys/windows/os.rs +++ b/library/std/src/sys/windows/os.rs @@ -281,17 +281,9 @@ pub fn temp_dir() -> PathBuf { #[cfg(not(target_vendor = "uwp"))] fn home_dir_crt() -> Option { unsafe { - use crate::sys::handle::Handle; - - let me = c::GetCurrentProcess(); - let mut token = ptr::null_mut(); - if c::OpenProcessToken(me, c::TOKEN_READ, &mut token) == 0 { - return None; - } - let _handle = Handle::from_raw_handle(token); super::fill_utf16_buf( |buf, mut sz| { - match c::GetUserProfileDirectoryW(token, buf, &mut sz) { + match c::GetUserProfileDirectoryW(c::CURRENT_PROCESS_TOKEN, buf, &mut sz) { 0 if c::GetLastError() != c::ERROR_INSUFFICIENT_BUFFER => 0, 0 => sz, _ => sz - 1, // sz includes the null terminator diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index d4875cfe1b066..aad753d8b4b35 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -189,7 +189,6 @@ fn make_win_dist( "libmoldname.a", "libpthread.a", //Windows import libs - "libadvapi32.a", "libbcrypt.a", "libcomctl32.a", "libcomdlg32.a", diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk index 3934c4725f413..7bd3c59e534ae 100644 --- a/src/test/run-make-fulldeps/tools.mk +++ b/src/test/run-make-fulldeps/tools.mk @@ -101,7 +101,7 @@ endif # Extra flags needed to compile a working executable with the standard library ifdef IS_WINDOWS ifdef IS_MSVC - EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib + EXTRACFLAGS := ws2_32.lib userenv.lib bcrypt.lib else EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt EXTRACXXFLAGS := -lstdc++