ivmai / bdwgc

The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (bdwgc, also known as bdw-gc, boehm-gc, libgc)

Home Page:https://www.hboehm.info/gc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getcontext fail with EFAULT on E2K

ivmai opened this issue · comments

Source: master (92abef5)
Host: Linux 5.4.0-6.9-e8c2 / e2k-v5
Occurrence: ~1/30

Not observed on release-8_2.

How to reproduce (after the modification of code, see below):
gcc -I include -I libatomic_ops/src -D GC_THREADS -D GC_ASSERTIONS -O0 -g -o gctest tests/gctest.c extra/gc.c -lpthread -ldl
while :; do ./gctest; done

Output:
GC Warning: getcontext failed: using another register retrieval method...

Instrument the source code (to abort on getcontext instead of warning):

diff --git a/mach_dep.c b/mach_dep.c
index b51f4f66..8ec8be8e 100644
--- a/mach_dep.c
+++ b/mach_dep.c
@@ -345,6 +345,7 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
         if (getcontext(&ctxt) < 0) {
           WARN("getcontext failed:"
                " using another register retrieval method...\n", 0);
+         abort();
           /* getcontext() is broken, do not try again.          */
           /* E.g., to workaround a bug in Docker ubuntu_32bit.  */
         } else {

Note: when reproducing this case, please ignore other gctest failures.

getcontext() implementation in E2K (which returns EFAULT in some cases):
https://github.com/OpenE2K/linux/blob/linux-5.4.193-mcst/arch/e2k/fast_syscalls/protected.c#L274