Skip to content

Commit ba9168b

Browse files
committed
syscall: add support for proc thread attribute lists
This will allow us to pass additional attributes when starting processes. Updates #44011. Change-Id: I4af365c5544a6d421830f247593ec970200e5e03 Reviewed-on: https://go-review.googlesource.com/c/go/+/288296 Trust: Jason A. Donenfeld <[email protected]> Trust: Alex Brainman <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent f414601 commit ba9168b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/syscall/syscall_windows.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ func NewCallbackCDecl(fn interface{}) uintptr {
284284
// This function returns 1 byte BOOLEAN rather than the 4 byte BOOL.
285285
//sys CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) [failretval&0xff==0] = CreateSymbolicLinkW
286286
//sys CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) [failretval&0xff==0] = CreateHardLinkW
287+
//sys initializeProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, attrcount uint32, flags uint32, size *uintptr) (err error) = InitializeProcThreadAttributeList
288+
//sys deleteProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST) = DeleteProcThreadAttributeList
289+
//sys updateProcThreadAttribute(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, flags uint32, attr uintptr, value uintptr, size uintptr, prevvalue uintptr, returnedsize *uintptr) (err error) = UpdateProcThreadAttribute
287290

288291
// syscall interface implementation for other packages
289292

@@ -1240,3 +1243,23 @@ func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overla
12401243
func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) error {
12411244
return postQueuedCompletionStatus(cphandle, qty, uintptr(key), overlapped)
12421245
}
1246+
1247+
// newProcThreadAttributeList allocates new PROC_THREAD_ATTRIBUTE_LIST, with
1248+
// the requested maximum number of attributes, which must be cleaned up by
1249+
// deleteProcThreadAttributeList.
1250+
func newProcThreadAttributeList(maxAttrCount uint32) (*_PROC_THREAD_ATTRIBUTE_LIST, error) {
1251+
var size uintptr
1252+
err := initializeProcThreadAttributeList(nil, maxAttrCount, 0, &size)
1253+
if err != ERROR_INSUFFICIENT_BUFFER {
1254+
if err == nil {
1255+
return nil, errorspkg.New("unable to query buffer size from InitializeProcThreadAttributeList")
1256+
}
1257+
return nil, err
1258+
}
1259+
al := (*_PROC_THREAD_ATTRIBUTE_LIST)(unsafe.Pointer(&make([]byte, size)[0]))
1260+
err = initializeProcThreadAttributeList(al, maxAttrCount, 0, &size)
1261+
if err != nil {
1262+
return nil, err
1263+
}
1264+
return al, nil
1265+
}

src/syscall/types_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,22 @@ type StartupInfo struct {
490490
StdErr Handle
491491
}
492492

493+
type _PROC_THREAD_ATTRIBUTE_LIST struct {
494+
_ [1]byte
495+
}
496+
497+
const (
498+
_PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000
499+
_PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 0x00020002
500+
)
501+
502+
type _STARTUPINFOEXW struct {
503+
StartupInfo
504+
ProcThreadAttributeList *_PROC_THREAD_ATTRIBUTE_LIST
505+
}
506+
507+
const _EXTENDED_STARTUPINFO_PRESENT = 0x00080000
508+
493509
type ProcessInformation struct {
494510
Process Handle
495511
Thread Handle

src/syscall/zsyscall_windows.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)