Use anonymous file instead of regular file to back mmap

Signed-off-by: Keren Tan <tankeren@gmail.com>
master
keren 2014-01-09 14:00:19 -08:00
parent 767410b875
commit 935d8169b8
1 changed files with 5 additions and 14 deletions

View File

@ -59,25 +59,16 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
return ret;
#ifdef HAVE_SELINUX
{ /* Use mmap instead of malloc for Selinux. Ref:
http://www.gnu.org/s/libc/manual/html_node/File-Size.html */
char tmpfname[] = "/tmp/.tccrunXXXXXX";
int fd = mkstemp (tmpfname);
s1->mem_size = ret;
unlink (tmpfname);
ftruncate (fd, s1->mem_size);
{ /* Use mmap instead of malloc for Selinux. */
s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (s1->write_mem == MAP_FAILED)
tcc_error("/tmp not writeable");
tcc_error("mmap not writeable");
s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC,
MAP_SHARED, fd, 0);
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (s1->runtime_mem == MAP_FAILED)
tcc_error("/tmp not executable");
tcc_error("mmap not executable");
ret = tcc_relocate_ex(s1, s1->write_mem);
}