| @@ -37,12 +37,33 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr); · 36 unmodified lines |
| 37 | 37 | int tcc_relocate(TCCState *s1) |
| 38 | 38 | { |
| 39 | 39 | int ret; |
| 40 | | − |
| 40 | +#ifdef HAVE_SELINUX |
| 41 | + char tmpfname[] = "/tmp/.tccrunXXXXXX"; |
| 42 | + int fd = mkstemp (tmpfname); |
| 43 | + unlink (tmpfname); ftruncate (fd, 1000); |
| 44 | + if ((ret= tcc_relocate_ex(s1,NULL)) < 0)return -1; |
| 45 | + s1->mem_size=ret; |
| 46 | + /* Use mmap instead of malloc for Selinux */ |
| 47 | + s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE, |
| 48 | + MAP_SHARED, fd, 0); |
| 49 | + if(s1->write_mem == MAP_FAILED){ |
| 50 | + error("/tmp not writeable"); |
| 51 | + return -1; |
| 52 | + } |
| 53 | + s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC, |
| 54 | + MAP_SHARED, fd, 0); |
| 55 | + if(s1->runtime_mem == MAP_FAILED){ |
| 56 | + error("/tmp not executable"); |
| 57 | + return -1; |
| 58 | + } |
| 59 | + ret = tcc_relocate_ex(s1, s1->write_mem); |
| 60 | +#else |
| 41 | 61 | ret = tcc_relocate_ex(s1, NULL); |
| 42 | 62 | if (-1 != ret) { |
| 43 | 63 | s1->runtime_mem = tcc_malloc(ret); |
| 44 | 64 | ret = tcc_relocate_ex(s1, s1->runtime_mem); |
| 45 | 65 | } |
| 66 | +#endif |
| 46 | 67 | return ret; |
| 47 | 68 | } |
| 48 | 69 | |
| @@ -50,34 +71,10 @@ int tcc_relocate(TCCState *s1) · 1 unmodified line |
| 50 | 71 | int tcc_run(TCCState *s1, int argc, char **argv) |
| 51 | 72 | { |
| 52 | 73 | int (*prog_main)(int, char **); |
| 53 | | − int ret; |
| 54 | | −#ifdef HAVE_SELINUX |
| 55 | | − int rret; |
| 56 | | − void *ptr,*writep; |
| 57 | | − char tmpfname[] = "/tmp/.tccrunXXXXXX"; |
| 58 | | − int fd = mkstemp (tmpfname); |
| 59 | | − unlink (tmpfname); |
| 60 | | − ftruncate (fd, 1000); |
| 61 | | − if ((rret= tcc_relocate_ex(s1,NULL)) < 0) |
| 62 | | − return -1; |
| 63 | | − /* Use mmap instead of malloc for Selinux */ |
| 64 | | − writep = mmap (NULL, rret, PROT_READ|PROT_WRITE, |
| 65 | | − MAP_SHARED, fd, 0); |
| 66 | | − if(writep == MAP_FAILED){ |
| 67 | | − error("/tmp not writeable"); |
| 68 | | − return -1; |
| 69 | | − } |
| 70 | | − ptr = mmap (NULL, rret, PROT_READ|PROT_EXEC, |
| 71 | | − MAP_SHARED, fd, 0); |
| 72 | | − if(ptr == MAP_FAILED){ |
| 73 | | − error("/tmp not executable"); |
| 74 | | − return -1; |
| 75 | | − } |
| 76 | | − tcc_relocate_ex(s1, writep); |
| 77 | | −#else |
| 74 | + |
| 78 | 75 | if (tcc_relocate(s1) < 0) |
| 79 | 76 | return -1; |
| 80 | | −#endif |
| 77 | + |
| 81 | 78 | prog_main = tcc_get_symbol_err(s1, "main"); |
| 82 | 79 | |
| 83 | 80 | #ifdef CONFIG_TCC_BACKTRACE |
| @@ -89,6 +86,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines |
| 89 | 86 | if (s1->do_bounds_check) { |
| 90 | 87 | void (*bound_init)(void); |
| 91 | 88 | void (*bound_exit)(void); |
| 89 | + int ret; |
| 92 | 90 | /* set error function */ |
| 93 | 91 | rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg"); |
| 94 | 92 | rt_prog_main = prog_main; |
| @@ -108,13 +106,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 13 unmodified lines |
| 108 | 106 | if (p) *p = 0; |
| 109 | 107 | } |
| 110 | 108 | #endif |
| 111 | | − ret=(*prog_main)(argc, argv); |
| 112 | | −#ifdef HAVE_SELINUX |
| 113 | | − munmap (writep, rret); |
| 114 | | − munmap (ptr, rret); |
| 115 | | − |
| 116 | | −#endif |
| 117 | | − return ret; |
| 109 | + return (*prog_main)(argc, argv); |
| 118 | 110 | } |
| 119 | 111 | |
| 120 | 112 | |