package winapi

import "github.com/Microsoft/hcsshim/internal/winapi"

Package winapi contains various low-level bindings to Windows APIs. It can be thought of as an extension to golang.org/x/sys/windows.

Index

Constants

const (
	STATUS_REPARSE_POINT_ENCOUNTERED               = 0xC000050B
	ERROR_NO_MORE_ITEMS                            = 0x103
	ERROR_MORE_DATA                  syscall.Errno = 234
)
const (
	FileLinkInformationClass          = 11
	FileDispositionInformationExClass = 64

	FILE_READ_ATTRIBUTES  = 0x0080
	FILE_WRITE_ATTRIBUTES = 0x0100
	DELETE                = 0x10000

	FILE_OPEN   = 1
	FILE_CREATE = 2

	FILE_LIST_DIRECTORY          = 0x00000001
	FILE_DIRECTORY_FILE          = 0x00000001
	FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020
	FILE_OPEN_FOR_BACKUP_INTENT  = 0x00004000
	FILE_OPEN_REPARSE_POINT      = 0x00200000

	FILE_DISPOSITION_DELETE = 0x00000001

	OBJ_DONT_REPARSE = 0x1000

	STATUS_MORE_ENTRIES    = 0x105
	STATUS_NO_MORE_ENTRIES = 0x8000001a
)
const (
	JOB_OBJECT_MSG_END_OF_JOB_TIME       uint32 = 1
	JOB_OBJECT_MSG_END_OF_PROCESS_TIME   uint32 = 2
	JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT  uint32 = 3
	JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO   uint32 = 4
	JOB_OBJECT_MSG_NEW_PROCESS           uint32 = 6
	JOB_OBJECT_MSG_EXIT_PROCESS          uint32 = 7
	JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS uint32 = 8
	JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT  uint32 = 9
	JOB_OBJECT_MSG_JOB_MEMORY_LIMIT      uint32 = 10
	JOB_OBJECT_MSG_NOTIFICATION_LIMIT    uint32 = 11
)

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_CPU_RATE_CONTROL_ENABLE uint32 = 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
)

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information

const (
	JobObjectBasicAccountingInformation      uint32 = 1
	JobObjectBasicProcessIdList              uint32 = 3
	JobObjectBasicAndIoAccountingInformation uint32 = 8
	JobObjectLimitViolationInformation       uint32 = 13
	JobObjectMemoryUsageInformation          uint32 = 28
	JobObjectNotificationLimitInformation2   uint32 = 33
	JobObjectIoAttribution                   uint32 = 42
)

JobObjectInformationClass values. Used for a call to QueryInformationJobObject

https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-queryinformationjobobject

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 types

const (
	LOGON32_PROVIDER_DEFAULT uint32 = 0
	LOGON32_PROVIDER_WINNT40 uint32 = 2
	LOGON32_PROVIDER_WINNT50 uint32 = 3
)

Logon providers

const ALL_PROCESSOR_GROUPS = 0xFFFF

Get count from all processor groups. https://docs.microsoft.com/en-us/windows/win32/procthread/processor-groups

const (
	FileIdInfo = 18
)

Select entries from FILE_INFO_BY_HANDLE_CLASS.

C declaration:

typedef enum _FILE_INFO_BY_HANDLE_CLASS {
    FileBasicInfo,
    FileStandardInfo,
    FileNameInfo,
    FileRenameInfo,
    FileDispositionInfo,
    FileAllocationInfo,
    FileEndOfFileInfo,
    FileStreamInfo,
    FileCompressionInfo,
    FileAttributeTagInfo,
    FileIdBothDirectoryInfo,
    FileIdBothDirectoryRestartInfo,
    FileIoPriorityHintInfo,
    FileRemoteProtocolInfo,
    FileFullDirectoryInfo,
    FileFullDirectoryRestartInfo,
    FileStorageInfo,
    FileAlignmentInfo,
    FileIdInfo,
    FileIdExtdDirectoryInfo,
    FileIdExtdDirectoryRestartInfo,
    FileDispositionInfoEx,
    FileRenameInfoEx,
    FileCaseSensitiveInfo,
    FileNormalizedNameInfo,
    MaximumFileInfoByHandleClass
} FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS;

Documentation: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ne-minwinbase-file_info_by_handle_class

const JOBOBJECT_IO_ATTRIBUTION_CONTROL_ENABLE uint32 = 0x1
const JOB_OBJECT_ALL_ACCESS = 0x1F001F

Access rights for creating or opening job objects.

https://docs.microsoft.com/en-us/windows/win32/procthread/job-object-security-and-access-rights

const JOB_OBJECT_IO_RATE_CONTROL_ENABLE = 0x1

IO limit flags

https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/ns-jobapi2-jobobject_io_rate_control_information

const PROCESS_ALL_ACCESS uint32 = 2097151
const STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
const SystemProcessInformation = 5

Functions

func CMGetDevNodeProperty

func CMGetDevNodeProperty(dnDevInst uint32, propertyKey *DevPropKey, propertyType *uint32, propertyBuffer *uint16, propertyBufferSize *uint32, uFlags uint32) (hr error)

func CMGetDeviceIDList

func CMGetDeviceIDList(pszFilter *byte, buffer *byte, bufferLen uint32, uFlags uint32) (hr error)

func CMGetDeviceIDListSize

func CMGetDeviceIDListSize(pulLen *uint32, pszFilter *byte, uFlags uint32) (hr error)

func CMLocateDevNode

func CMLocateDevNode(pdnDevInst *uint32, pDeviceID string, uFlags uint32) (hr error)

func ConvertStringSetToSlice

func ConvertStringSetToSlice(buf []byte) ([]string, error)

ConvertStringSetToSlice is a helper function used to convert the contents of `buf` into a string slice. `buf` contains a set of null terminated strings with an additional null at the end to indicate the end of the set.

func CreateRemoteThread

func CreateRemoteThread(process windows.Handle, sa *windows.SecurityAttributes, stackSize uint32, startAddr uintptr, parameter uintptr, creationFlags uint32, threadID *uint32) (handle windows.Handle, err error)

func GetActiveProcessorCount

func GetActiveProcessorCount(groupNumber uint16) (amount uint32)

func GetProcessImageFileName

func GetProcessImageFileName(hProcess windows.Handle, imageFileName *uint16, nSize uint32) (size uint32, err error)

func GetQueuedCompletionStatus

func GetQueuedCompletionStatus(cphandle windows.Handle, qty *uint32, key *uintptr, overlapped **windows.Overlapped, timeout uint32) (err error)

func IsProcessInJob

func IsProcessInJob(procHandle windows.Handle, jobHandle windows.Handle, result *bool) (err error)

func LocalAlloc

func LocalAlloc(flags uint32, size int) (ptr uintptr)

func LocalFree

func LocalFree(ptr uintptr)

func LogonUser

func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32, token *windows.Token) (err error)

func NTSuccess

func NTSuccess(status uint32) bool

func NtCreateFile

func NtCreateFile(handle *uintptr, accessMask uint32, oa *ObjectAttributes, iosb *IOStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32)

func NtCreateJobObject

func NtCreateJobObject(jobHandle *windows.Handle, desiredAccess uint32, objAttributes *ObjectAttributes) (status uint32)

func NtOpenDirectoryObject

func NtOpenDirectoryObject(handle *uintptr, accessMask uint32, oa *ObjectAttributes) (status uint32)

func NtOpenJobObject

func NtOpenJobObject(jobHandle *windows.Handle, desiredAccess uint32, objAttributes *ObjectAttributes) (status uint32)

func NtQueryDirectoryObject

func NtQueryDirectoryObject(handle uintptr, buffer *byte, length uint32, singleEntry bool, restartScan bool, context *uint32, returnLength *uint32) (status uint32)

func NtQuerySystemInformation

func NtQuerySystemInformation(systemInfoClass int, systemInformation uintptr, systemInfoLength uint32, returnLength *uint32) (status uint32)

func NtSetInformationFile

func NtSetInformationFile(handle uintptr, iosb *IOStatusBlock, information uintptr, length uint32, class uint32) (status uint32)

func OpenJobObject

func OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error)

func QueryInformationJobObject

func QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error)

func QueryIoRateControlInformationJobObject

func QueryIoRateControlInformationJobObject(jobHandle windows.Handle, volumeName *uint16, ioRateControlInfo **JOBOBJECT_IO_RATE_CONTROL_INFORMATION, infoBlockCount *uint32) (ret uint32, err error)

func QueryWorkingSet

func QueryWorkingSet(handle windows.Handle, pv uintptr, cb uint32) (err error)

func RtlMoveMemory

func RtlMoveMemory(destination *byte, source *byte, length uintptr) (err error)

