#! @file windows.sakura #! @author John Christman (sorakatadzuma@gmail.com) #! @copyright Malunal Studios, LLC. #! @license MIT #! #! Contains `system::windows`: what Windows gives a program, declared once for #! std, its runtime, and anything else that reaches the system itself. These are #! the functions of `kernel32.dll`, the structs they take, as C lays them out, #! and the numbers they are asked for and give. The functions Windows keeps for #! waiting on a word are in `waits.sakura`, a library of their own. extern import "kernel32.dll" when os == windows; extern module system::windows when os == windows; pub def GetLastError(): u32; pub def SetLastError(code: u32): void; pub def GetStdHandle(which: u32): u64; pub def SetStdHandle(which: u32, handle: u64): i32; pub def CloseHandle(handle: u64): i32; pub def DuplicateHandle( from_process: u64, handle: u64, to_process: u64, made: &mut u64, access: u32, inherit: i32, options: u32 ): i32; pub def CreateFileW( name: *u16, access: u32, share: u32, security: *mut u8, disposition: u32, flags: u32, model: u64 ): u64; pub def ReOpenFile(handle: u64, access: u32, share: u32, flags: u32): u64; pub def ReadFile( handle: u64, into: *mut u8, length: u32, read: &mut u32, overlapped: *mut u8 ): i32; pub def WriteFile( handle: u64, from: *u8, length: u32, written: &mut u32, overlapped: *mut u8 ): i32; pub def SetFilePointerEx(handle: u64, distance: i64, position: &mut i64, method: u32): i32; pub def GetFileType(handle: u64): u32; pub def GetFileInformationByHandle(handle: u64, info: &mut file_information): i32; pub def GetFileInformationByHandleEx(handle: u64, class: u32, info: *mut u8, size: u32): i32; pub def SetFileInformationByHandle(handle: u64, class: u32, info: *mut u8, size: u32): i32; pub def GetFinalPathNameByHandleW(handle: u64, into: *mut u16, length: u32, flags: u32): u32; pub def GetFileAttributesW(name: *u16): u32; pub def SetFileAttributesW(name: *u16, attributes: u32): i32; pub def CreateDirectoryW(name: *u16, security: *mut u8): i32; pub def RemoveDirectoryW(name: *u16): i32; pub def DeleteFileW(name: *u16): i32; pub def MoveFileExW(from: *u16, to: *u16, flags: u32): i32; pub def GetCurrentDirectoryW(length: u32, into: *mut u16): u32; pub def SetCurrentDirectoryW(name: *u16): i32; pub def GetFullPathNameW(name: *u16, length: u32, into: *mut u16, part: *mut u8): u32; pub def FindFirstFileExW( name: *u16, level: u32, data: *mut u8, search: u32, filter: *mut u8, flags: u32 ): u64; pub def FindNextFileW(find: u64, data: *mut u8): i32; pub def FindClose(find: u64): i32; pub def GetConsoleMode(handle: u64, mode: &mut u32): i32; pub def GetConsoleWindow(): u64; pub def WriteConsoleW( handle: u64, from: *u16, length: u32, written: &mut u32, reserved: *mut u8 ): i32; pub def ReadConsoleW( handle: u64, into: *mut u16, length: u32, read: &mut u32, control: *mut u8 ): i32; pub def CreatePipe(reading: &mut u64, writing: &mut u64, security: *mut u8, size: u32): i32; pub def PeekNamedPipe( handle: u64, into: *mut u8, length: u32, read: *mut u32, available: &mut u32, left: *mut u32 ): i32; pub def GetCurrentProcess(): u64; pub def GetCurrentProcessId(): u32; pub def GetCurrentThreadId(): u32; pub def GetModuleFileNameW(library: u64, into: *mut u16, length: u32): u32; pub def GetCommandLineW(): *u16; pub def GetSystemDirectoryW(into: *mut u16, length: u32): u32; pub def CreateProcessW( application: *u16, command: *mut u16, process_security: *mut u8, thread_security: *mut u8, inherit: i32, flags: u32, environment: *mut u16, directory: *u16, startup: &mut startup_information, information: &mut process_information ): i32; pub def InitializeProcThreadAttributeList( list: *mut u8, count: u32, flags: u32, size: &mut u64 ): i32; pub def UpdateProcThreadAttribute( list: *mut u8, flags: u32, attribute: u64, value: *mut u8, size: u64, previous: *mut u8, returned: *mut u64 ): i32; pub def DeleteProcThreadAttributeList(list: *mut u8): void; pub def OpenProcess(access: u32, inherit: i32, process: u32): u64; pub def TerminateProcess(process: u64, code: u32): i32; pub def GetExitCodeProcess(process: u64, code: &mut u32): i32; pub def WaitForSingleObject(handle: u64, milliseconds: u32): u32; pub def WaitForMultipleObjects(count: u32, handles: *u64, all: i32, milliseconds: u32): u32; pub def CreateWaitableTimerExW(security: *mut u8, name: *u16, flags: u32, access: u32): u64; pub def SetWaitableTimer( timer: u64, due: &i64, period: i32, routine: *mut u8, argument: *mut u8, wake: i32 ): i32; pub def Sleep(milliseconds: u32): void; pub def SwitchToThread(): i32; pub def GetActiveProcessorCount(group: u16): u32; pub def GetProcessAffinityMask(process: u64, mask: &mut u64, system: &mut u64): i32; pub def GetEnvironmentStringsW(): *mut u16; pub def FreeEnvironmentStringsW(block: *mut u16): i32; pub def GetSystemTimePreciseAsFileTime(time: &mut filetime): void; pub def QueryPerformanceCounter(count: &mut i64): i32; pub def QueryPerformanceFrequency(frequency: &mut i64): i32; pub def GetDynamicTimeZoneInformation(into: &mut zone_information): u32; pub def VirtualAlloc(address: u64, size: u64, kind: u32, protection: u32): u64; pub def VirtualFree(address: u64, size: u64, kind: u32): i32; pub def MultiByteToWideChar(page: u32, flags: u32, bytes: *u8, count: i32, units: *mut u16, room: i32): i32; pub def WideCharToMultiByte( page: u32, flags: u32, wide: *u16, count: i32, into: *mut u8, size: i32, fallback: *u8, used: *mut i32 ): i32; pub def ExitProcess(code: u32): void; pub def SetErrorMode(mode: u32): u32; pub def OpenThread(access: u32, inherit: i32, id: u32): u64; pub def SuspendThread(thread: u64): u32; pub def ResumeThread(thread: u64): u32; pub def GetThreadContext(thread: u64, context: *mut u64): i32; pub def VirtualProtect(at: u64, size: u64, protect: u32, was: &mut u32): i32; pub def FlushInstructionCache(process: u64, at: u64, size: u64): i32; pub def LoadLibraryW(name: *u16): u64; pub def FreeLibrary(handle: u64): i32; pub def GetProcAddress(handle: u64, name: *u8): u64; pub def GetModuleHandleW(name: *u16): u64; pub def K32EnumProcessModules(process: u64, into: *mut u64, size: u32, needed: &mut u32): i32; pub def CreateJobObjectW(security: *mut u8, name: *u16): u64; pub def SetInformationJobObject(job: u64, kind: u32, information: *mut u8, length: u32): i32; pub def AssignProcessToJobObject(job: u64, process: u64): i32; # What the system's functions are asked for, and what they give. pub val invalid_handle: u64 = 0xFFFFFFFFFFFFFFFF; pub val invalid_attributes: u32 = 0xFFFFFFFF; pub val infinite: u32 = 0xFFFFFFFF; pub val wait_failed: u32 = 0xFFFFFFFF; pub val generic_read: u32 = 0x80000000; pub val generic_write: u32 = 0x40000000; pub val append_data: u32 = 0x4; pub val read_attributes: u32 = 0x80; pub val write_attributes: u32 = 0x100; pub val synchronize: u32 = 0x100000; pub val share_all: u32 = 7; # Others may read, write, rename, and remove it. pub val create_new: u32 = 1; pub val create_always: u32 = 2; pub val open_existing: u32 = 3; pub val open_always: u32 = 4; pub val truncate_existing: u32 = 5; pub val backup_semantics: u32 = 0x02000000; # Lets a directory be opened. pub val open_reparse_point: u32 = 0x00200000; # Opens a link rather than what it leads to. pub val readonly: u32 = 0x1; pub val directory: u32 = 0x10; pub val device: u32 = 0x40; pub val normal: u32 = 0x80; pub val reparse_point: u32 = 0x400; pub val symlink_tag: u32 = 0xA000000C; pub val junction_tag: u32 = 0xA0000003; pub val disk_type: u32 = 1; pub val use_std_handles: u32 = 0x100; pub val unicode_block: u32 = 0x400; pub val extended_startup: u32 = 0x80000; pub val create_no_window: u32 = 0x08000000; # A console program started gets a console no one sees. pub val handle_list: u64 = 0x20002; pub val same_access: u32 = 2; pub val process_terminate: u32 = 1; pub val control_c_exit: u32 = 0xC000013A; # What a program the console's Ctrl-C stopped exits with. # The codes of failures the operations look for themselves. pub val error_file_not_found: u32 = 2; pub val error_path_not_found: u32 = 3; pub val error_access_denied: u32 = 5; pub val error_invalid_function: u32 = 1; pub val error_sharing_violation: u32 = 32; pub val error_handle_eof: u32 = 38; pub val error_invalid_parameter: u32 = 87; pub val error_broken_pipe: u32 = 109; pub val error_no_more_files: u32 = 18; pub val error_bad_exe_format: u32 = 193; pub val error_operation_aborted: u32 = 995; pub val error_timeout: u32 = 1460; pub val error_cant_access_file: u32 = 1920; # A time of the system, in tenths of microseconds since 1601 began, as two # halves. pub struct filetime { pub var low: u32; pub var high: u32; } # What `GetFileInformationByHandle` describes a file with. pub struct file_information { pub var attributes: u32; pub var created: filetime; pub var accessed: filetime; pub var written: filetime; pub var volume: u32; pub var size_high: u32; pub var size_low: u32; pub var links: u32; pub var index_high: u32; pub var index_low: u32; } # What `SetFileInformationByHandle` sets a file's attributes with, leaving each # time that is zero as it is. pub struct basic_information { pub var created: i64; pub var accessed: i64; pub var written: i64; pub var changed: i64; pub var attributes: u32; } # What a program is started with: its window, which a program of the console # has none of, its standard streams, and a list of what more it is given. pub struct startup_information { pub var size: u32; pub var reserved: *mut u16; pub var desktop: *mut u16; pub var title: *mut u16; pub var x: u32; pub var y: u32; pub var width: u32; pub var height: u32; pub var columns: u32; pub var rows: u32; pub var fill: u32; pub var flags: u32; pub var show: u16; pub var extra_size: u16; pub var extra: *mut u8; pub var standard_input: u64; pub var standard_output: u64; pub var standard_error: u64; pub var attributes: *mut u8; } # What `CreateProcessW` gives of a program it started. pub struct process_information { pub var process: u64; pub var thread: u64; pub var process_id: u32; pub var thread_id: u32; } # A date and time of the system, as a zone's changes are given. pub struct system_time { pub var year: u16; pub var month: u16; pub var day_of_week: u16; pub var day: u16; # Of a change, which of the month's weeks, 5 being its last. pub var hour: u16; pub var minute: u16; pub var second: u16; pub var millisecond: u16; } # The zone the system is set to, as `GetDynamicTimeZoneInformation` gives it: # minutes behind UTC, and what it calls its usual and its summer time, how far # each is from that, and when each begins. pub struct zone_information { pub var bias: i32; pub var standard_name: u16[32]; pub var standard_date: system_time; pub var standard_bias: i32; pub var daylight_name: u16[32]; pub var daylight_date: system_time; pub var daylight_bias: i32; pub var key_name: u16[128]; pub var no_daylight: u8; } pub const startup_bytes: u64 = 112; pub const basic_bytes: u64 = 40;