From ea16aa384747fa66abf234f0156981f6b736c929 Mon Sep 17 00:00:00 2001 From: Tri11Paragon Date: Thu, 31 Oct 2024 19:28:43 -0700 Subject: [PATCH] fixes for windows --- include/blt/std/allocator.h | 5 ++++- include/blt/std/memory_util.h | 2 +- include/blt/std/mmap.h | 4 ++++ include/blt/std/system.h | 2 +- libraries/parallel-hashmap | 2 +- src/blt/std/assert.cpp | 24 ++++++++++++++---------- src/blt/std/mmap.cpp | 9 +++++++++ src/blt/std/system.cpp | 2 +- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/include/blt/std/allocator.h b/include/blt/std/allocator.h index 873c0e4..03e466e 100644 --- a/include/blt/std/allocator.h +++ b/include/blt/std/allocator.h @@ -546,6 +546,7 @@ namespace blt template static inline T* allocate_huge_page(blt::size_t BLOCK_SIZE, blt::size_t HUGE_PAGE_SIZE = BLT_2MB_SIZE) { +#ifdef __unix__ BLT_ASSERT((BLOCK_SIZE & (HUGE_PAGE_SIZE - 1)) == 0 && "Must be multiple of the huge page size!"); T* buffer = static_cast(mmap(nullptr, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0)); @@ -578,6 +579,8 @@ namespace blt BLT_ERROR("Offset by %ld pages, resulting: %p", (reinterpret_cast(buffer) - ptr_size) / 4096, buffer); } return buffer; +#endif + return malloc(BLOCK_SIZE); } /** @@ -701,7 +704,7 @@ namespace blt } else buffer = reinterpret_cast(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE)); #else - buffer = reinterpret_cast(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE)); + buffer = static_cast(_aligned_malloc(BLOCK_SIZE, BLOCK_SIZE)); #endif construct(buffer); #ifndef BLT_DISABLE_STATS diff --git a/include/blt/std/memory_util.h b/include/blt/std/memory_util.h index 6344b11..0985253 100644 --- a/include/blt/std/memory_util.h +++ b/include/blt/std/memory_util.h @@ -28,7 +28,7 @@ #if defined(__clang__) || defined(__llvm__) || defined(__GNUC__) || defined(__GNUG__) - #if defined(__GNUC__) || defined(__GNUG__) + #if (defined(__GNUC__) || defined(__GNUG__)) && !defined(WIN32) #include diff --git a/include/blt/std/mmap.h b/include/blt/std/mmap.h index 01dac95..e1b7810 100644 --- a/include/blt/std/mmap.h +++ b/include/blt/std/mmap.h @@ -95,7 +95,11 @@ namespace blt public: void* allocate(blt::size_t bytes) // NOLINT { +#ifdef WIN32 + return _aligned_malloc(bytes, BLT_2MB_SIZE); +#else return std::aligned_alloc(BLT_2MB_SIZE, bytes); +#endif } void deallocate(void* ptr, blt::size_t) // NOLINT diff --git a/include/blt/std/system.h b/include/blt/std/system.h index 106a214..3225830 100644 --- a/include/blt/std/system.h +++ b/include/blt/std/system.h @@ -146,7 +146,7 @@ namespace blt::system std::uint64_t dt; }; -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(WIN32) using suseconds_t = std::size_t; #endif diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 4817a6d..2d0b499 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 4817a6d3b8407063cf0328eb92dbb27ee2f55528 +Subproject commit 2d0b499273ea02f7211ae2af705418c9509691fb diff --git a/src/blt/std/assert.cpp b/src/blt/std/assert.cpp index 3d03a23..64b5e80 100644 --- a/src/blt/std/assert.cpp +++ b/src/blt/std/assert.cpp @@ -13,7 +13,7 @@ #include #include -struct abort_exception : public std::exception +struct abort_exception final : public std::exception { public: explicit abort_exception(const char* what) @@ -42,14 +42,18 @@ struct abort_exception : public std::exception char* error{nullptr}; }; -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) && !defined(WIN32) + #define IS_GNU_BACKTRACE +#endif + +#ifdef IS_GNU_BACKTRACE #include #include #endif -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE #define BLT_STACK_TRACE(number) void* ptrs[number]; \ int size = backtrace(ptrs, number); \ char** messages = backtrace_symbols(ptrs, size); @@ -64,7 +68,7 @@ struct abort_exception : public std::exception namespace blt { -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE static inline std::string _macro_filename(const std::string& path) { @@ -79,7 +83,7 @@ namespace blt void b_throw(const char* what, const char* path, int line) { -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE BLT_STACK_TRACE(50); BLT_ERROR("An exception '%s' has occurred in file '%s:%d'", what, path, line); @@ -96,7 +100,7 @@ namespace blt void b_assert_failed(const char* expression, const char* msg, const char* path, int line) { -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE BLT_STACK_TRACE(50); BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line); @@ -122,7 +126,7 @@ namespace blt { if (messages == nullptr) return; -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE for (int i = 1; i < size; i++) { int tabs = i - 1; @@ -167,13 +171,13 @@ namespace blt void b_abort(const char* what, const char* path, int line) { -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) +#if IS_GNU_BACKTRACE BLT_STACK_TRACE(50); #endif BLT_FATAL("----{BLT ABORT}----"); BLT_FATAL("\tWhat: %s", what); - BLT_FATAL("\tcalled from %s:%d", path, line); -#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) + BLT_FATAL("\tCalled from %s:%d", path, line); +#if IS_GNU_BACKTRACE printStacktrace(messages, size, path, line); BLT_FREE_STACK_TRACE(); diff --git a/src/blt/std/mmap.cpp b/src/blt/std/mmap.cpp index 30a0f3b..ef7a978 100644 --- a/src/blt/std/mmap.cpp +++ b/src/blt/std/mmap.cpp @@ -21,6 +21,8 @@ #include +#else +#include #endif namespace blt @@ -99,16 +101,23 @@ namespace blt } return buffer; #else + (void)page_type; + (void)bytes; BLT_ABORT("Platform not supported for huge page allocation!"); #endif } void mmap_free(void* ptr, blt::size_t bytes) { +#ifdef __unix__ if (munmap(ptr, bytes)) { BLT_ERROR_STREAM << "Failed to deallocate\n"; throw bad_alloc_t(handle_mmap_error()); } +#else + (void)ptr; + (void)bytes; +#endif } } \ No newline at end of file diff --git a/src/blt/std/system.cpp b/src/blt/std/system.cpp index 060894a..546bac6 100644 --- a/src/blt/std/system.cpp +++ b/src/blt/std/system.cpp @@ -6,7 +6,7 @@ #include #include -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(WIN32) #include /* for struct timeval */ #include #else