Hello,

I have recently added code to redirect fork/sigaction to the bound checking
code. I also implemented limited thread local storage support.

See also commit Fix boundschecking for signal/sigaction/fork <https://repo.or.cz/tinycc.git/commit/853a498f2c234b41b8b2e7dacb371e9cec947b43>

The radare2 project (https://github.com/radareorg/radare2) has very high
load for fork/sigaction and bound checking failed.
For bound checking and tcc to work I had to do patches and sent them to a
maintainer for the radare2 project. The patches I sent probably need some
review and are not present in the radare2 git repository yet.
After the above commit and the changes to radare2 project to compile
with "tcc -b" the result was the same as compiled with gcc.

The implementation of thread local storage is just enough to link the
gcc compiled code of bcheck.c on i386/x86_64. It does not mean that
thread local storage is now supported and static linking still fails.

There is still one problem. fork() is not compatible with -run and SELINUX.
You can see this when doing:
tcc -b -run tests/tests2/114_bound_signal.c

The problem is that MAP_SHARED is used. This means the parent and child
still share the same memory after fork().
The patch below fixes this.
Can I apply this patch or is there a better solution?

        Herman


diff --git a/tccrun.c b/tccrun.c
index 17f1eeb..7057e44 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -88,8 +88,12 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
     unlink(tmpfname);
     ftruncate(fd, size);

+#if 0 /* does not work with fork */
     ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
     prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
+#else
+    ptr = prx = mmap (NULL, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, fd, 0);
+#endif
     if (ptr == MAP_FAILED || prx == MAP_FAILED)
        tcc_error("tccrun: could not map memory");
     dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size);
diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
index f7f4791..93e4062 100644
--- a/tests/tests2/Makefile
+++ b/tests/tests2/Makefile
@@ -94,7 +94,6 @@ GEN-ALWAYS =
     ./a.exe

 114_bound_signal.test: FLAGS += -b
-114_bound_signal.test: NORUN = true # tcc -run does not support fork and -b and SELINUX
 115_bound_setjmp.test: FLAGS += -b
 116_bound_setjmp2.test: FLAGS += -b
 117_builtins.test: T1 = ( $(TCC) -run $1 && $(TCC) -b -run $1 )

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to