From 05636b97d032b034a86e73b4eb3d8cef1a660177 Mon Sep 17 00:00:00 2001 From: Maksim An Date: Tue, 2 Apr 2024 10:38:35 -0700 Subject: [PATCH] Update `JOB_OBJECT_ALL_ACCESS` and `OpenJobObject` (#2095) Update `JOB_OBJECT_ALL_ACCESS` value to the most recent one. Update `winapi.OpenJobObject` to accept `inheritHandle` as `bool`. The underlying syscall stays the same, but this allows cleaner calls from go's perspective as it avoids `bool` to `uint32` casting. Signed-off-by: Maksim An (cherry picked from commit 42671b424b99461eb3dde4ed44f6f123092f656d) Signed-off-by: Kirtana Ashok --- internal/jobobject/jobobject.go | 2 +- internal/winapi/jobobject.go | 4 ++-- internal/winapi/zsyscall_windows.go | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/jobobject/jobobject.go b/internal/jobobject/jobobject.go index 3abd96742d..b505731c36 100644 --- a/internal/jobobject/jobobject.go +++ b/internal/jobobject/jobobject.go @@ -188,7 +188,7 @@ func Open(ctx context.Context, options *Options) (_ *JobObject, err error) { return nil, winapi.RtlNtStatusToDosError(status) } } else { - jobHandle, err = winapi.OpenJobObject(winapi.JOB_OBJECT_ALL_ACCESS, 0, unicodeJobName.Buffer) + jobHandle, err = winapi.OpenJobObject(winapi.JOB_OBJECT_ALL_ACCESS, false, unicodeJobName.Buffer) if err != nil { return nil, err } diff --git a/internal/winapi/jobobject.go b/internal/winapi/jobobject.go index 1b8f68a678..4c04dd3f83 100644 --- a/internal/winapi/jobobject.go +++ b/internal/winapi/jobobject.go @@ -28,7 +28,7 @@ const ( // https://docs.microsoft.com/en-us/windows/win32/procthread/job-object-security-and-access-rights const ( JOB_OBJECT_QUERY = 0x0004 - JOB_OBJECT_ALL_ACCESS = 0x1F001F + JOB_OBJECT_ALL_ACCESS = 0x1F003F ) // IO limit flags @@ -199,7 +199,7 @@ type SILOOBJECT_BASIC_INFORMATION struct { // LPCWSTR lpName // ); // -//sys OpenJobObject(desiredAccess uint32, inheritHandle int32, lpName *uint16) (handle windows.Handle, err error) = kernel32.OpenJobObjectW +//sys OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error) = kernel32.OpenJobObjectW // DWORD SetIoRateControlInformationJobObject( // HANDLE hJob, diff --git a/internal/winapi/zsyscall_windows.go b/internal/winapi/zsyscall_windows.go index 33720fe8b5..4d75bd0d27 100644 --- a/internal/winapi/zsyscall_windows.go +++ b/internal/winapi/zsyscall_windows.go @@ -470,8 +470,12 @@ func LocalFree(ptr uintptr) { return } -func OpenJobObject(desiredAccess uint32, inheritHandle int32, lpName *uint16) (handle windows.Handle, err error) { - r0, _, e1 := syscall.SyscallN(procOpenJobObjectW.Addr(), uintptr(desiredAccess), uintptr(inheritHandle), uintptr(unsafe.Pointer(lpName))) +func OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error) { + var _p0 uint32 + if inheritHandle { + _p0 = 1 + } + r0, _, e1 := syscall.Syscall(procOpenJobObjectW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(lpName))) handle = windows.Handle(r0) if handle == 0 { err = errnoErr(e1)