diff options
| author | qmuntal <quimmuntal@gmail.com> | 2023-01-30 14:42:17 +0100 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2023-01-31 22:06:41 +0000 |
| commit | a17d959debdb04cd550016a3501dd09d50cd62e7 (patch) | |
| tree | 3fd64a6cfada925520bf0a915f1389a47f1c5552 /src/syscall | |
| parent | 34d026862df50e36bdb74f010f746f91b7d6a052 (diff) | |
| download | go-a17d959debdb04cd550016a3501dd09d50cd62e7.tar.xz | |
runtime: always use LoadLibraryEx to load system libraries
This CL removes a fallback that used LoadLibraryA when the runtime
was loading system DLLs on Windows 7, Windows Server 2008 R2,
or earlier.
We can safely remove that fallback now, as go1.21 will require at least
Windows 8 or Server 2012.
This CL also saves some syscall initialization time and bytes:
new:
init syscall @2.3 ms, 0 ms clock, 1000 bytes, 18 allocs
old:
init syscall @3.6 ms, 0.52 ms clock, 1744 bytes, 24 allocs
Updates #57003
Change-Id: I7dcc1173537785b6b580e9f78632c0c74da658d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/463842
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/syscall')
| -rw-r--r-- | src/syscall/dll_windows.go | 28 | ||||
| -rw-r--r-- | src/syscall/security_windows.go | 1 | ||||
| -rw-r--r-- | src/syscall/zsyscall_windows.go | 9 |
3 files changed, 2 insertions, 36 deletions
diff --git a/src/syscall/dll_windows.go b/src/syscall/dll_windows.go index 34b481d6e6..78c8b0169a 100644 --- a/src/syscall/dll_windows.go +++ b/src/syscall/dll_windows.go @@ -44,7 +44,7 @@ func Syscall18(trap, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a func SyscallN(trap uintptr, args ...uintptr) (r1, r2 uintptr, err Errno) func loadlibrary(filename *uint16) (handle uintptr, err Errno) -func loadsystemlibrary(filename *uint16, absoluteFilepath *uint16) (handle uintptr, err Errno) +func loadsystemlibrary(filename *uint16) (handle uintptr, err Errno) func getprocaddress(handle uintptr, procname *uint8) (proc uintptr, err Errno) // A DLL implements access to a single DLL. @@ -53,26 +53,6 @@ type DLL struct { Handle Handle } -// We use this for computing the absolute path for system DLLs on systems -// where SEARCH_SYSTEM32 is not available. -var systemDirectoryPrefix string - -func init() { - n := uint32(MAX_PATH) - for { - b := make([]uint16, n) - l, e := getSystemDirectory(&b[0], n) - if e != nil { - panic("Unable to determine system directory: " + e.Error()) - } - if l <= n { - systemDirectoryPrefix = UTF16ToString(b[:l]) + "\\" - break - } - n = l - } -} - // LoadDLL loads the named DLL file into memory. // // If name is not an absolute path and is not a known system DLL used by @@ -89,11 +69,7 @@ func LoadDLL(name string) (*DLL, error) { var h uintptr var e Errno if sysdll.IsSystemDLL[name] { - absoluteFilepathp, err := UTF16PtrFromString(systemDirectoryPrefix + name) - if err != nil { - return nil, err - } - h, e = loadsystemlibrary(namep, absoluteFilepathp) + h, e = loadsystemlibrary(namep) } else { h, e = loadlibrary(namep) } diff --git a/src/syscall/security_windows.go b/src/syscall/security_windows.go index 67102b6929..00dc920974 100644 --- a/src/syscall/security_windows.go +++ b/src/syscall/security_windows.go @@ -290,7 +290,6 @@ type Tokenprimarygroup struct { //sys OpenProcessToken(h Handle, access uint32, token *Token) (err error) = advapi32.OpenProcessToken //sys GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) = advapi32.GetTokenInformation //sys GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) = userenv.GetUserProfileDirectoryW -//sys getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) = kernel32.GetSystemDirectoryW // An access token contains the security information for a logon session. // The system creates an access token when a user logs on, and every diff --git a/src/syscall/zsyscall_windows.go b/src/syscall/zsyscall_windows.go index 61d89f1460..9190ec8b20 100644 --- a/src/syscall/zsyscall_windows.go +++ b/src/syscall/zsyscall_windows.go @@ -866,15 +866,6 @@ func GetStdHandle(stdhandle int) (handle Handle, err error) { return } -func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { - r0, _, e1 := Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0) - len = uint32(r0) - if len == 0 { - err = errnoErr(e1) - } - return -} - func GetSystemTimeAsFileTime(time *Filetime) { Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0) return |
