From 8e724128e8233c1e0addef8f0860e33194bd9ab9 Mon Sep 17 00:00:00 2001 From: Iavael Date: Sun, 12 Jan 2014 09:26:41 +0400 Subject: [PATCH] Revert "Use anonymous file instead of regular file to back mmap" This reverts commit 935d8169b8e3570f1a5e726c5295be2f460c1540, because two anonymous mappings would have different content, while they must have the same one. --- tccrun.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tccrun.c b/tccrun.c index 97f4761b..b07ab0f4 100644 --- a/tccrun.c +++ b/tccrun.c @@ -59,18 +59,25 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) return ret; #ifdef HAVE_SELINUX - { /* Use mmap instead of malloc for 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); s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + MAP_SHARED, fd, 0); if (s1->write_mem == MAP_FAILED) - tcc_error("mmap not writeable"); + tcc_error("/tmp not writeable"); s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + MAP_SHARED, fd, 0); if (s1->runtime_mem == MAP_FAILED) - tcc_error("mmap not executable"); + tcc_error("/tmp not executable"); ret = tcc_relocate_ex(s1, s1->write_mem); }