diff options
| author | Iavael <iavaelooeyt@gmail.com> | 2014-01-12 09:26:41 +0400 |
|---|---|---|
| committer | Iavael <iavaelooeyt@gmail.com> | 2014-01-12 09:29:30 +0400 |
| commit | 8e724128e8233c1e0addef8f0860e33194bd9ab9 (patch) | |
| tree | fcf306e6b7c33a8935cf96235b1085fa2d7dac55 /tccrun.c | |
| parent | f42a02efda42bad2937f60c5ad98b028ddc2a581 (diff) | |
| download | tinycc-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.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -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); } |
