fixes for windows

v2
Tri11Paragon 2024-10-31 19:28:43 -07:00
parent e81f590f5e
commit ea16aa3847
8 changed files with 35 additions and 15 deletions

View File

@ -546,6 +546,7 @@ namespace blt
template<typename T, bool WARN_ON_FAIL = false> template<typename T, bool WARN_ON_FAIL = false>
static inline T* allocate_huge_page(blt::size_t BLOCK_SIZE, blt::size_t HUGE_PAGE_SIZE = BLT_2MB_SIZE) 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!"); BLT_ASSERT((BLOCK_SIZE & (HUGE_PAGE_SIZE - 1)) == 0 && "Must be multiple of the huge page size!");
T* buffer = static_cast<T*>(mmap(nullptr, BLOCK_SIZE, PROT_READ | PROT_WRITE, T* buffer = static_cast<T*>(mmap(nullptr, BLOCK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0)); 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<blt::size_t>(buffer) - ptr_size) / 4096, buffer); BLT_ERROR("Offset by %ld pages, resulting: %p", (reinterpret_cast<blt::size_t>(buffer) - ptr_size) / 4096, buffer);
} }
return buffer; return buffer;
#endif
return malloc(BLOCK_SIZE);
} }
/** /**
@ -701,7 +704,7 @@ namespace blt
} else } else
buffer = reinterpret_cast<block*>(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE)); buffer = reinterpret_cast<block*>(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE));
#else #else
buffer = reinterpret_cast<block*>(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE)); buffer = static_cast<block*>(_aligned_malloc(BLOCK_SIZE, BLOCK_SIZE));
#endif #endif
construct(buffer); construct(buffer);
#ifndef BLT_DISABLE_STATS #ifndef BLT_DISABLE_STATS

View File

@ -28,7 +28,7 @@
#if defined(__clang__) || defined(__llvm__) || defined(__GNUC__) || defined(__GNUG__) #if defined(__clang__) || defined(__llvm__) || defined(__GNUC__) || defined(__GNUG__)
#if defined(__GNUC__) || defined(__GNUG__) #if (defined(__GNUC__) || defined(__GNUG__)) && !defined(WIN32)
#include <byteswap.h> #include <byteswap.h>

View File

@ -95,7 +95,11 @@ namespace blt
public: public:
void* allocate(blt::size_t bytes) // NOLINT 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); return std::aligned_alloc(BLT_2MB_SIZE, bytes);
#endif
} }
void deallocate(void* ptr, blt::size_t) // NOLINT void deallocate(void* ptr, blt::size_t) // NOLINT

View File

@ -146,7 +146,7 @@ namespace blt::system
std::uint64_t dt; std::uint64_t dt;
}; };
#ifdef _MSC_VER #if defined(_MSC_VER) || defined(WIN32)
using suseconds_t = std::size_t; using suseconds_t = std::size_t;
#endif #endif

@ -1 +1 @@
Subproject commit 4817a6d3b8407063cf0328eb92dbb27ee2f55528 Subproject commit 2d0b499273ea02f7211ae2af705418c9509691fb

View File

@ -13,7 +13,7 @@
#include <exception> #include <exception>
#include <cstring> #include <cstring>
struct abort_exception : public std::exception struct abort_exception final : public std::exception
{ {
public: public:
explicit abort_exception(const char* what) explicit abort_exception(const char* what)
@ -42,14 +42,18 @@ struct abort_exception : public std::exception
char* error{nullptr}; 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 <execinfo.h> #include <execinfo.h>
#include <cstdlib> #include <cstdlib>
#endif #endif
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #if IS_GNU_BACKTRACE
#define BLT_STACK_TRACE(number) void* ptrs[number]; \ #define BLT_STACK_TRACE(number) void* ptrs[number]; \
int size = backtrace(ptrs, number); \ int size = backtrace(ptrs, number); \
char** messages = backtrace_symbols(ptrs, size); char** messages = backtrace_symbols(ptrs, size);
@ -64,7 +68,7 @@ struct abort_exception : public std::exception
namespace blt namespace blt
{ {
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #if IS_GNU_BACKTRACE
static inline std::string _macro_filename(const std::string& path) 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) 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_STACK_TRACE(50);
BLT_ERROR("An exception '%s' has occurred in file '%s:%d'", what, path, line); 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) 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_STACK_TRACE(50);
BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line); BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line);
@ -122,7 +126,7 @@ namespace blt
{ {
if (messages == nullptr) if (messages == nullptr)
return; return;
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #if IS_GNU_BACKTRACE
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
{ {
int tabs = i - 1; int tabs = i - 1;
@ -167,13 +171,13 @@ namespace blt
void b_abort(const char* what, const char* path, int line) void b_abort(const char* what, const char* path, int line)
{ {
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #if IS_GNU_BACKTRACE
BLT_STACK_TRACE(50); BLT_STACK_TRACE(50);
#endif #endif
BLT_FATAL("----{BLT ABORT}----"); BLT_FATAL("----{BLT ABORT}----");
BLT_FATAL("\tWhat: %s", what); BLT_FATAL("\tWhat: %s", what);
BLT_FATAL("\tcalled from %s:%d", path, line); BLT_FATAL("\tCalled from %s:%d", path, line);
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #if IS_GNU_BACKTRACE
printStacktrace(messages, size, path, line); printStacktrace(messages, size, path, line);
BLT_FREE_STACK_TRACE(); BLT_FREE_STACK_TRACE();

View File

@ -21,6 +21,8 @@
#include <sys/mman.h> #include <sys/mman.h>
#else
#include <blt/std/assert.h>
#endif #endif
namespace blt namespace blt
@ -99,16 +101,23 @@ namespace blt
} }
return buffer; return buffer;
#else #else
(void)page_type;
(void)bytes;
BLT_ABORT("Platform not supported for huge page allocation!"); BLT_ABORT("Platform not supported for huge page allocation!");
#endif #endif
} }
void mmap_free(void* ptr, blt::size_t bytes) void mmap_free(void* ptr, blt::size_t bytes)
{ {
#ifdef __unix__
if (munmap(ptr, bytes)) if (munmap(ptr, bytes))
{ {
BLT_ERROR_STREAM << "Failed to deallocate\n"; BLT_ERROR_STREAM << "Failed to deallocate\n";
throw bad_alloc_t(handle_mmap_error()); throw bad_alloc_t(handle_mmap_error());
} }
#else
(void)ptr;
(void)bytes;
#endif
} }
} }

View File

@ -6,7 +6,7 @@
#include <blt/std/system.h> #include <blt/std/system.h>
#include <blt/std/logging.h> #include <blt/std/logging.h>
#ifndef _MSC_VER #if !defined(_MSC_VER) && !defined(WIN32)
#include <sys/time.h> /* for struct timeval */ #include <sys/time.h> /* for struct timeval */
#include <sys/resource.h> #include <sys/resource.h>
#else #else