From 46c610d6e59e0becad790c795f4b1ff159da3a79 Mon Sep 17 00:00:00 2001 From: Tetralux <1348560+Tetralux@users.noreply.github.com> Date: Wed, 16 Jan 2019 17:07:43 +0000 Subject: [PATCH 1/2] Fix printing IR of integer as a pointer with endianness. When converting an integer value into a pointer and writing out the IR for it in 'ir_print_exact_value', 'is_type_integer_endian_{little,big}' did not correct handle being asked about pointer types. They now reply with whether the endianness of 'uintptr' matches the endianness being asked about. --- src/types.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types.cpp b/src/types.cpp index eb850fa66..52c06ef71 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1041,6 +1041,8 @@ bool is_type_integer_endian_big(Type *t) { return build_context.endian_kind == TargetEndian_Big; } else if (t->kind == Type_BitSet) { return is_type_integer_endian_big(bit_set_to_int(t)); + } else if (t->kind == Type_Pointer) { + return is_type_integer_endian_big(&basic_types[Basic_uintptr]); } else { GB_PANIC("Unsupported type: %s", type_to_string(t)); } @@ -1058,6 +1060,8 @@ bool is_type_integer_endian_little(Type *t) { return build_context.endian_kind == TargetEndian_Little; } else if (t->kind == Type_BitSet) { return is_type_integer_endian_little(bit_set_to_int(t)); + } else if (t->kind == Type_Pointer) { + return is_type_integer_endian_little(&basic_types[Basic_uintptr]); } else { GB_PANIC("Unsupported type: %s", type_to_string(t)); } From be1a3488a443641d3108326c14df5685279be9de Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 18 Jan 2019 13:24:40 +0100 Subject: [PATCH 2/2] Initial support for GetVersionExA --- core/os/os_windows.odin | 35 +++++++++++++++++++++++++++++ core/sys/win32/general.odin | 16 ++++++++++++++ core/sys/win32/kernel32.odin | 43 ++++++++++++++++++------------------ 3 files changed, 73 insertions(+), 21 deletions(-) diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin index 2fec6b845..9618f83be 100644 --- a/core/os/os_windows.odin +++ b/core/os/os_windows.odin @@ -287,4 +287,39 @@ _alloc_command_line_arguments :: proc() -> []string { return arg_list; } +get_windows_version_ansi :: proc() -> win32.OS_Version_Info_Ex_A { + osvi : win32.OS_Version_Info_Ex_A; + osvi.os_version_info_size = size_of(win32.OS_Version_Info_Ex_A); + win32.get_version(&osvi); + return osvi; +} +is_windows_xp :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 5 && osvi.minor_version == 1); +} + +is_windows_vista :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 6 && osvi.minor_version == 0); +} + +is_windows_7 :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 6 && osvi.minor_version == 1); +} + +is_windows_8 :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 6 && osvi.minor_version == 2); +} + +is_windows_8_1 :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 6 && osvi.minor_version == 3); +} + +is_windows_10 :: proc() -> bool { + osvi := get_windows_version_ansi(); + return (osvi.major_version == 10 && osvi.minor_version == 0); +} \ No newline at end of file diff --git a/core/sys/win32/general.odin b/core/sys/win32/general.odin index c7e79860a..c34294b51 100644 --- a/core/sys/win32/general.odin +++ b/core/sys/win32/general.odin @@ -298,6 +298,22 @@ File_Notify_Information :: struct { file_name: [1]u16, } + +// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_osversioninfoexa +OS_Version_Info_Ex_A :: struct { + os_version_info_size: u32, + major_version: u32, + minor_version: u32, + build_number: u32, + platform_id : u32, + service_pack_string: [128]u8, + service_pack_major: u16, + service_pack_minor: u16, + suite_mask: u16, + product_type: u8, + reserved: u8 +} + MAPVK_VK_TO_VSC :: 0; MAPVK_VSC_TO_VK :: 1; MAPVK_VK_TO_CHAR :: 2; diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin index 7163bc662..a41fe32de 100644 --- a/core/sys/win32/kernel32.odin +++ b/core/sys/win32/kernel32.odin @@ -5,38 +5,39 @@ foreign import "system:kernel32.lib" @(default_calling_convention = "std") foreign kernel32 { - @(link_name="GetLastError") get_last_error :: proc() -> i32 ---; - @(link_name="CreateProcessA") create_process_a :: proc(application_name, command_line: cstring, + @(link_name="GetLastError") get_last_error :: proc() -> i32 ---; + @(link_name="CreateProcessA") create_process_a :: proc(application_name, command_line: cstring, process_attributes, thread_attributes: ^Security_Attributes, inherit_handle: Bool, creation_flags: u32, environment: rawptr, current_direcotry: cstring, startup_info: ^Startup_Info, process_information: ^Process_Information) -> Bool ---; - @(link_name="CreateProcessW") create_process_w :: proc(application_name, command_line: Wstring, + @(link_name="CreateProcessW") create_process_w :: proc(application_name, command_line: Wstring, process_attributes, thread_attributes: ^Security_Attributes, inherit_handle: Bool, creation_flags: u32, environment: rawptr, current_direcotry: cstring, startup_info: ^Startup_Info, process_information: ^Process_Information) -> Bool ---; - @(link_name="GetExitCodeProcess") get_exit_code_process :: proc(process: Handle, exit: ^u32) -> Bool ---; - @(link_name="ExitProcess") exit_process :: proc(exit_code: u32) ---; - @(link_name="GetModuleHandleA") get_module_handle_a :: proc(module_name: cstring) -> Hinstance ---; - @(link_name="GetModuleHandleW") get_module_handle_w :: proc(module_name: Wstring) -> Hinstance ---; - @(link_name="Sleep") sleep :: proc(ms: i32) -> i32 ---; - @(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc(result: ^i64) -> i32 ---; - @(link_name="QueryPerformanceCounter") query_performance_counter :: proc(result: ^i64) -> i32 ---; - @(link_name="OutputDebugStringA") output_debug_string_a :: proc(c_str: cstring) ---; + @(link_name="GetExitCodeProcess") get_exit_code_process :: proc(process: Handle, exit: ^u32) -> Bool ---; + @(link_name="ExitProcess") exit_process :: proc(exit_code: u32) ---; + @(link_name="GetModuleHandleA") get_module_handle_a :: proc(module_name: cstring) -> Hinstance ---; + @(link_name="GetModuleHandleW") get_module_handle_w :: proc(module_name: Wstring) -> Hinstance ---; + @(link_name="Sleep") sleep :: proc(ms: i32) -> i32 ---; + @(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc(result: ^i64) -> i32 ---; + @(link_name="QueryPerformanceCounter") query_performance_counter :: proc(result: ^i64) -> i32 ---; + @(link_name="OutputDebugStringA") output_debug_string_a :: proc(c_str: cstring) ---; - @(link_name="GetCommandLineA") get_command_line_a :: proc() -> cstring ---; - @(link_name="GetCommandLineW") get_command_line_w :: proc() -> Wstring ---; - @(link_name="GetSystemMetrics") get_system_metrics :: proc(index: i32) -> i32 ---; - @(link_name="GetCurrentThreadId") get_current_thread_id :: proc() -> u32 ---; + @(link_name="GetCommandLineA") get_command_line_a :: proc() -> cstring ---; + @(link_name="GetCommandLineW") get_command_line_w :: proc() -> Wstring ---; + @(link_name="GetSystemMetrics") get_system_metrics :: proc(index: i32) -> i32 ---; + @(link_name="GetVersionExA") get_version :: proc(osvi: ^OS_Version_Info_Ex_A) ---; + @(link_name="GetCurrentThreadId") get_current_thread_id :: proc() -> u32 ---; - @(link_name="GetSystemTimeAsFileTime") get_system_time_as_file_time :: proc(system_time_as_file_time: ^Filetime) ---; - @(link_name="FileTimeToLocalFileTime") file_time_to_local_file_time :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool ---; - @(link_name="FileTimeToSystemTime") file_time_to_system_time :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool ---; - @(link_name="SystemTimeToFileTime") system_time_to_file_time :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool ---; + @(link_name="GetSystemTimeAsFileTime") get_system_time_as_file_time :: proc(system_time_as_file_time: ^Filetime) ---; + @(link_name="FileTimeToLocalFileTime") file_time_to_local_file_time :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool ---; + @(link_name="FileTimeToSystemTime") file_time_to_system_time :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool ---; + @(link_name="SystemTimeToFileTime") system_time_to_file_time :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool ---; - @(link_name="CloseHandle") close_handle :: proc(h: Handle) -> i32 ---; - @(link_name="GetStdHandle") get_std_handle :: proc(h: i32) -> Handle ---; + @(link_name="CloseHandle") close_handle :: proc(h: Handle) -> i32 ---; + @(link_name="GetStdHandle") get_std_handle :: proc(h: i32) -> Handle ---; @(link_name="CreateFileA") create_file_a :: proc(filename: cstring, desired_access, share_module: u32,