History

make --with-selinux work with libtcc, too

Henry Kroll III committed 16 years ago

Commit 2ab42851 parent a4ed5873 files · +35 −34Browse files

Unified · Split

3 files
  1. libtcc.c +5 −0
  2. tcc.h +4 −0
  3. tccrun.c +26 −34
libtcc.c+5−0
@@ -1038,7 +1038,12 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 1037 unmodified lines
1038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);1038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
1039 1039
1040 tcc_free(s1->tcc_lib_path);1040 tcc_free(s1->tcc_lib_path);
1041#ifdef HAVE_SELINUX
1042 munmap (s1->write_mem, s1->mem_size);
1043 munmap (s1->runtime_mem, s1->mem_size);
1044#else
1041 tcc_free(s1->runtime_mem);1045 tcc_free(s1->runtime_mem);
1046#endif
1042 tcc_free(s1);1047 tcc_free(s1);
1043}1048}
1044 1049
tcc.h+4−0
@@ -521,6 +521,10 @@ struct TCCState { · 520 unmodified lines
521 /* for tcc_relocate */521 /* for tcc_relocate */
522 int runtime_added;522 int runtime_added;
523 void *runtime_mem;523 void *runtime_mem;
524#ifdef HAVE_SELINUX
525 void *write_mem;
526 unsigned long mem_size;
527#endif
524 528
525 struct InlineFunc **inline_fns;529 struct InlineFunc **inline_fns;
526 int nb_inline_fns;530 int nb_inline_fns;
tccrun.c+26−34
@@ -37,12 +37,33 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr); · 36 unmodified lines
37int tcc_relocate(TCCState *s1)37int tcc_relocate(TCCState *s1)
38{38{
39 int ret;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 ret = tcc_relocate_ex(s1, NULL);61 ret = tcc_relocate_ex(s1, NULL);
42 if (-1 != ret) {62 if (-1 != ret) {
43 s1->runtime_mem = tcc_malloc(ret);63 s1->runtime_mem = tcc_malloc(ret);
44 ret = tcc_relocate_ex(s1, s1->runtime_mem);64 ret = tcc_relocate_ex(s1, s1->runtime_mem);
45 }65 }
66#endif
46 return ret;67 return ret;
47}68}
48 69
@@ -50,34 +71,10 @@ int tcc_relocate(TCCState *s1) · 1 unmodified line
50int tcc_run(TCCState *s1, int argc, char **argv)71int tcc_run(TCCState *s1, int argc, char **argv)
51{72{
52 int (*prog_main)(int, char **);73 int (*prog_main)(int, char **);
53 int ret;74
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
78 if (tcc_relocate(s1) < 0)75 if (tcc_relocate(s1) < 0)
79 return -1;76 return -1;
80#endif77
81 prog_main = tcc_get_symbol_err(s1, "main");78 prog_main = tcc_get_symbol_err(s1, "main");
82 79
83#ifdef CONFIG_TCC_BACKTRACE80#ifdef CONFIG_TCC_BACKTRACE
@@ -89,6 +86,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines
89 if (s1->do_bounds_check) {86 if (s1->do_bounds_check) {
90 void (*bound_init)(void);87 void (*bound_init)(void);
91 void (*bound_exit)(void);88 void (*bound_exit)(void);
89 int ret;
92 /* set error function */90 /* set error function */
93 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");91 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
94 rt_prog_main = prog_main;92 rt_prog_main = prog_main;
@@ -108,13 +106,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 13 unmodified lines
108 if (p) *p = 0;106 if (p) *p = 0;
109 }107 }
110#endif108#endif
111 ret=(*prog_main)(argc, argv);109 return (*prog_main)(argc, argv);
112#ifdef HAVE_SELINUX
113 munmap (writep, rret);
114 munmap (ptr, rret);
115
116#endif
117 return ret;
118}110}
119 111
120 112

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t