windows: add various NT APIs

In anticipation of the next commit which adds win32 pipe APIs, add some
of the foundational NT APIs for that, which will be required for making
a robust Go pipe library. Also add a simple test case.

Change-Id: I898bd6c5265a8939a7f05a24c4d9b22941dc56b7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298171
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Jason A. Donenfeld
2021-03-04 20:34:36 +00:00
parent 444254391f
commit 1243437a8e
5 changed files with 429 additions and 3 deletions
+26
View File
@@ -536,3 +536,29 @@ func TestProcThreadAttributeListPointers(t *testing.T) {
t.Error("ProcThreadAttributeList was not garbage collected after a second")
}
}
func TestPEBFilePath(t *testing.T) {
peb := windows.RtlGetCurrentPeb()
if peb == nil || peb.Ldr == nil {
t.Error("unable to retrieve PEB with valid Ldr")
}
var entry *windows.LDR_DATA_TABLE_ENTRY
for cur := peb.Ldr.InMemoryOrderModuleList.Flink; cur != &peb.Ldr.InMemoryOrderModuleList; cur = cur.Flink {
e := (*windows.LDR_DATA_TABLE_ENTRY)(unsafe.Pointer(uintptr(unsafe.Pointer(cur)) - unsafe.Offsetof(windows.LDR_DATA_TABLE_ENTRY{}.InMemoryOrderLinks)))
if e.DllBase == peb.ImageBaseAddress {
entry = e
break
}
}
if entry == nil {
t.Error("unable to find Ldr entry for current process")
}
osPath, err := os.Executable()
if err != nil {
t.Errorf("unable to get path to current executable: %v", err)
}
pebPath := entry.FullDllName.String()
if osPath != pebPath {
t.Errorf("expected os.Executable() to return same value as peb.Ldr.{entry}.FullDllName - want %#q; got %#q", osPath, pebPath)
}
}