From 855e68c8590b0d6a9d08863d2982eb8aeddd98d3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 26 Sep 2019 17:53:21 +0000 Subject: [PATCH] windows: revert breaking API changes from CL 196798, add new accessor funcs CL 196798 changed API and broke a number of projects. Revert the signature changes but add new convenience functions instead. Change-Id: I49e389204f4756ec054ba8fd7555e235ef6370e8 Reviewed-on: https://go-review.googlesource.com/c/sys/+/197597 Run-TryBot: Brad Fitzpatrick Reviewed-by: Bryan C. Mills --- windows/security_windows.go | 4 ++-- windows/syscall_windows.go | 24 ++++++++++++++++++++---- windows/syscall_windows_test.go | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/windows/security_windows.go b/windows/security_windows.go index f5e725a1..c605ee6a 100644 --- a/windows/security_windows.go +++ b/windows/security_windows.go @@ -650,12 +650,12 @@ type Token Handle // OpenCurrentProcessToken opens an access token associated with current // process with TOKEN_QUERY access. It is a real token that needs to be closed. // -// Deprecated: Explicitly call OpenProcessToken(GetCurrentProcess(), ...) +// Deprecated: Explicitly call OpenProcessToken(CurrentProcess(), ...) // with the desired access instead, or use GetCurrentProcessToken for a // TOKEN_QUERY token. func OpenCurrentProcessToken() (Token, error) { var token Token - err := OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) + err := OpenProcessToken(CurrentProcess(), TOKEN_QUERY, &token) return token, err } diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 5734645b..4ce8eaf1 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -309,16 +309,32 @@ func NewCallbackCDecl(fn interface{}) uintptr { // GetCurrentProcess returns the handle for the current process. // It is a pseudo handle that does not need to be closed. -func GetCurrentProcess() Handle { - return Handle(^uintptr(1 - 1)) +// The returned error is always nil. +// +// Deprecated: use CurrentProcess for the same Handle without the nil +// error. +func GetCurrentProcess() (Handle, error) { + return CurrentProcess(), nil } +// CurrentProcess returns the handle for the current process. +// It is a pseudo handle that does not need to be closed. +func CurrentProcess() Handle { return Handle(^uintptr(1 - 1)) } + // GetCurrentThread returns the handle for the current thread. // It is a pseudo handle that does not need to be closed. -func GetCurrentThread() Handle { - return Handle(^uintptr(2 - 1)) +// The returned error is always nil. +// +// Deprecated: use CurrentThread for the same Handle without the nil +// error. +func GetCurrentThread() (Handle, error) { + return CurrentThread(), nil } +// CurrentThread returns the handle for the current thread. +// It is a pseudo handle that does not need to be closed. +func CurrentThread() Handle { return Handle(^uintptr(2 - 1)) } + // GetProcAddressByOrdinal retrieves the address of the exported // function from module by ordinal. func GetProcAddressByOrdinal(module Handle, ordinal uintptr) (proc uintptr, err error) { diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 6130cf2a..a63df60b 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -246,7 +246,7 @@ func TestGetNamedSecurityInfo(t *testing.T) { } func TestGetSecurityInfo(t *testing.T) { - sd, err := windows.GetSecurityInfo(windows.GetCurrentProcess(), windows.SE_KERNEL_OBJECT, windows.DACL_SECURITY_INFORMATION) + sd, err := windows.GetSecurityInfo(windows.CurrentProcess(), windows.SE_KERNEL_OBJECT, windows.DACL_SECURITY_INFORMATION) if err != nil { t.Fatal(err) }