aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkeren <keren@bluebird.(none)>2014-01-09 14:00:19 -0800
committerkeren <keren@bluebird.(none)>2014-01-09 14:00:19 -0800
commit935d8169b8e3570f1a5e726c5295be2f460c1540 (patch)
treec90e6add3ff189da6f32e41f803e561ff9e424b3
parent767410b8750b45d63805b45ca1a2cf34d7cb4923 (diff)
downloadtinycc-935d8169b8e3570f1a5e726c5295be2f460c1540.tar.gz
tinycc-935d8169b8e3570f1a5e726c5295be2f460c1540.tar.bz2
Use anonymous file instead of regular file to back mmap
Signed-off-by: Keren Tan <tankeren@gmail.com>
-rw-r--r--tccrun.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/tccrun.c b/tccrun.c
index b07ab0f..a53330f 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);
}