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(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
2 defined(__DragonFly__)
3
4#include <errno.h>
5#include <pthread.h>
6#include <string.h>
7#include <sys/mman.h>
8
9#include "src/globals.h"
10#include "src/macros.h"
12
13namespace broom {
14namespace platform {
15// Some platforms require the file descriptor to be -1, even when
16// MAP_ANONYMOUS/MAP_ANON is specified.
17constexpr const int kInvalidFd = -1;
18
19void UnmapMemorySpace(const MemorySpace& space) {
20 BENSURE_EQ(munmap(space.StartPtr(), space.Size()), 0,
21 "Failed to unmap memory: {}", strerror(errno));
22}
23
25 switch (permissions) {
27 return PROT_READ;
29 return PROT_WRITE;
31 return PROT_READ | PROT_WRITE;
33 return 0;
34 }
35 ABORT("Unexpected permissions");
36}
37
39 return 0;
40}
41
45 flags |= MAP_ANON;
47 void* maybe_pointer = mmap(nullptr, space_size, prot, flags, kInvalidFd, 0);
48 return MemorySpace{maybe_pointer, space_size};
49}
50} // namespace platform
51} // namespace broom
52#endif
#define BROOM_UNUSED
Definition macros.h:109
#define BENSURE_EQ(lhs, rhs, m,...)
Definition macros.h:26
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,...)