aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os1_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/os1_windows.go')
-rw-r--r--src/runtime/os1_windows.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/runtime/os1_windows.go b/src/runtime/os1_windows.go
index d0120347db..ab378b0730 100644
--- a/src/runtime/os1_windows.go
+++ b/src/runtime/os1_windows.go
@@ -88,8 +88,11 @@ var (
// Following syscalls are only available on some Windows PCs.
// We will load syscalls, if available, before using them.
+ _AddDllDirectory,
_AddVectoredContinueHandler,
- _GetQueuedCompletionStatusEx stdFunction
+ _GetQueuedCompletionStatusEx,
+ _LoadLibraryExW,
+ _ stdFunction
)
// Call a Windows function with stdcall conventions,
@@ -110,8 +113,10 @@ func loadOptionalSyscalls() {
return stdFunction(unsafe.Pointer(f))
}
if l != 0 {
+ _AddDllDirectory = findfunc("AddDllDirectory")
_AddVectoredContinueHandler = findfunc("AddVectoredContinueHandler")
_GetQueuedCompletionStatusEx = findfunc("GetQueuedCompletionStatusEx")
+ _LoadLibraryExW = findfunc("LoadLibraryExW")
}
}
@@ -121,6 +126,11 @@ func getLoadLibrary() uintptr {
}
//go:nosplit
+func getLoadLibraryEx() uintptr {
+ return uintptr(unsafe.Pointer(_LoadLibraryExW))
+}
+
+//go:nosplit
func getGetProcAddress() uintptr {
return uintptr(unsafe.Pointer(_GetProcAddress))
}
@@ -139,6 +149,22 @@ const (
// in sys_windows_386.s and sys_windows_amd64.s
func externalthreadhandler()
+// When loading DLLs, we prefer to use LoadLibraryEx with
+// LOAD_LIBRARY_SEARCH_* flags, if available. LoadLibraryEx is not
+// available on old Windows, though, and the LOAD_LIBRARY_SEARCH_*
+// flags are not available on some versions of Windows without a
+// security patch.
+//
+// https://msdn.microsoft.com/en-us/library/ms684179(v=vs.85).aspx says:
+// "Windows 7, Windows Server 2008 R2, Windows Vista, and Windows
+// Server 2008: The LOAD_LIBRARY_SEARCH_* flags are available on
+// systems that have KB2533623 installed. To determine whether the
+// flags are available, use GetProcAddress to get the address of the
+// AddDllDirectory, RemoveDllDirectory, or SetDefaultDllDirectories
+// function. If GetProcAddress succeeds, the LOAD_LIBRARY_SEARCH_*
+// flags can be used with LoadLibraryEx."
+var useLoadLibraryEx bool
+
func osinit() {
asmstdcallAddr = unsafe.Pointer(funcPC(asmstdcall))
@@ -146,6 +172,8 @@ func osinit() {
loadOptionalSyscalls()
+ useLoadLibraryEx = (_LoadLibraryExW != nil && _AddDllDirectory != nil)
+
disableWER()
externalthreadhandlerp = funcPC(externalthreadhandler)