windows: do not query library for inline functions

The GetCurrent*Token variety of functions are actually implemented as
inline functions in the header files of the SDK. Attempting to call out
to these as library functions is an error. This commit also adds a test
to ensure that these work as expected.

Change-Id: I105f1ca1a8936114fe61bc22188200c31f240a23
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177840
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Jason A. Donenfeld
2019-05-22 04:47:17 +00:00
committed by Brad Fitzpatrick
parent 30999d67c8
commit 8097e1b27f
3 changed files with 89 additions and 17 deletions
-14
View File
@@ -259,9 +259,7 @@ var (
procEqualSid = modadvapi32.NewProc("EqualSid")
procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership")
procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
procGetCurrentThreadToken = modadvapi32.NewProc("GetCurrentThreadToken")
procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
procGetCurrentProcessToken = modadvapi32.NewProc("GetCurrentProcessToken")
procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
procSetThreadToken = modadvapi32.NewProc("SetThreadToken")
@@ -2824,12 +2822,6 @@ func OpenProcessToken(process Handle, access uint32, token *Token) (err error) {
return
}
func GetCurrentThreadToken() (token Token) {
r0, _, _ := syscall.Syscall(procGetCurrentThreadToken.Addr(), 0, 0, 0, 0)
token = Token(r0)
return
}
func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token) (err error) {
var _p0 uint32
if openAsSelf {
@@ -2848,12 +2840,6 @@ func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token
return
}
func GetCurrentProcessToken() (token Token) {
r0, _, _ := syscall.Syscall(procGetCurrentProcessToken.Addr(), 0, 0, 0, 0)
token = Token(r0)
return
}
func ImpersonateSelf(impersonationlevel uint32) (err error) {
r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
if r1 == 0 {