Skip to content

Commit 51b60fd

Browse files
author
Bryan C. Mills
committed
windows/registry: lock OS thread while enumerating keys
CL 361154 updated the standard syscall package to document that successive calls to syscall.RegEnumKeyEx must occur on the same OS thread (after that requirement was empirically discovered in golang/go#49320). This use in x/sys needs to be updated to comply with the newly-discovered requirement. Fixes golang/go#49466. Change-Id: Idc45d91f175e1db25c215213fcaa45982c2f5e6e Reviewed-on: https://go-review.googlesource.com/c/sys/+/362576 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 02f5c03 commit 51b60fd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

windows/registry/key.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build windows
56
// +build windows
67

78
// Package registry provides access to the Windows registry.
@@ -24,6 +25,7 @@ package registry
2425

2526
import (
2627
"io"
28+
"runtime"
2729
"syscall"
2830
"time"
2931
)
@@ -113,6 +115,13 @@ func OpenRemoteKey(pcname string, k Key) (Key, error) {
113115
// The parameter n controls the number of returned names,
114116
// analogous to the way os.File.Readdirnames works.
115117
func (k Key) ReadSubKeyNames(n int) ([]string, error) {
118+
// RegEnumKeyEx must be called repeatedly and to completion.
119+
// During this time, this goroutine cannot migrate away from
120+
// its current thread. See https://golang.org/issue/49320 and
121+
// https://golang.org/issue/49466.
122+
runtime.LockOSThread()
123+
defer runtime.UnlockOSThread()
124+
116125
names := make([]string, 0)
117126
// Registry key size limit is 255 bytes and described there:
118127
// https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx

0 commit comments

Comments
 (0)