Minor update to clangformat file. (#694)
This commit is contained in:
committed by
GitHub
parent
45dbdb00af
commit
69e280c331
@@ -91,6 +91,7 @@ PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace snmalloc
|
||||
|
||||
public:
|
||||
constexpr Buddy() = default;
|
||||
|
||||
/**
|
||||
* Add a block to the buddy allocator.
|
||||
*
|
||||
|
||||
@@ -159,4 +159,5 @@ namespace snmalloc
|
||||
}
|
||||
}
|
||||
} // namespace snmalloc
|
||||
|
||||
#include "../mem/remotecache.h"
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace snmalloc
|
||||
static constexpr Contents root = nullptr;
|
||||
|
||||
static constexpr address_t MASK = 1;
|
||||
|
||||
static void set(Handle ptr, Contents r)
|
||||
{
|
||||
SNMALLOC_ASSERT((address_cast(r) & MASK) == 0);
|
||||
|
||||
@@ -92,7 +92,9 @@ namespace snmalloc
|
||||
{}
|
||||
|
||||
void set_owner() {}
|
||||
|
||||
void clear_owner() {}
|
||||
|
||||
void assert_not_owned_by_current_thread() {}
|
||||
};
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ namespace snmalloc
|
||||
*/
|
||||
template<typename Fn>
|
||||
struct function_ref;
|
||||
|
||||
template<typename R, typename... Args>
|
||||
struct function_ref<R(Args...)>
|
||||
{
|
||||
|
||||
@@ -137,6 +137,7 @@ namespace snmalloc
|
||||
{
|
||||
return ptr != t.ptr;
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
bool is_null()
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace snmalloc
|
||||
{
|
||||
char data[Size];
|
||||
};
|
||||
|
||||
auto* d = static_cast<Block*>(dst);
|
||||
auto* s = static_cast<const Block*>(src);
|
||||
*d = *s;
|
||||
@@ -254,6 +255,7 @@ namespace snmalloc
|
||||
{
|
||||
void* p[2];
|
||||
};
|
||||
|
||||
if (sizeof(Ptr2) <= len)
|
||||
{
|
||||
auto dp = static_cast<Ptr2*>(dst);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# include "sizeclasstable.h"
|
||||
|
||||
# include <cstddef>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace snmalloc
|
||||
*/
|
||||
using BackendSlabMetadata = typename Config::Backend::SlabMetadata;
|
||||
using PagemapEntry = typename Config::PagemapEntry;
|
||||
|
||||
/// }@
|
||||
|
||||
/**
|
||||
@@ -197,6 +198,7 @@ namespace snmalloc
|
||||
{
|
||||
capptr::AllocFull<PreAllocObject> next;
|
||||
};
|
||||
|
||||
// The following code implements Sattolo's algorithm for generating
|
||||
// random cyclic permutations. This implementation is in the opposite
|
||||
// direction, so that the original space does not need initialising.
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace snmalloc::external_alloc
|
||||
}
|
||||
# elif defined(__APPLE__)
|
||||
# include <malloc/malloc.h>
|
||||
|
||||
namespace snmalloc::external_alloc
|
||||
{
|
||||
inline size_t malloc_usable_size(void* ptr)
|
||||
@@ -30,6 +31,7 @@ namespace snmalloc::external_alloc
|
||||
}
|
||||
# elif defined(__linux__) || defined(__HAIKU__)
|
||||
# include <malloc.h>
|
||||
|
||||
namespace snmalloc::external_alloc
|
||||
{
|
||||
using ::malloc_usable_size;
|
||||
@@ -41,6 +43,7 @@ namespace snmalloc::external_alloc
|
||||
}
|
||||
# elif defined(__FreeBSD__)
|
||||
# include <malloc_np.h>
|
||||
|
||||
namespace snmalloc::external_alloc
|
||||
{
|
||||
using ::malloc_usable_size;
|
||||
|
||||
@@ -528,6 +528,7 @@ namespace snmalloc
|
||||
|
||||
protected:
|
||||
constexpr Prev(address_t prev) : prev(prev) {}
|
||||
|
||||
constexpr Prev() = default;
|
||||
|
||||
address_t replace(address_t next)
|
||||
@@ -570,10 +571,12 @@ namespace snmalloc
|
||||
struct KeyTweak
|
||||
{
|
||||
address_t key_tweak = 0;
|
||||
|
||||
SNMALLOC_FAST_PATH address_t get()
|
||||
{
|
||||
return key_tweak;
|
||||
}
|
||||
|
||||
void set(address_t kt)
|
||||
{
|
||||
key_tweak = kt;
|
||||
@@ -588,6 +591,7 @@ namespace snmalloc
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set(address_t) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <utility>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
enum Boundary
|
||||
|
||||
@@ -189,6 +189,7 @@ namespace snmalloc
|
||||
{
|
||||
return meta &= ~META_BOUNDARY_BIT;
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string.h>
|
||||
|
||||
using namespace snmalloc;
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
@@ -88,7 +89,9 @@ extern "C"
|
||||
// statistics on fork if built with statistics.
|
||||
|
||||
SNMALLOC_EXPORT SNMALLOC_USED_FUNCTION inline void _malloc_prefork(void) {}
|
||||
|
||||
SNMALLOC_EXPORT SNMALLOC_USED_FUNCTION inline void _malloc_postfork(void) {}
|
||||
|
||||
SNMALLOC_EXPORT SNMALLOC_USED_FUNCTION inline void _malloc_first_thread(void)
|
||||
{}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Malloc extensions
|
||||
*
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
extern "C" ssize_t __sys_writev(int fd, const struct iovec* iov, int iovcnt);
|
||||
extern "C" int __sys_fsync(int fd);
|
||||
|
||||
/// @}
|
||||
|
||||
namespace snmalloc
|
||||
@@ -57,6 +58,7 @@ namespace snmalloc
|
||||
static constexpr size_t address_bits = (Aal::bits == 32) ?
|
||||
Aal::address_bits :
|
||||
(Aal::aal_name == RISCV ? 38 : Aal::address_bits);
|
||||
|
||||
// TODO, if we ever backport to MIPS, this should yield 39 there.
|
||||
|
||||
/**
|
||||
|
||||
@@ -172,6 +172,7 @@ namespace snmalloc
|
||||
uint64_t result;
|
||||
char buffer[sizeof(uint64_t)];
|
||||
};
|
||||
|
||||
ssize_t ret;
|
||||
|
||||
// give a try to SYS_getrandom
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
extern "C" ssize_t _sys_writev(int fd, const struct iovec* iov, int iovcnt);
|
||||
extern "C" int _sys_fsync(int fd);
|
||||
|
||||
/// @}
|
||||
|
||||
namespace snmalloc
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace snmalloc
|
||||
UNUSED(str);
|
||||
oe_abort();
|
||||
}
|
||||
|
||||
static constexpr size_t address_bits = Aal::address_bits;
|
||||
static constexpr size_t page_size = Aal::smallest_page_size;
|
||||
};
|
||||
|
||||
@@ -407,6 +407,7 @@ namespace snmalloc
|
||||
uint64_t result;
|
||||
char buffer[sizeof(uint64_t)];
|
||||
};
|
||||
|
||||
ssize_t ret;
|
||||
int flags = O_RDONLY;
|
||||
#if defined(O_CLOEXEC)
|
||||
|
||||
@@ -238,6 +238,7 @@ namespace snmalloc
|
||||
|
||||
# ifdef PLATFORM_HAS_WAITONADDRESS
|
||||
using WaitingWord = char;
|
||||
|
||||
template<class T>
|
||||
static void wait_on_address(std::atomic<T>& addr, T expected)
|
||||
{
|
||||
@@ -247,11 +248,13 @@ namespace snmalloc
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void notify_one_on_address(std::atomic<T>& addr)
|
||||
{
|
||||
::WakeByAddressSingle(&addr);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void notify_all_on_address(std::atomic<T>& addr)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace snmalloc
|
||||
using Alloc = snmalloc::LocalAllocator<snmalloc::StandardConfigClientMeta<
|
||||
ArrayClientMetaDataProvider<std::atomic<size_t>>>>;
|
||||
}
|
||||
|
||||
#define SNMALLOC_PROVIDE_OWN_CONFIG
|
||||
#include <snmalloc/snmalloc.h>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ int main()
|
||||
|
||||
// Specify type of allocator
|
||||
# define SNMALLOC_PROVIDE_OWN_CONFIG
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
class CustomConfig : public CommonConfig
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace snmalloc
|
||||
using Alloc = snmalloc::LocalAllocator<snmalloc::StandardConfigClientMeta<
|
||||
ArrayClientMetaDataProvider<std::atomic<size_t>>>>;
|
||||
}
|
||||
|
||||
# define SNMALLOC_PROVIDE_OWN_CONFIG
|
||||
# include <snmalloc/snmalloc.h>
|
||||
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
|
||||
using namespace snmalloc;
|
||||
static constexpr size_t GRANULARITY_BITS = 20;
|
||||
|
||||
struct T
|
||||
{
|
||||
size_t v = 99;
|
||||
|
||||
T(size_t v) : v(v) {}
|
||||
|
||||
T() {}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,28 +22,36 @@ struct NodeRef
|
||||
static constexpr size_t offset = 10000;
|
||||
|
||||
size_t* ptr;
|
||||
|
||||
constexpr NodeRef(size_t* p) : ptr(p) {}
|
||||
|
||||
constexpr NodeRef() : ptr(nullptr) {}
|
||||
|
||||
constexpr NodeRef(const NodeRef& other) : ptr(other.ptr) {}
|
||||
|
||||
constexpr NodeRef(NodeRef&& other) : ptr(other.ptr) {}
|
||||
|
||||
bool operator!=(const NodeRef& other) const
|
||||
{
|
||||
return ptr != other.ptr;
|
||||
}
|
||||
|
||||
NodeRef& operator=(const NodeRef& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void set(uint16_t val)
|
||||
{
|
||||
*ptr = ((size_t(val) + offset) << 1) + (*ptr & 1);
|
||||
}
|
||||
|
||||
explicit operator uint16_t()
|
||||
{
|
||||
return uint16_t((*ptr >> 1) - offset);
|
||||
}
|
||||
|
||||
explicit operator size_t*()
|
||||
{
|
||||
return ptr;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace
|
||||
{
|
||||
SNMALLOC_CHECK(0 && "Should never be called!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox class. Allocates a memory region and an allocator that can
|
||||
* allocate into this from the outside.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
// Specify type of allocator
|
||||
#define SNMALLOC_PROVIDE_OWN_CONFIG
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
using CustomGlobals = FixedRangeConfig<PALNoAlloc<DefaultPal>>;
|
||||
|
||||
@@ -30,6 +30,7 @@ extern "C" void* enclave_malloc(size_t);
|
||||
extern "C" void enclave_free(void*);
|
||||
|
||||
using namespace snmalloc;
|
||||
|
||||
int main()
|
||||
{
|
||||
setup();
|
||||
|
||||
@@ -46,10 +46,12 @@ void chatty(const char* p, ...)
|
||||
struct MyAlloc
|
||||
{
|
||||
MyAlloc() {}
|
||||
|
||||
void* alloc(size_t sz)
|
||||
{
|
||||
return malloc(sz);
|
||||
}
|
||||
|
||||
void dealloc(void* p)
|
||||
{
|
||||
free(p);
|
||||
@@ -59,11 +61,14 @@ struct MyAlloc
|
||||
struct MyAlloc
|
||||
{
|
||||
snmalloc::Alloc& a;
|
||||
|
||||
MyAlloc() : a(ThreadAlloc::get()) {}
|
||||
|
||||
void* alloc(size_t sz)
|
||||
{
|
||||
return a.alloc(sz);
|
||||
}
|
||||
|
||||
void dealloc(void* p)
|
||||
{
|
||||
a.dealloc(p);
|
||||
|
||||
@@ -97,12 +97,14 @@ void setup()
|
||||
}
|
||||
# else
|
||||
# include <signal.h>
|
||||
|
||||
void error_handle(int signal)
|
||||
{
|
||||
snmalloc::UNUSED(signal);
|
||||
snmalloc::error("Seg Fault");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
signal(SIGSEGV, error_handle);
|
||||
|
||||
Reference in New Issue
Block a user