Page MenuHomeFreeBSD
Paste P319

Masterwork From Distant Lands
ActivePublic

Authored by markj on Sep 24 2019, 9:15 PM.
Tags
None
Referenced Files
F5295600: raw.txt
Sep 24 2019, 9:15 PM
Subscribers
None
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int
main(int argc, char **argv)
{
char template[PATH_MAX];
void *addr;
size_t sz;
int fd;
sz = 16 * 4096;
(void)snprintf(template, sizeof(template), "test.XXXXXX");
fd = mkstemp(template);
if (fd < 0)
err(1, "mkostemp");
if (fchmod(fd, 0700) < 0)
err(1, "fchmod");
if (ftruncate(fd, sz) < 0)
err(1, "ftruncate");
addr = mmap(NULL, sz, PROT_MAX(PROT_READ) | PROT_READ, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED)
err(1, "mmap");
if (mlock(addr, sz) != 0)
err(1, "mlock");
if (ftruncate(fd, 0) != 0)
err(1, "ftruncate");
if (ftruncate(fd, sz) != 0)
err(1, "ftruncate");
(void)close(fd);
fd = open(template, O_EXEC);
if (fd < 0)
err(1, "open");
fexecve(fd, argv, NULL);
err(1, "fexecve");
return (0);
}

Event Timeline

markj changed the title of this paste from untitled to Masterwork From Distant Lands.