Processes and threads v0.1.0
ALL_PROCESSOR_GROUPS
pub const ALL_PROCESSOR_GROUPS: uint16 = 0xFFFF;
ALL_PROCESSOR_GROUPS: asks GetActiveProcessorCount about every processor group at once.
STACK_SIZE_PARAM_IS_A_RESERVATION
pub const STACK_SIZE_PARAM_IS_A_RESERVATION: uint32 = 0x00010000;
STACK_SIZE_PARAM_IS_A_RESERVATION: CreateThread takes its stack size as the space to reserve rather than to
commit, which is what a stack size usually means.
INFINITE
pub const INFINITE: uint32 = 0xFFFFFFFF;
INFINITE: a wait with no time-out.
ExitProcess
pub extern func ExitProcess(exitCode: uint32)
Ends the calling process and all its threads.
Parameters
| Name | Type | Description |
|---|---|---|
exitCode | uint32 | the status to report |
FreeLibrary
pub extern func FreeLibrary(libModule: *opaque) -> bool32
Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. When the reference count reaches zero, the module is unloaded from the address space of the calling process and the handle is no longer valid
See also: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-freelibrary
Parameters
| Name | Type | Description |
|---|---|---|
libModule | *opaque | a module handle from LoadLibraryA |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
GetCommandLineW
pub extern func GetCommandLineW() -> *uint16
Retrieves the command line the process was started with, as one string.
The string belongs to the process for its whole life and must not be written or freed. It is the command line
exactly as the parent passed it, quotes and all; CommandLineToArgvW splits it into arguments.
See also: https://learn.microsoft.com/windows/win32/api/processenv/nf-processenv-getcommandlinew
Returns: the NUL-terminated UTF-16 command line, which is never null
GetModuleFileNameW
pub extern func GetModuleFileNameW(
moduleHandle: *opaque,
buffer: *var uint16,
size: uint32
) -> uint32
Retrieves the full path of the file a module was loaded from; a null module is the process's executable.
The path is NUL-terminated when it fits. When it does not, it is cut to size units, the last of them the
terminator, and the call returns size.
See also: https://learn.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew
Parameters
| Name | Type | Description |
|---|---|---|
moduleHandle | *opaque | the module, or null for the executable |
buffer | *var uint16 | receives the path |
size | uint32 | how many units buffer holds |
Returns: the path's length without its terminator, size when it was cut, or zero on failure with the
reason in GetLastError
GetEnvironmentStringsW
pub extern func GetEnvironmentStringsW() -> *uint16
Copies the calling process's environment block.
The block is a sequence of NUL-terminated name=value UTF-16 strings ended by an empty one. It is a copy owned
by the caller, released with FreeEnvironmentStringsW; changes made to the environment after the call do not
appear in it.
See also: https://learn.microsoft.com/windows/win32/api/processenv/nf-processenv-getenvironmentstringsw
Returns: the environment block, or null on failure with the reason in GetLastError
GetCurrentProcessId
pub extern func GetCurrentProcessId() -> uint32
Retrieves the process identifier of the calling process.
Returns: the calling process's identifier
GetActiveProcessorCount
pub extern func GetActiveProcessorCount(groupNumber: uint16) -> uint32
Retrieves the number of active processors in a processor group, or in all of them.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getactiveprocessorcount
Parameters
| Name | Type | Description |
|---|---|---|
groupNumber | uint16 | the processor group, or ALL_PROCESSOR_GROUPS for the whole system |
Returns: the number of active processors, or zero on failure
GetCurrentThreadId
pub extern func GetCurrentThreadId() -> uint32
pub extern func GetCurrentThreadId() -> uint32
Retrieves the thread identifier of the calling thread.
Returns: the calling thread's identifier
GetProcAddress
pub extern func GetProcAddress(
libModule: *opaque,
procName: *char8
) -> *opaque
Retrieves the address of an exported symbol.
See also: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress
Parameters
| Name | Type | Description |
|---|---|---|
libModule | *opaque | a module handle from LoadLibraryA |
procName | *char8 | the exported symbol's name |
Returns: the symbol's address, or null
LoadLibraryA
pub extern func LoadLibraryA(libFileName: *char8) -> *opaque
Loads a DLL into the calling process.
See also: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya
Parameters
| Name | Type | Description |
|---|---|---|
libFileName | *char8 | the library's name or path |
Returns: the module's handle, or null
CreateThread
pub extern func CreateThread(
securityAttributes: *opaque,
stackSize: uint64,
startAddress: *opaque,
parameter: *opaque,
creationFlags: uint32,
threadId: *uint32
) -> *opaque
Creates a thread to execute within the virtual address space of the calling process.
Parameters
| Name | Type | Description |
|---|---|---|
securityAttributes | *opaque | a security descriptor, or null for the default |
stackSize | uint64 | the initial stack size, or zero for the default |
startAddress | *opaque | the thread's entry point |
parameter | *opaque | the value handed to the entry point |
creationFlags | uint32 | the thread creation flags |
threadId | *uint32 | receives the new thread's identifier, or null |
Returns: the new thread's handle, or null
Sleep
pub extern func Sleep(milliseconds: uint32)
Suspends the execution of the current thread until the time-out interval elapses.
See also: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds | uint32 | a duration in milliseconds |
SwitchToThread
pub extern func SwitchToThread() -> bool32
Causes the calling thread to yield execution to another thread that is ready to run.
Returns: non-zero on success, and zero on failure with the reason in GetLastError
WaitForSingleObject
pub extern func WaitForSingleObject(
handle: *opaque,
milliseconds: uint32
) -> uint32
Waits until the specified object is in the signaled state or the time-out interval elapses.
See also: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject
Parameters
| Name | Type | Description |
|---|---|---|
handle | *opaque | the handle to act on |
milliseconds | uint32 | a duration in milliseconds |
Returns: why the wait ended
CommandLineToArgvW
pub extern func CommandLineToArgvW(
commandLine: *uint16,
count: *var int32
) -> **uint16
Splits a command line into arguments the way the C runtime does.
Backslashes, quotes and spaces follow the C runtime's rules, and the first argument, the program, is read up to
the first space outside quotes. The result is one allocation holding the pointer array and every argument; it
stays valid until passed to LocalFree.
See also: https://learn.microsoft.com/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw
Parameters
| Name | Type | Description |
|---|---|---|
commandLine | *uint16 | the NUL-terminated UTF-16 command line, usually from GetCommandLineW |
count | *var int32 | receives how many arguments the array holds |
Returns: the array of NUL-terminated UTF-16 arguments, or null on failure with the reason in GetLastError