func RtlNtStatusToDosError

func RtlNtStatusToDosError(status uint32) (winerr error)

func SearchPath

func SearchPath(lpPath *uint16, lpFileName *uint16, lpExtension *uint16, nBufferLength uint32, lpBuffer *uint16, lpFilePath *uint16) (size uint32, err error)

func SetIoRateControlInformationJobObject

func SetIoRateControlInformationJobObject(jobHandle windows.Handle, ioRateControlInfo *JOBOBJECT_IO_RATE_CONTROL_INFORMATION) (ret uint32, err error)

func SetJobCompartmentId

func SetJobCompartmentId(handle windows.Handle, compartmentId uint32) (win32Err error)

func Uint16BufferToSlice

func Uint16BufferToSlice(buffer *uint16, bufferLength int) (result []uint16)

Uint16BufferToSlice wraps a uint16 pointer-and-length into a slice for easier interop with Go APIs

Types

type DevPropKey

type DevPropKey struct {
	Fmtid guid.GUID
	Pid   uint32
}

type FILE_ID_INFO

type FILE_ID_INFO struct {
	VolumeSerialNumber uint64
	FileID             [16]byte
}

C declaration:

typedef struct _FILE_ID_INFO {
    ULONGLONG   VolumeSerialNumber;
    FILE_ID_128 FileId;
} FILE_ID_INFO, *PFILE_ID_INFO;

Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_id_info

type FileDispositionInformationEx

type FileDispositionInformationEx struct {
	Flags uintptr
}

type FileLinkInformation

type FileLinkInformation struct {
	ReplaceIfExists bool
	RootDirectory   uintptr
	FileNameLength  uint32
	FileName        [1]uint16
}

type IOStatusBlock

type IOStatusBlock struct {
	Status, Information uintptr
}

type JOBOBJECT_ASSOCIATE_COMPLETION_PORT

type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct {
	CompletionKey  windows.Handle
	CompletionPort windows.Handle
}

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port

type JOBOBJECT_BASIC_ACCOUNTING_INFORMATION

type JOBOBJECT_BASIC_ACCOUNTING_INFORMATION struct {
	TotalUserTime             int64
	TotalKernelTime           int64
	ThisPeriodTotalUserTime   int64
	ThisPeriodTotalKernelTime int64
	TotalPageFaultCount       uint32
	TotalProcesses            uint32
	ActiveProcesses           uint32
	TotalTerminateProcesses   uint32
}

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_accounting_information

type JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

type JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION struct {
	BasicInfo JOBOBJECT_BASIC_ACCOUNTING_INFORMATION
	IoInfo    windows.IO_COUNTERS
}

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_and_io_accounting_information

type 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_basic_limit_information

type 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_basic_process_id_list

func (*JOBOBJECT_BASIC_PROCESS_ID_LIST) AllPids

AllPids returns all the process Ids in the job object.

type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION struct {
	ControlFlags uint32
	Value        uint32
}

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information

type JOBOBJECT_IO_ATTRIBUTION_INFORMATION

type JOBOBJECT_IO_ATTRIBUTION_INFORMATION struct {
	ControlFlags uint32
	ReadStats    JOBOBJECT_IO_ATTRIBUTION_STATS
	WriteStats   JOBOBJECT_IO_ATTRIBUTION_STATS
}
typedef struct _JOBOBJECT_IO_ATTRIBUTION_INFORMATION {
    ULONG ControlFlags;
    JOBOBJECT_IO_ATTRIBUTION_STATS ReadStats;
    JOBOBJECT_IO_ATTRIBUTION_STATS WriteStats;
} JOBOBJECT_IO_ATTRIBUTION_INFORMATION, *PJOBOBJECT_IO_ATTRIBUTION_INFORMATION;

type JOBOBJECT_IO_ATTRIBUTION_STATS

type JOBOBJECT_IO_ATTRIBUTION_STATS struct {
	IoCount                       uintptr
	TotalNonOverlappedQueueTime   uint64
	TotalNonOverlappedServiceTime uint64
	TotalSize                     uint64
}
typedef struct _JOBOBJECT_IO_ATTRIBUTION_STATS {
    ULONG_PTR IoCount;
    ULONGLONG TotalNonOverlappedQueueTime;
    ULONGLONG TotalNonOverlappedServiceTime;
    ULONGLONG TotalSize;
} JOBOBJECT_IO_ATTRIBUTION_STATS, *PJOBOBJECT_IO_ATTRIBUTION_STATS;

