Make snmalloc build on Windows with Clang
Fixes a few places where Clang complains about Windows specific code, and also uses macros supported by Clang on Windows. A few places separating platform and compiler specific code, as MSVC and WIN32 were used interchangably previously.
This commit is contained in:
committed by
Matthew Parkinson
parent
eaeb2aa53d
commit
0affc069cf
@@ -97,7 +97,7 @@ namespace snmalloc
|
||||
# if defined(_MSC_VER) && defined(SNMALLOC_VA_BITS_64)
|
||||
return _InterlockedCompareExchange128(
|
||||
(volatile __int64*)&linked,
|
||||
expect.aba + 1,
|
||||
(__int64)(expect.aba + (uintptr_t)1),
|
||||
(__int64)value,
|
||||
(__int64*)&expect);
|
||||
# else
|
||||
|
||||
@@ -138,13 +138,16 @@ namespace snmalloc
|
||||
|
||||
inline size_t ctz(size_t x)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
#if __has_builtin(__builtin_ctzl)
|
||||
return static_cast<size_t>(__builtin_ctzl(x));
|
||||
#elif defined(_MSC_VER)
|
||||
# ifdef SNMALLOC_VA_BITS_64
|
||||
return _tzcnt_u64(x);
|
||||
# else
|
||||
return _tzcnt_u32((uint32_t)x);
|
||||
# endif
|
||||
#else
|
||||
// Probably GCC at this point.
|
||||
return static_cast<size_t>(__builtin_ctzl(x));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
# define ALWAYSINLINE __forceinline
|
||||
# define NOINLINE __declspec(noinline)
|
||||
# define likely(x) !!(x)
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace snmalloc
|
||||
using alloc_id_t = size_t;
|
||||
union
|
||||
{
|
||||
std::atomic<Remote*> next;
|
||||
Remote* non_atomic_next;
|
||||
std::atomic<Remote*> next = nullptr;
|
||||
};
|
||||
|
||||
alloc_id_t allocator_id;
|
||||
|
||||
@@ -200,11 +200,14 @@ namespace snmalloc
|
||||
// If we're on Windows 10 or newer, we can use the VirtualAlloc2
|
||||
// function. The FromApp variant is useable by UWP applications and
|
||||
// cannot allocate executable memory.
|
||||
MEM_ADDRESS_REQUIREMENTS addressReqs = {0};
|
||||
MEM_EXTENDED_PARAMETER param = {0};
|
||||
addressReqs.Alignment = align;
|
||||
param.Type = MemExtendedParameterAddressRequirements;
|
||||
MEM_ADDRESS_REQUIREMENTS addressReqs = {NULL, NULL, align};
|
||||
|
||||
MEM_EXTENDED_PARAMETER param = {
|
||||
{MemExtendedParameterAddressRequirements, 0}, {0}};
|
||||
// Separate assignment as MSVC doesn't support .Pointer in the
|
||||
// initialisation list.
|
||||
param.Pointer = &addressReqs;
|
||||
|
||||
void* ret = VirtualAlloc2FromApp(
|
||||
nullptr, nullptr, *size, flags, PAGE_READWRITE, ¶m, 1);
|
||||
if (ret == nullptr)
|
||||
|
||||
@@ -25,7 +25,7 @@ void print_stack_trace()
|
||||
{
|
||||
// SymInitialize failed
|
||||
error = GetLastError();
|
||||
printf("SymInitialize returned error : %d\n", error);
|
||||
printf("SymInitialize returned error : %lu\n", error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user