Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On aarch64, use PROT_MTE on arena mapping if MTE is enabled. #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string.h>
#include <sys/ipc.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <sys/shm.h>
#include <sys/syscall.h>
#include <unistd.h>
Expand Down Expand Up @@ -232,15 +233,22 @@ static void check_thp_state(void) {
void *alloc_arena_mmap(size_t page_size, bool use_thp, size_t arena_size, int fd) {
void *arena;
size_t pagemask = page_size - 1;
int prot = PROT_READ | PROT_WRITE;
int flags;

#ifdef __aarch64__
int tac = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
if (tac != -1 && (tac & PR_MTE_TCF_MASK))
prot |= PROT_MTE;
#endif

if (fd == -1)
flags = MAP_PRIVATE | MAP_ANONYMOUS | get_page_size_flags(page_size);
else
flags = MAP_SHARED;

arena_size = (arena_size + pagemask) & ~pagemask;
arena = mmap(0, arena_size, PROT_READ | PROT_WRITE, flags, fd, 0);
arena = mmap(0, arena_size, prot, flags, fd, 0);
if (arena == MAP_FAILED) {
perror("mmap");
exit(1);
Expand Down