On Thu, Apr 02, 2020 at 01:53:06PM +0200, KP Singh wrote: > > -int heap_mprotect(void) > +#define PAGE_SIZE 4096 > +#define GET_PAGE_ADDR(ADDR) \ > + (char *)(((unsigned long) ADDR) & ~(PAGE_SIZE-1)) > + > +int stack_mprotect(void) > { > + > void *buf; > long sz; > int ret; > @@ -25,12 +30,9 @@ int heap_mprotect(void) > if (sz < 0) > return sz; > > - buf = memalign(sz, 2 * sz); > - if (buf == NULL) > - return -ENOMEM; > - > - ret = mprotect(buf, sz, PROT_READ | PROT_WRITE | PROT_EXEC); > - free(buf); > + buf = alloca(PAGE_SIZE * 3); > + ret = mprotect(GET_PAGE_ADDR(buf + PAGE_SIZE), PAGE_SIZE, > + PROT_READ | PROT_WRITE | PROT_EXEC); Great. Something like this should work. Please use sysconf(_SC_PAGE_SIZE); like prog_tests/mmap.c does. selftests/bpf are run not only on x86