From 3237f87a09c42321dc6699ec0c281d6818048b28 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 14 Mar 2023 11:37:23 +0100 Subject: [PATCH] Added some Win32 declarations. --- lib/std/io/os/fileinfo_win32.c3 | 2 +- lib/std/os/win32/files.c3 | 8 +++-- lib/std/os/win32/process.c3 | 18 ++++++++++ lib/std/os/win32/types.c3 | 58 +++++++++++++++++++++++++++++- lib/std/threads/os/thread_win32.c3 | 2 -- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 lib/std/os/win32/process.c3 diff --git a/lib/std/io/os/fileinfo_win32.c3 b/lib/std/io/os/fileinfo_win32.c3 index e44906235..241292b3c 100644 --- a/lib/std/io/os/fileinfo_win32.c3 +++ b/lib/std/io/os/fileinfo_win32.c3 @@ -21,7 +21,7 @@ fn bool native_file_or_dir_exists(String path) { @pool() { - return files::win32_PathFileExistsW(path.to_temp_utf16()) ?? false; + return (bool)files::win32_PathFileExistsW(path.to_temp_utf16()) ?? false; }; } diff --git a/lib/std/os/win32/files.c3 b/lib/std/os/win32/files.c3 index 5b74146a7..e844bb392 100644 --- a/lib/std/os/win32/files.c3 +++ b/lib/std/os/win32/files.c3 @@ -24,10 +24,12 @@ struct Win32_FILE_ATTRIBUTE_DATA Win32_DWORD nFileSizeLow; } -extern fn bool win32_GetFileAttributesExW(Win32_LPCWSTR, Win32_GET_FILEEX_INFO_LEVELS, Win32_LPVOID) @extern("GetFileAttributesExW"); -extern fn bool win32_PathFileExistsW(Win32_LPCWSTR) @extern("PathFileExistsW"); +extern fn Win32_BOOL win32_CloseHandle(Win32_HANDLE) @extern("CloseHandle"); +extern fn Win32_BOOL win32_CreatePipe(Win32_PHANDLE hReadPipe, Win32_PHANDLE hWritePipe, Win32_LPSECURITY_ATTRIBUTES lpPipeAttributes, Win32_DWORD nSize) @extern("CreatePipe"); +extern fn Win32_BOOL win32_GetFileAttributesExW(Win32_LPCWSTR, Win32_GET_FILEEX_INFO_LEVELS, Win32_LPVOID) @extern("GetFileAttributesExW"); +extern fn Win32_BOOL win32_PathFileExistsW(Win32_LPCWSTR) @extern("PathFileExistsW"); extern fn Win32_DWORD win32_GetTempPathW(Win32_DWORD nBufferLength, Win32_LPWSTR lpBuffer) @extern("GetTempPathW"); -extern fn bool win32_SetCurrentDirectoryW(Win32_LPCTSTR buffer) @extern("SetCurrentDirectoryW"); +extern fn Win32_BOOL win32_SetCurrentDirectoryW(Win32_LPCTSTR buffer) @extern("SetCurrentDirectoryW"); /* extern ulong _win32_GetCurrentDirectoryW(ulong, Char16* buffer) @extern("GetCurrentDirectoryW"); diff --git a/lib/std/os/win32/process.c3 b/lib/std/os/win32/process.c3 new file mode 100644 index 000000000..4f74c35c3 --- /dev/null +++ b/lib/std/os/win32/process.c3 @@ -0,0 +1,18 @@ +module std::os::win32::process; + +$if (env::os_is_win32()): + +extern fn bool win32_CreateProcessW( + Win32_LPCWSTR lpApplicationName, + Win32_LPWSTR lpCommandLine, + Win32_LPSECURITY_ATTRIBUTES lpProcessAttributes, + Win32_LPSECURITY_ATTRIBUTES lpThreadAttributes, + Win32_BOOL bInheritHandles, + Win32_DWORD dwCreationFlags, + Win32_LPVOID lpEnvironment, + Win32_LPCWSTR lpCurrentDirectory, + Win32_LPSTARTUPINFOW lpStartupInfo, + Win32_LPPROCESS_INFORMATION lpProcessInformation +); + +$endif; \ No newline at end of file diff --git a/lib/std/os/win32/types.c3 b/lib/std/os/win32/types.c3 index 46991a74a..68f415fa3 100644 --- a/lib/std/os/win32/types.c3 +++ b/lib/std/os/win32/types.c3 @@ -183,4 +183,60 @@ union Win32_LARGE_INTEGER Win32_LONG highPart; } ulong quadPart; -} \ No newline at end of file +} + +typedef Win32_CRITICAL_SECTION = distinct ulong[5]; + +struct Win32_SECURITY_ATTRIBUTES +{ + Win32_DWORD nLength; + Win32_LPVOID lpSecurityDescriptor; + Win32_BOOL bInheritHandle; +} + +typedef Win32_LPSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; +typedef Win32_PSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; + +struct Win32_STARTUPINFOW +{ + Win32_DWORD cb; + Win32_LPWSTR lpReserved; + Win32_LPWSTR lpDesktop; + Win32_LPWSTR lpTitle; + Win32_DWORD dwX; + Win32_DWORD dwY; + Win32_DWORD dwXSize; + Win32_DWORD dwYSize; + Win32_DWORD dwXCountChars; + Win32_DWORD dwYCountChars; + Win32_DWORD dwFillAttribute; + Win32_DWORD dwFlags; + Win32_WORD wShowWindow; + Win32_WORD cbReserved2; + Win32_LPBYTE lpReserved2; + Win32_HANDLE hStdInput; + Win32_HANDLE hStdOutput; + Win32_HANDLE hStdError; +} + +typedef Win32_LPSTARTUPINFOW = Win32_STARTUPINFOW*; + +struct Win32_STARTUPINFOEXW +{ + inline Win32_STARTUPINFOW win32_StartupInfo; + Win32_LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; +} + +typedef Win32_LPPROC_THREAD_ATTRIBUTE_LIST = void*; +typedef Win32_LPSTARTUPINFOEXW = Win32_STARTUPINFOEXW*; + +struct Win32_PROCESS_INFORMATION +{ + Win32_HANDLE hProcess; + Win32_HANDLE hThread; + Win32_DWORD dwProcessId; + Win32_DWORD dwThreadId; +} + +typedef Win32_PPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; +typedef Win32_LPPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; diff --git a/lib/std/threads/os/thread_win32.c3 b/lib/std/threads/os/thread_win32.c3 index ce34cfd4f..76b02dcc9 100644 --- a/lib/std/threads/os/thread_win32.c3 +++ b/lib/std/threads/os/thread_win32.c3 @@ -3,8 +3,6 @@ module std::thread::os; $if (thread::THREAD_MODEL == ThreadModel.WIN32): typedef NativeThread = Win32_HANDLE; -typedef Win32_CRITICAL_SECTION = distinct ulong[5]; -typedef Win32_HANDLE = distinct ulong; struct NativeMutex {