aboutsummaryrefslogtreecommitdiff
path: root/tccrun.c
diff options
context:
space:
mode:
authorIavael <iavaelooeyt@gmail.com>2014-01-12 09:26:41 +0400
committerIavael <iavaelooeyt@gmail.com>2014-01-12 09:29:30 +0400
commit8e724128e8233c1e0addef8f0860e33194bd9ab9 (patch)
treefcf306e6b7c33a8935cf96235b1085fa2d7dac55 /tccrun.c
parentf42a02efda42bad2937f60c5ad98b028ddc2a581 (diff)
downloadtinycc-8e724128e8233c1e0addef8f0860e33194bd9ab9.tar.gz
tinycc-8e724128e8233c1e0addef8f0860e33194bd9ab9.tar.bz2
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.
Diffstat (limited to 'tccrun.c')
-rw-r--r--tccrun.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/tccrun.c b/tccrun.c
index 97f4761..b07ab0f 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);
}