From 935d8169b8e3570f1a5e726c5295be2f460c1540 Mon Sep 17 00:00:00 2001 From: keren Date: Thu, 9 Jan 2014 14:00:19 -0800 Subject: [PATCH] Use anonymous file instead of regular file to back mmap Signed-off-by: Keren Tan --- tccrun.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tccrun.c b/tccrun.c index b07ab0f4..a53330f5 100644 --- a/tccrun.c +++ b/tccrun.c @@ -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); }