type 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/jobapi2/ns-jobapi2-jobobject_io_rate_control_information

type JOBOBJECT_MEMORY_USAGE_INFORMATION

type JOBOBJECT_MEMORY_USAGE_INFORMATION struct {
	JobMemory         uint64
	PeakJobMemoryUsed uint64
}
typedef struct _JOBOBJECT_MEMORY_USAGE_INFORMATION {
    ULONG64 JobMemory;
    ULONG64 PeakJobMemoryUsed;
} JOBOBJECT_MEMORY_USAGE_INFORMATION, *PJOBOBJECT_MEMORY_USAGE_INFORMATION;

type ObjectAttributes

type ObjectAttributes struct {
	Length             uintptr
	RootDirectory      uintptr
	ObjectName         *UnicodeString
	Attributes         uintptr
	SecurityDescriptor uintptr
	SecurityQoS        uintptr
}

type ObjectDirectoryInformation

type ObjectDirectoryInformation struct {
	Name     UnicodeString
	TypeName UnicodeString
}

type PSAPI_WORKING_SET_BLOCK

type PSAPI_WORKING_SET_BLOCK struct {
	Flags uintptr
}

type PSAPI_WORKING_SET_INFORMATION

type PSAPI_WORKING_SET_INFORMATION struct {
	NumberOfEntries uintptr
	WorkingSetInfo  [1]PSAPI_WORKING_SET_BLOCK
}

type SYSTEM_PROCESS_INFORMATION

type SYSTEM_PROCESS_INFORMATION struct {
	NextEntryOffset              uint32         // ULONG
	NumberOfThreads              uint32         // ULONG
	WorkingSetPrivateSize        int64          // LARGE_INTEGER
	HardFaultCount               uint32         // ULONG
	NumberOfThreadsHighWatermark uint32         // ULONG
	CycleTime                    uint64         // ULONGLONG
	CreateTime                   int64          // LARGE_INTEGER
	UserTime                     int64          // LARGE_INTEGER
	KernelTime                   int64          // LARGE_INTEGER
	ImageName                    UnicodeString  // UNICODE_STRING
	BasePriority                 int32          // KPRIORITY
	UniqueProcessID              windows.Handle // HANDLE
	InheritedFromUniqueProcessID windows.Handle // HANDLE
	HandleCount                  uint32         // ULONG
	SessionID                    uint32         // ULONG
	UniqueProcessKey             *uint32        // ULONG_PTR
	PeakVirtualSize              uintptr        // SIZE_T
	VirtualSize                  uintptr        // SIZE_T
	PageFaultCount               uint32         // ULONG
	PeakWorkingSetSize           uintptr        // SIZE_T
	WorkingSetSize               uintptr        // SIZE_T
	QuotaPeakPagedPoolUsage      uintptr        // SIZE_T
	QuotaPagedPoolUsage          uintptr        // SIZE_T
	QuotaPeakNonPagedPoolUsage   uintptr        // SIZE_T
	QuotaNonPagedPoolUsage       uintptr        // SIZE_T
	PagefileUsage                uintptr        // SIZE_T
	PeakPagefileUsage            uintptr        // SIZE_T
	PrivatePageCount             uintptr        // SIZE_T
	ReadOperationCount           int64          // LARGE_INTEGER
	WriteOperationCount          int64          // LARGE_INTEGER
	OtherOperationCount          int64          // LARGE_INTEGER
	ReadTransferCount            int64          // LARGE_INTEGER
	WriteTransferCount           int64          // LARGE_INTEGER
	OtherTransferCount           int64          // LARGE_INTEGER
}

type UnicodeString

type UnicodeString struct {
	Length        uint16
	MaximumLength uint16
	Buffer        *uint16
}

func NewUnicodeString

func NewUnicodeString(s string) (*UnicodeString, error)

NewUnicodeString allocates a new UnicodeString and copies `s` into the buffer of the new UnicodeString.

func (UnicodeString) String

func (uni UnicodeString) String() string

String converts a UnicodeString to a golang string

Source Files

devices.go errors.go filesystem.go iocp.go jobobject.go logon.go memory.go net.go path.go process.go processor.go system.go thread.go utils.go winapi.go zsyscall_windows.go

Version
v0.8.16
Published
Apr 7, 2021
Platform
windows/amd64
Imports
6 packages
Last checked
6 hours ago

Tools for package owners.