From 854af27f14a7156d646cb0812811bbc293b2d6a7 Mon Sep 17 00:00:00 2001 From: Takuto Ikuta Date: Tue, 28 May 2019 17:17:54 +0900 Subject: [PATCH] windows: add functions for priority class took const value from https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setpriorityclass https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getpriorityclass Change-Id: I376bb8e1f5de8968177512857d60169cb7b7c776 Reviewed-on: https://go-review.googlesource.com/c/sys/+/179038 Reviewed-by: Alex Brainman Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- windows/syscall_windows.go | 2 ++ windows/types_windows.go | 12 ++++++++++++ windows/zsyscall_windows.go | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index eace6093..14dafa9f 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -258,6 +258,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys TerminateJobObject(job Handle, exitCode uint32) (err error) = kernel32.TerminateJobObject //sys SetErrorMode(mode uint32) (ret uint32) = kernel32.SetErrorMode //sys ResumeThread(thread Handle) (ret uint32, err error) [failretval==0xffffffff] = kernel32.ResumeThread +//sys SetPriorityClass(process Handle, priorityClass uint32) (err error) = kernel32.SetPriorityClass +//sys GetPriorityClass(process Handle) (ret uint32, err error) = kernel32.GetPriorityClass // Volume Management Functions //sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW diff --git a/windows/types_windows.go b/windows/types_windows.go index 0661a493..611b035f 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -408,6 +408,18 @@ const ( SEM_NOOPENFILEERRORBOX = 0x8000 ) +const ( + // Priority class. + ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000 + BELOW_NORMAL_PRIORITY_CLASS = 0x00004000 + HIGH_PRIORITY_CLASS = 0x00000080 + IDLE_PRIORITY_CLASS = 0x00000040 + NORMAL_PRIORITY_CLASS = 0x00000020 + PROCESS_MODE_BACKGROUND_BEGIN = 0x00100000 + PROCESS_MODE_BACKGROUND_END = 0x00200000 + REALTIME_PRIORITY_CLASS = 0x00000100 +) + var ( OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00") OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00") diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 9d5a3bc5..b9758895 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -196,6 +196,8 @@ var ( procTerminateJobObject = modkernel32.NewProc("TerminateJobObject") procSetErrorMode = modkernel32.NewProc("SetErrorMode") procResumeThread = modkernel32.NewProc("ResumeThread") + procSetPriorityClass = modkernel32.NewProc("SetPriorityClass") + procGetPriorityClass = modkernel32.NewProc("GetPriorityClass") procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW") procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW") procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW") @@ -2105,6 +2107,31 @@ func ResumeThread(thread Handle) (ret uint32, err error) { return } +func SetPriorityClass(process Handle, priorityClass uint32) (err error) { + r1, _, e1 := syscall.Syscall(procSetPriorityClass.Addr(), 2, uintptr(process), uintptr(priorityClass), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetPriorityClass(process Handle) (ret uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetPriorityClass.Addr(), 1, uintptr(process), 0, 0) + ret = uint32(r0) + if ret == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) { r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath))) if r1 == 0 {