Skip to content

Instantly share code, notes, and snippets.

@lattera
Created June 21, 2019 20:30
Show Gist options
  • Save lattera/c3e41bca2527426c31a9d9174990c620 to your computer and use it in GitHub Desktop.
Save lattera/c3e41bca2527426c31a9d9174990c620 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
int
main(int argc, char *argv[])
{
void *addr;
addr = mmap(NULL, getpagesize(),
PROT_MAX(PROT_READ|PROT_WRITE|PROT_EXEC) | PROT_READ |
PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
printf("addr: 0x%016lx\n", (unsigned long)addr);
if (mprotect(addr, getpagesize(), PROT_READ|PROT_EXEC))
perror("mprotect");
while (printf("%d\n", getpid()))
sleep(5);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment