Skip to content
Permalink
Browse files

Some code cleanup / simplification.

  • Loading branch information...
emeryberger committed Nov 29, 2018
1 parent 784d29a commit e52d3e0eee93262544f57b36bd6f9a506a4e52c9
Showing with 14 additions and 7 deletions.
  1. +13 −6 heaps/top/mmapheap.h
  2. +1 −1 wrappers/mmapwrapper.h
@@ -114,17 +114,24 @@ namespace HL {
static inline void * malloc (size_t sz) {
// Round up to the size of a page.
sz = (sz + CPUInfo::PageSize - 1) & (size_t) ~(CPUInfo::PageSize - 1);
void * addr = 0;
int flags = 0;
static int fd = -1;
#if defined(MAP_ALIGN) && defined(MAP_ANON)
// Request memory aligned to the Alignment value above.
void * ptr = mmap ((char *) Alignment, sz, HL_MMAP_PROTECTION_MASK, MAP_PRIVATE | MAP_ALIGN | MAP_ANON, -1, 0);
addr = Alignment;
flags |= MAP_PRIVATE | MAP_ALIGN | MAP_ANON;
#elif !defined(MAP_ANONYMOUS)
static int fd = ::open ("/dev/zero", O_RDWR);
void * ptr = mmap (NULL, sz, HL_MMAP_PROTECTION_MASK, MAP_PRIVATE, fd, 0);
if (fd == -1) {
fd = ::open ("/dev/zero", O_RDWR);
}
flags |= MAP_PRIVATE;
#else
void * ptr = mmap (NULL, sz, HL_MMAP_PROTECTION_MASK, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
flags |= MAP_PRIVATE | MAP_ANONYMOUS;
#endif

auto ptr = mmap (addr, sz, HL_MMAP_PROTECTION_MASK, flags, fd, 0);
if (ptr == MAP_FAILED) {
ptr = NULL;
ptr = nullptr;
}
return ptr;
}
@@ -158,7 +158,7 @@ namespace HL {
mapFlag |= MAP_ANONYMOUS | MAP_PRIVATE;
#endif

ptr = mmap (startAddress, sz, HL_MMAP_PROTECTION_MASK, mapFlag, fd, 0);
ptr = mmap(startAddress, sz, HL_MMAP_PROTECTION_MASK, mapFlag, fd, 0);

if (ptr == MAP_FAILED) {
return NULL;

0 comments on commit e52d3e0

Please sign in to comment.
You can’t perform that action at this time.