Skip to content

Commit

Permalink
Use (anonymous) mmap() when available.
Browse files Browse the repository at this point in the history
Should fix #147 (SELinux related segfault)
  • Loading branch information
ngrewe committed Feb 12, 2020
1 parent bfc0b9a commit 0e84e31
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions block_to_imp.c
Expand Up @@ -82,8 +82,11 @@ static int mprotect(void *buffer, size_t len, int prot)

return 0 != VirtualProtect(buffer, len, newProt, &oldProt);
}
#endif // _WIN32

#else
# ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS MAP_ANON
# endif
#endif

#define PAGE_SIZE 4096

Expand Down Expand Up @@ -163,7 +166,7 @@ static struct trampoline_set *alloc_trampolines(char *start, char *end)
#if _WIN32
metadata->buffers = VirtualAlloc(NULL, sizeof(struct trampoline_buffers), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
#else
posix_memalign((void **)&metadata->buffers, getpagesize(), sizeof(struct trampoline_buffers));
metadata->buffers = mmap(NULL, sizeof(struct trampoline_buffers), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
#endif
for (int i=0 ; i<HEADERS_PER_PAGE ; i++)
{
Expand Down

0 comments on commit 0e84e31

Please sign in to comment.