diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 1918272d..c94b21b1 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -63,6 +63,14 @@ endif() ########################################## +if(MINGW) + momo_add_c_and_cxx_compile_options( + -Wno-array-bounds + ) +endif() + +########################################## + if(LINUX) add_link_options( -Wl,--no-undefined diff --git a/src/backends/unicorn-emulator/unicorn.hpp b/src/backends/unicorn-emulator/unicorn.hpp index a129404c..c06ea4f6 100644 --- a/src/backends/unicorn-emulator/unicorn.hpp +++ b/src/backends/unicorn-emulator/unicorn.hpp @@ -10,7 +10,9 @@ #pragma GCC diagnostic ignored "-Wunused-function" #endif +#ifndef NOMINMAX #define NOMINMAX +#endif #include #ifdef __clang__ diff --git a/src/common/platform/compiler.hpp b/src/common/platform/compiler.hpp index 07fc82c2..4d051025 100644 --- a/src/common/platform/compiler.hpp +++ b/src/common/platform/compiler.hpp @@ -20,11 +20,13 @@ #endif #ifdef OS_WINDOWS -#define EXPORT_SYMBOL __declspec(dllexport) -#define IMPORT_SYMBOL __declspec(dllimport) -#define NO_INLINE __declspec(noinline) +#define EXPORT_SYMBOL __declspec(dllexport) +#define IMPORT_SYMBOL __declspec(dllimport) +#define NO_INLINE __declspec(noinline) +#ifndef DECLSPEC_ALIGN #define DECLSPEC_ALIGN(n) __declspec(align(n)) +#endif #define RESTRICTED_POINTER diff --git a/src/common/platform/file_management.hpp b/src/common/platform/file_management.hpp index 60097940..bf43b9d7 100644 --- a/src/common/platform/file_management.hpp +++ b/src/common/platform/file_management.hpp @@ -72,8 +72,10 @@ #define SL_RETURN_SINGLE_ENTRY 0x02 #define SL_NO_CURSOR_UPDATE 0x10 -#define SEC_IMAGE 0x01000000 -#define SEC_RESERVE 0x04000000 +#ifndef SEC_IMAGE +#define SEC_IMAGE 0x01000000 +#define SEC_RESERVE 0x04000000 +#endif typedef enum _FSINFOCLASS { diff --git a/src/common/platform/memory.hpp b/src/common/platform/memory.hpp index 8f6023cd..3ff99657 100644 --- a/src/common/platform/memory.hpp +++ b/src/common/platform/memory.hpp @@ -2,23 +2,24 @@ // NOLINTBEGIN(modernize-use-using) -#define PAGE_EXECUTE 0x10 -#define PAGE_EXECUTE_READ 0x20 -#define PAGE_EXECUTE_READWRITE 0x40 -#define PAGE_EXECUTE_WRITECOPY 0x80 +#define PAGE_EXECUTE 0x10 +#define PAGE_EXECUTE_READ 0x20 +#define PAGE_EXECUTE_READWRITE 0x40 +#define PAGE_EXECUTE_WRITECOPY 0x80 -#define PAGE_NOACCESS 0x01 -#define PAGE_READONLY 0x02 -#define PAGE_READWRITE 0x04 -#define PAGE_WRITECOPY 0x08 +#define PAGE_NOACCESS 0x01 +#define PAGE_READONLY 0x02 +#define PAGE_READWRITE 0x04 +#define PAGE_WRITECOPY 0x08 -#define PAGE_TARGETS_INVALID 0x40000000 -#define PAGE_TARGETS_NO_UPDATE 0x40000000 +#define PAGE_TARGETS_INVALID 0x40000000 +#define PAGE_TARGETS_NO_UPDATE 0x40000000 -#define PAGE_GUARD 0x100 -#define PAGE_NOCACHE 0x200 -#define PAGE_WRITECOMBINE 0x400 +#define PAGE_GUARD 0x100 +#define PAGE_NOCACHE 0x200 +#define PAGE_WRITECOMBINE 0x400 +#ifndef MEM_64K_PAGES #define MEM_COMMIT 0x00001000 #define MEM_RESERVE 0x00002000 #define MEM_DECOMMIT 0x00004000 @@ -37,6 +38,7 @@ #define MEM_DOS_LIM 0x40000000 #define MEM_4MB_PAGES 0x80000000 #define MEM_64K_PAGES (MEM_LARGE_PAGES | MEM_PHYSICAL) +#endif typedef enum _MEMORY_INFORMATION_CLASS { @@ -64,7 +66,11 @@ typedef enum _SECTION_INHERIT ViewUnmap = 2 } SECTION_INHERIT; -typedef struct DECLSPEC_ALIGN(16) _EMU_MEMORY_BASIC_INFORMATION64 +typedef struct +#ifndef __MINGW64__ + DECLSPEC_ALIGN(16) +#endif + _EMU_MEMORY_BASIC_INFORMATION64 { uint64_t BaseAddress; uint64_t AllocationBase; diff --git a/src/common/platform/platform.hpp b/src/common/platform/platform.hpp index 6e8dff89..fc4c1edf 100644 --- a/src/common/platform/platform.hpp +++ b/src/common/platform/platform.hpp @@ -1,6 +1,6 @@ #pragma once -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW64__) #pragma warning(push) #pragma warning(disable : 4201) // nameless struct/union #pragma warning(disable : 4702) // unreachable code @@ -31,6 +31,6 @@ #pragma GCC diagnostic pop #endif -#ifdef OS_WINDOWS +#if defined(_WIN32) && !defined(__MINGW64__) #pragma warning(pop) #endif diff --git a/src/common/platform/process.hpp b/src/common/platform/process.hpp index 0fc6adbb..1234f900 100644 --- a/src/common/platform/process.hpp +++ b/src/common/platform/process.hpp @@ -591,7 +591,11 @@ using NEON128 = struct _NEON128 LONGLONG High; }; -typedef struct DECLSPEC_ALIGN(16) _CONTEXT64 +typedef struct +#if !defined(__MINGW64__) + DECLSPEC_ALIGN(16) +#endif + _CONTEXT64 { DWORD64 P1Home; DWORD64 P2Home; diff --git a/src/samples/test-sample/CMakeLists.txt b/src/samples/test-sample/CMakeLists.txt index 918b772c..cba82b1e 100644 --- a/src/samples/test-sample/CMakeLists.txt +++ b/src/samples/test-sample/CMakeLists.txt @@ -8,7 +8,7 @@ list(SORT SRC_FILES) add_executable(test-sample ${SRC_FILES}) -if(MINGW) +if(WIN) target_link_libraries(test-sample PRIVATE ws2_32) endif() diff --git a/src/samples/test-sample/test.cpp b/src/samples/test-sample/test.cpp index a3ec47ca..6b5cdba6 100644 --- a/src/samples/test-sample/test.cpp +++ b/src/samples/test-sample/test.cpp @@ -9,7 +9,9 @@ #include #include +#ifndef NOMINMAX #define NOMINMAX +#endif #define WIN32_LEAN_AND_MEAN #include @@ -23,8 +25,6 @@ #include #endif -#pragma comment(lib, "ws2_32.lib") - using namespace std::literals; // Externally visible and potentially modifiable state @@ -570,8 +570,10 @@ namespace return false; } - if (sendto(sender, send_data.data(), static_cast(send_data.size()), 0, - reinterpret_cast(&destination), sizeof(destination)) != send_data.size()) + const auto sent_bytes = sendto(sender, send_data.data(), static_cast(send_data.size()), 0, + reinterpret_cast(&destination), sizeof(destination)); + + if (static_cast(sent_bytes) != send_data.size()) { puts("Failed to send data!"); return false; @@ -593,6 +595,7 @@ namespace return send_data == std::string_view(buffer, len); } +#ifndef __MINGW64__ void throw_access_violation() { if (do_the_task) @@ -601,7 +604,6 @@ namespace } } -#ifndef __MINGW64__ bool test_access_violation_exception() { __try diff --git a/src/windows-emulator/std_include.hpp b/src/windows-emulator/std_include.hpp index 05cf0d0b..4162beb2 100644 --- a/src/windows-emulator/std_include.hpp +++ b/src/windows-emulator/std_include.hpp @@ -1,36 +1,5 @@ #pragma once -#ifdef _WIN32 -#pragma warning(push) -#pragma warning(disable : 4005) -#pragma warning(disable : 4127) -#pragma warning(disable : 4201) -#pragma warning(disable : 4244) -#pragma warning(disable : 4245) -#pragma warning(disable : 4324) -#pragma warning(disable : 4458) -#pragma warning(disable : 4471) -#pragma warning(disable : 4505) -#pragma warning(disable : 4702) -#pragma warning(disable : 4996) -#pragma warning(disable : 5054) -#pragma warning(disable : 6011) -#pragma warning(disable : 6297) -#pragma warning(disable : 6385) -#pragma warning(disable : 6386) -#pragma warning(disable : 6387) -#pragma warning(disable : 26110) -#pragma warning(disable : 26451) -#pragma warning(disable : 26444) -#pragma warning(disable : 26451) -#pragma warning(disable : 26489) -#pragma warning(disable : 26495) -#pragma warning(disable : 26498) -#pragma warning(disable : 26812) -#pragma warning(disable : 28020) -#pragma warning(pop) -#endif - #include #include #include