Broom 1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
platform.cc
Go to the documentation of this file.
1#if defined(__APPLE__)
2#include <pthread.h>
3#include <sys/mman.h>
4
5#include <format>
6#include <print>
7#include <utility>
8
10
11namespace broom {
12namespace platform {
13constexpr const int kInvalidFd = -1;
14
16
17void UnmapMemorySpace(const MemorySpace& space) {
18 BENSURE_EQ(munmap(space.StartPtr(), space.Size()), 0,
19 "Failed to unmap memory: {}", strerror(errno));
20}
21
23 switch (permissions) {
25 return PROT_READ;
27 return PROT_WRITE;
29 return PROT_READ | PROT_WRITE;
31 return 0;
32 }
33 ABORT("Unexpected permissions");
34}
35
37 return 0;
38}
39
43 flags |= MAP_ANON;
45 void* maybe_pointer = mmap(nullptr, space_size, prot, flags, kInvalidFd, 0);
46 BASSERT_NE(maybe_pointer, nullptr, "Unrecoverable mmap failure: {}",
48 return MemorySpace{maybe_pointer, space_size};
49}
50
51} // namespace platform
52} // namespace broom
53#endif
#define BASSERT_NE(lhs, rhs, m,...)
Definition macros.h:63
#define BROOM_UNUSED
Definition macros.h:109
#define BENSURE_EQ(lhs, rhs, m,...)
Definition macros.h:26
void * GetStackBottom()
void UnmapMemorySpace(const MemorySpace &space)
MemorySpace MapMemorySpace(size_t space_size, MemoryPermissions permissions=Allocator::kDefaultPermissions)
MemoryPermissions
Definition allocator.h:111
std::queue< T, broom::deque< T > > queue
Definition broom-queue.h:12
#define ABORT(m,...)