From 4c4112fbc79752361648d14ecb9a82c58aa0522c Mon Sep 17 00:00:00 2001 From: zhibog Date: Sat, 24 Oct 2020 00:14:01 +0200 Subject: [PATCH 1/3] Fixed getting windows version. The former function is no longer working on Windows 10. Also fixed the struct to use correct win32 names --- core/os/os_windows.odin | 33 ++++++++++++++++----------------- core/sys/windows/ntdll.odin | 8 ++++++++ core/sys/windows/types.odin | 25 +++++++++++++------------ 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 core/sys/windows/ntdll.odin diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin index 86c4b4df2..a6af811b5 100644 --- a/core/os/os_windows.odin +++ b/core/os/os_windows.odin @@ -160,40 +160,39 @@ _alloc_command_line_arguments :: proc() -> []string { return arg_list; } -get_windows_version_ansi :: proc() -> win32.OSVERSIONINFOEXW { +get_windows_version_w :: proc() -> win32.OSVERSIONINFOEXW { osvi : win32.OSVERSIONINFOEXW; - osvi.os_version_info_size = size_of(win32.OSVERSIONINFOEXW); - win32.GetVersionExW(&osvi); + osvi.dwOSVersionInfoSize = size_of(win32.OSVERSIONINFOEXW); + win32.RtlGetVersion(&osvi); return osvi; } is_windows_xp :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 5 && osvi.minor_version == 1); + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1); } is_windows_vista :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 6 && osvi.minor_version == 0); + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0); } is_windows_7 :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 6 && osvi.minor_version == 1); + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1); } is_windows_8 :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 6 && osvi.minor_version == 2); + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2); } is_windows_8_1 :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 6 && osvi.minor_version == 3); + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3); } is_windows_10 :: proc() -> bool { - osvi := get_windows_version_ansi(); - return (osvi.major_version == 10 && osvi.minor_version == 0); -} - + osvi := get_windows_version_w(); + return (osvi.dwMajorVersion == 10 && osvi.dwMinorVersion == 0); +} \ No newline at end of file diff --git a/core/sys/windows/ntdll.odin b/core/sys/windows/ntdll.odin new file mode 100644 index 000000000..2f2f74687 --- /dev/null +++ b/core/sys/windows/ntdll.odin @@ -0,0 +1,8 @@ +package version + +foreign import ntdll_lib "system:ntdll.lib" + +@(default_calling_convention="std") +foreign ntdll_lib { + RtlGetVersion :: proc(lpVersionInformation: ^OSVERSIONINFOEXW) -> NTSTATUS ---; +} \ No newline at end of file diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 73af4f418..5d1cbb6c9 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -36,6 +36,7 @@ ULONG_PTR :: uint; DWORD_PTR :: ULONG_PTR; ULONG :: c_ulong; UCHAR :: BYTE; +NTSTATUS :: c.long; PDWORD_PTR :: ^DWORD_PTR; ATOM :: distinct WORD; @@ -721,15 +722,15 @@ SYSTEM_INFO :: struct { // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfoexw OSVERSIONINFOEXW :: struct { - os_version_info_size: ULONG, - major_version: ULONG, - minor_version: ULONG, - build_number: ULONG, - platform_id : ULONG, - service_pack_string: [128]WCHAR, - service_pack_major: USHORT, - service_pack_minor: USHORT, - suite_mask: USHORT, - product_type: UCHAR, - reserved: UCHAR, -} + dwOSVersionInfoSize: ULONG, + dwMajorVersion: ULONG, + dwMinorVersion: ULONG, + dwBuildNumber: ULONG, + dwPlatformId: ULONG, + szCSDVersion: [128]WCHAR, + wServicePackMajor: USHORT, + wServicePackMinor: USHORT, + wSuiteMask: USHORT, + wProductType: UCHAR, + wReserved: UCHAR, +}; \ No newline at end of file From 05b58bdbb138cce95a7f948837897b40b4369cf2 Mon Sep 17 00:00:00 2001 From: zhibog Date: Sat, 24 Oct 2020 00:17:36 +0200 Subject: [PATCH 2/3] Fixed package name --- core/sys/windows/ntdll.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys/windows/ntdll.odin b/core/sys/windows/ntdll.odin index 2f2f74687..0f7472f33 100644 --- a/core/sys/windows/ntdll.odin +++ b/core/sys/windows/ntdll.odin @@ -1,4 +1,4 @@ -package version +package sys_windows foreign import ntdll_lib "system:ntdll.lib" From 213864a50c653903f41f9e2f4a5e84b9a82b9ea0 Mon Sep 17 00:00:00 2001 From: Tetralux Date: Mon, 26 Oct 2020 00:12:31 +0000 Subject: [PATCH 3/3] Reuse container.Queue capacity when calling pop_front() Currently, the Queue will never reuse it's full capacity if you call `pop_front`, even if you empty it before pushing more items. With this change, if you empty the Queue with `pop_front`, then the offset will be set back to the start of the underlying array when you pop the last item. Future pushes will then reuse the already-allocated--but now empty--space. --- core/container/queue.odin | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/container/queue.odin b/core/container/queue.odin index 6e7e79ad3..2664b9a08 100644 --- a/core/container/queue.odin +++ b/core/container/queue.odin @@ -115,6 +115,9 @@ queue_pop_front :: proc(q: ^$Q/Queue($T)) -> T { item := queue_get(q^, 0); q.offset = (q.offset + 1) % array_len(q.data); q.len -= 1; + if q.len == 0 { + q.offset = 0; + } return item; }