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
10381038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
10391039
10401040 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
10411045 tcc_free(s1->runtime_mem);
1046+#endif
10421047 tcc_free(s1);
10431048 }
10441049
tcc.h+4−0
@@ -521,6 +521,10 @@ struct TCCState { · 520 unmodified lines
521521 /* for tcc_relocate */
522522 int runtime_added;
523523 void *runtime_mem;
524+#ifdef HAVE_SELINUX
525+ void *write_mem;
526+ unsigned long mem_size;
527+#endif
524528
525529 struct InlineFunc **inline_fns;
526530 int nb_inline_fns;
tccrun.c+26−34
@@ -37,12 +37,33 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr); · 36 unmodified lines
3737 int tcc_relocate(TCCState *s1)
3838 {
3939 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
4161 ret = tcc_relocate_ex(s1, NULL);
4262 if (-1 != ret) {
4363 s1->runtime_mem = tcc_malloc(ret);
4464 ret = tcc_relocate_ex(s1, s1->runtime_mem);
4565 }
66+#endif
4667 return ret;
4768 }
4869
@@ -50,34 +71,10 @@ int tcc_relocate(TCCState *s1) · 1 unmodified line
5071 int tcc_run(TCCState *s1, int argc, char **argv)
5172 {
5273 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+
7875 if (tcc_relocate(s1) < 0)
7976 return -1;
80−#endif
77+
8178 prog_main = tcc_get_symbol_err(s1, "main");
8279
8380 #ifdef CONFIG_TCC_BACKTRACE
@@ -89,6 +86,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines
8986 if (s1->do_bounds_check) {
9087 void (*bound_init)(void);
9188 void (*bound_exit)(void);
89+ int ret;
9290 /* set error function */
9391 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
9492 rt_prog_main = prog_main;
@@ -108,13 +106,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 13 unmodified lines
108106 if (p) *p = 0;
109107 }
110108 #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);
118110 }
119111
120112

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