aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-01-15 16:29:00 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-15 23:38:58 +0000
commit682a1d2176b02337460aeede0ff9e49429525195 (patch)
tree519995d9fde76d38f34ce9c9cfdf756ff2e1e958 /src/runtime
parent9f83418b83a43029ce8801ef10162dd94fdba81d (diff)
downloadgo-682a1d2176b02337460aeede0ff9e49429525195.tar.gz
go-682a1d2176b02337460aeede0ff9e49429525195.zip
runtime: detect errors in DuplicateHandle
These functions rely on DuplicateHandle succeeding, but they don't check the return value, which might be masking subtle bugs that cause other problems down the line. Updates #43720. Change-Id: I77f0e6645affa534777ffc173144a52e4afa5f81 Reviewed-on: https://go-review.googlesource.com/c/go/+/284135 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Austin Clements <austin@google.com> Trust: Alex Brainman <alex.brainman@gmail.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/os_windows.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
index d389d38ab9..16ff285e88 100644
--- a/src/runtime/os_windows.go
+++ b/src/runtime/os_windows.go
@@ -893,7 +893,10 @@ func sigblock(exiting bool) {
// Called on the new thread, cannot allocate memory.
func minit() {
var thandle uintptr
- stdcall7(_DuplicateHandle, currentProcess, currentThread, currentProcess, uintptr(unsafe.Pointer(&thandle)), 0, 0, _DUPLICATE_SAME_ACCESS)
+ if stdcall7(_DuplicateHandle, currentProcess, currentThread, currentProcess, uintptr(unsafe.Pointer(&thandle)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 {
+ print("runtime.minit: duplicatehandle failed; errno=", getlasterror(), "\n")
+ throw("runtime.minit: duplicatehandle failed")
+ }
// Configure usleep timer, if possible.
var timer uintptr
@@ -1134,8 +1137,12 @@ func profileloop1(param uintptr) uint32 {
}
// Acquire our own handle to the thread.
var thread uintptr
- stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS)
+ if stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 {
+ print("runtime.profileloop1: duplicatehandle failed; errno=", getlasterror(), "\n")
+ throw("runtime.profileloop1: duplicatehandle failed")
+ }
unlock(&mp.threadLock)
+
// mp may exit between the DuplicateHandle
// above and the SuspendThread. The handle
// will remain valid, but SuspendThread may
@@ -1214,7 +1221,10 @@ func preemptM(mp *m) {
return
}
var thread uintptr
- stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS)
+ if stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 {
+ print("runtime.preemptM: duplicatehandle failed; errno=", getlasterror(), "\n")
+ throw("runtime.preemptM: duplicatehandle failed")
+ }
unlock(&mp.threadLock)
// Prepare thread context buffer. This must be aligned to 16 bytes.