-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #874 from dcantah/expand-winapi
Add new winapi bindings for job containers
- Loading branch information
Showing
13 changed files
with
323 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package winapi | ||
|
||
import ( | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// Messages that can be received from an assigned io completion port. | ||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port | ||
const ( | ||
JOB_OBJECT_MSG_END_OF_JOB_TIME = 1 | ||
JOB_OBJECT_MSG_END_OF_PROCESS_TIME = 2 | ||
JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT = 3 | ||
JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO = 4 | ||
JOB_OBJECT_MSG_NEW_PROCESS = 6 | ||
JOB_OBJECT_MSG_EXIT_PROCESS = 7 | ||
JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS = 8 | ||
JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT = 9 | ||
JOB_OBJECT_MSG_JOB_MEMORY_LIMIT = 10 | ||
JOB_OBJECT_MSG_NOTIFICATION_LIMIT = 11 | ||
) | ||
|
||
// IO limit flags | ||
// | ||
// https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/ns-jobapi2-jobobject_io_rate_control_information | ||
const JOB_OBJECT_IO_RATE_CONTROL_ENABLE = 0x1 | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information | ||
const ( | ||
JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 1 << iota | ||
JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED | ||
JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP | ||
JOB_OBJECT_CPU_RATE_CONTROL_NOTIFY | ||
JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE | ||
) | ||
|
||
// JobObjectInformationClass values. Used for a call to QueryInformationJobObject | ||
// | ||
// https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-queryinformationjobobject | ||
const ( | ||
JobObjectBasicAccountingInformation uint32 = 1 | ||
JobObjectBasicProcessIdList uint32 = 3 | ||
JobObjectBasicAndIoAccountingInformation uint32 = 8 | ||
JobObjectLimitViolationInformation uint32 = 13 | ||
JobObjectNotificationLimitInformation2 uint32 = 33 | ||
) | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information | ||
type JOBOBJECT_BASIC_LIMIT_INFORMATION struct { | ||
PerProcessUserTimeLimit int64 | ||
PerJobUserTimeLimit int64 | ||
LimitFlags uint32 | ||
MinimumWorkingSetSize uintptr | ||
MaximumWorkingSetSize uintptr | ||
ActiveProcessLimit uint32 | ||
Affinity uintptr | ||
PriorityClass uint32 | ||
SchedulingClass uint32 | ||
} | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information | ||
type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION struct { | ||
ControlFlags uint32 | ||
Rate uint32 | ||
} | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/ns-jobapi2-jobobject_io_rate_control_information | ||
type JOBOBJECT_IO_RATE_CONTROL_INFORMATION struct { | ||
MaxIops int64 | ||
MaxBandwidth int64 | ||
ReservationIops int64 | ||
BaseIOSize uint32 | ||
VolumeName string | ||
ControlFlags uint32 | ||
} | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_process_id_list | ||
type JOBOBJECT_BASIC_PROCESS_ID_LIST struct { | ||
NumberOfAssignedProcesses uint32 | ||
NumberOfProcessIdsInList uint32 | ||
ProcessIdList [1]uintptr | ||
} | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port | ||
type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct { | ||
CompletionKey uintptr | ||
CompletionPort windows.Handle | ||
} | ||
|
||
// BOOL IsProcessInJob( | ||
// HANDLE ProcessHandle, | ||
// HANDLE JobHandle, | ||
// PBOOL Result | ||
// ); | ||
// | ||
//sys IsProcessInJob(procHandle windows.Handle, jobHandle windows.Handle, result *bool) (err error) = kernel32.IsProcessInJob | ||
|
||
// BOOL QueryInformationJobObject( | ||
// HANDLE hJob, | ||
// JOBOBJECTINFOCLASS JobObjectInformationClass, | ||
// LPVOID lpJobObjectInformation, | ||
// DWORD cbJobObjectInformationLength, | ||
// LPDWORD lpReturnLength | ||
// ); | ||
// | ||
//sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject | ||
|
||
// HANDLE OpenJobObjectW( | ||
// DWORD dwDesiredAccess, | ||
// BOOL bInheritHandle, | ||
// LPCWSTR lpName | ||
// ); | ||
// | ||
//sys OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error) = kernel32.OpenJobObjectW | ||
|
||
// DWORD SetIoRateControlInformationJobObject( | ||
// HANDLE hJob, | ||
// JOBOBJECT_IO_RATE_CONTROL_INFORMATION *IoRateControlInfo | ||
// ); | ||
// | ||
//sys SetIoRateControlInformationJobObject(jobHandle windows.Handle, ioRateControlInfo *JOBOBJECT_IO_RATE_CONTROL_INFORMATION) (ret uint32, err error) = kernel32.SetIoRateControlInformationJobObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package winapi | ||
|
||
// BOOL LogonUserA( | ||
// LPCWSTR lpszUsername, | ||
// LPCWSTR lpszDomain, | ||
// LPCWSTR lpszPassword, | ||
// DWORD dwLogonType, | ||
// DWORD dwLogonProvider, | ||
// PHANDLE phToken | ||
// ); | ||
// | ||
//sys LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32, token *windows.Token) (err error) = advapi32.LogonUserW | ||
|
||
// Logon types | ||
const ( | ||
LOGON32_LOGON_INTERACTIVE uint32 = 2 | ||
LOGON32_LOGON_NETWORK uint32 = 3 | ||
LOGON32_LOGON_BATCH uint32 = 4 | ||
LOGON32_LOGON_SERVICE uint32 = 5 | ||
LOGON32_LOGON_UNLOCK uint32 = 7 | ||
LOGON32_LOGON_NETWORK_CLEARTEXT uint32 = 8 | ||
LOGON32_LOGON_NEW_CREDENTIALS uint32 = 9 | ||
) | ||
|
||
// Logon providers | ||
const ( | ||
LOGON32_PROVIDER_DEFAULT uint32 = 0 | ||
LOGON32_PROVIDER_WINNT40 uint32 = 2 | ||
LOGON32_PROVIDER_WINNT50 uint32 = 3 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package winapi | ||
|
||
// VOID RtlMoveMemory( | ||
// _Out_ VOID UNALIGNED *Destination, | ||
// _In_ const VOID UNALIGNED *Source, | ||
// _In_ SIZE_T Length | ||
// ); | ||
//sys RtlMoveMemory(destination *byte, source *byte, length uintptr) (err error) = kernel32.RtlMoveMemory | ||
|
||
//sys LocalAlloc(flags uint32, size int) (ptr uintptr) = kernel32.LocalAlloc | ||
//sys LocalFree(ptr uintptr) = kernel32.LocalFree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package winapi | ||
|
||
// DWORD SearchPathW( | ||
// LPCWSTR lpPath, | ||
// LPCWSTR lpFileName, | ||
// LPCWSTR lpExtension, | ||
// DWORD nBufferLength, | ||
// LPWSTR lpBuffer, | ||
// LPWSTR *lpFilePart | ||
// ); | ||
//sys SearchPath(lpPath *uint16, lpFileName *uint16, lpExtension *uint16, nBufferLength uint32, lpBuffer *uint16, lpFilePath **uint16) (size uint32, err error) = kernel32.SearchPathW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package winapi | ||
|
||
const PROCESS_ALL_ACCESS uint32 = 2097151 |
8 changes: 3 additions & 5 deletions
8
internal/processorinfo/syscall.go → internal/winapi/processor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package processorinfo | ||
|
||
//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go syscall.go | ||
|
||
//sys getActiveProcessorCount(groupNumber uint16) (amount uint32) = kernel32.GetActiveProcessorCount | ||
package winapi | ||
|
||
// Get count from all processor groups. | ||
// https://docs.microsoft.com/en-us/windows/win32/procthread/processor-groups | ||
const ALL_PROCESSOR_GROUPS = 0xFFFF | ||
|
||
//sys GetActiveProcessorCount(groupNumber uint16) (amount uint32) = kernel32.GetActiveProcessorCount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/*Package winapi contains various low-level bindings to Windows APIs. It can | ||
be thought of as an extension to golang.org/x/sys/windows. */ | ||
// Package winapi contains various low-level bindings to Windows APIs. It can | ||
// be thought of as an extension to golang.org/x/sys/windows. | ||
package winapi | ||
|
||
//go:generate go run ..\..\mksyscall_windows.go -output zsyscall_windows.go devices.go heapalloc.go ntfs.go errors.go | ||
//go:generate go run ..\..\mksyscall_windows.go -output zsyscall_windows.go jobobject.go path.go logon.go memory.go processor.go devices.go filesystem.go errors.go |
Oops, something went wrong.