mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 08:37:31 -04:00
windows: use pseudo handle constants to implement GetCurrentProcess
There's no point in adding a function call to retrieve a constant, or worse, a syscall to retrieve a constant. These are fixed and baked so deep into NT they'll never change. So let's benefit from the obvious optimization and make these constants. Go easily inlines the function calls as well. We also take the opportunity to sunset OpenCurrentProcessToken and restore its original behavior, since users should be invoking this deliberately with the correct access mask. Change-Id: I92f7de56c0fcf5b69b59f5a79d2828c7ddf3c8f6 Reviewed-on: https://go-review.googlesource.com/c/sys/+/196800 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
@@ -647,13 +647,16 @@ func (tml *Tokenmandatorylabel) Size() uint32 {
|
||||
// system-related operations on the local computer.
|
||||
type Token Handle
|
||||
|
||||
// OpenCurrentProcessToken opens the access token
|
||||
// associated with current process. It is a real
|
||||
// token that needs to be closed, unlike
|
||||
// GetCurrentProcessToken.
|
||||
func OpenCurrentProcessToken() (token Token, err error) {
|
||||
err = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_DUPLICATE, &token)
|
||||
return
|
||||
// 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(), ...)
|
||||
// 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)
|
||||
return token, err
|
||||
}
|
||||
|
||||
// GetCurrentProcessToken returns the access token associated with
|
||||
|
||||
Reference in New Issue
Block a user