mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
Use anonymous file instead of regular file to back mmap
Signed-off-by: Keren Tan <tankeren@gmail.com>
This commit is contained in:
parent
767410b875
commit
935d8169b8
19
tccrun.c
19
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user