From 2c1ae2ea45bd662c74a15b9e1d68be845d366783 Mon Sep 17 00:00:00 2001 From: Greg Steuck Date: Tue, 22 Nov 2022 22:49:34 -0800 Subject: Remove OpenBSD uthreads (GC_OPENBSD_UTHREADS) support Issue #512 (bdwgc). Userland threads were replaced by rthreads on OpenBSD about a decade ago. Prior to OpenBSD 5.2 release (2012), the OS had user threads and required special handling. * include/private/gc_priv.h [GC_OPENBSD_THREADS && !GC_USESIGRT_SIGNALS] (SIG_SUSPEND): Do not check GC_OPENBSD_UTHREADS (assume not defined). * include/private/gcconfig.h [OPENBSD] (NEED_FIND_LIMIT): Likewise. * include/private/gcconfig.h [PTHREAD_STOP_WORLD_IMPL && !NACL] (SIGNAL_BASED_STOP_WORLD): Likewise. * os_dep.c [OPENBSD] (GC_register_data_segments): Likewise. * pthread_stop_world.c (GC_usleep, GC_suspend_all, GC_stop_world, GC_start_world, GC_stop_init): Likewise. * tests/initfromthread.c (main): Likewise. * include/private/gcconfig.h [GC_OPENBSD_THREADS && OpenBSD<201211] (GC_OPENBSD_UTHREADS): Do not define. * os_dep.c [OPENBSD && GC_OPENBSD_UTHREADS]: Do not include sys/syscall.h. * os_dep.c [OPENBSD && GC_OPENBSD_UTHREADS] (__syscall): Do not declare. * os_dep.c [OPENBSD && GC_OPENBSD_UTHREADS] (GC_find_limit_openbsd): Remove. * os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS] (GC_find_limit_with_bound): Move comment from GC_find_limit_openbsd. * pthread_stop_world.c [!NACL && GC_OPENBSD_UTHREADS]: Do not include pthread_np.h. Co-authored-by: Kurt Miller --- os_dep.c | 65 +++++----------------------------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) (limited to 'os_dep.c') diff --git a/os_dep.c b/os_dep.c index 8e140836..42b0fa06 100644 --- a/os_dep.c +++ b/os_dep.c @@ -524,60 +524,6 @@ GC_INNER const char * GC_get_maps(void) LONGJMP(GC_jmp_buf_openbsd, 1); } -# ifdef GC_OPENBSD_UTHREADS -# include - EXTERN_C_BEGIN - extern sigset_t __syscall(quad_t, ...); - EXTERN_C_END - - /* Don't use GC_find_limit() because siglongjmp() outside of the */ - /* signal handler by-passes our userland pthreads lib, leaving */ - /* SIGSEGV and SIGPROF masked. Instead, use this custom one that */ - /* works-around the issues. */ - - /* Return the first non-addressable location > p or bound. */ - STATIC ptr_t GC_find_limit_openbsd(ptr_t p, ptr_t bound) - { - static volatile ptr_t result; - /* Safer if static, since otherwise it may not be */ - /* preserved across the longjmp. Can safely be */ - /* static since it's only called with the */ - /* allocation lock held. */ - - struct sigaction act; - word pgsz = (word)sysconf(_SC_PAGESIZE); - - GC_ASSERT((word)bound >= pgsz); - GC_ASSERT(I_HOLD_LOCK()); - - act.sa_handler = GC_fault_handler_openbsd; - sigemptyset(&act.sa_mask); - act.sa_flags = SA_NODEFER | SA_RESTART; - /* act.sa_restorer is deprecated and should not be initialized. */ - sigaction(SIGSEGV, &act, &old_segv_act); - - if (SETJMP(GC_jmp_buf_openbsd) == 0) { - result = (ptr_t)((word)p & ~(pgsz-1)); - for (;;) { - if ((word)result >= (word)bound - pgsz) { - result = bound; - break; - } - result += pgsz; /* no overflow expected */ - GC_noop1((word)(*result)); - } - } - -# ifdef THREADS - /* Due to the siglongjump we need to manually unmask SIGPROF. */ - __syscall(SYS_sigprocmask, SIG_UNBLOCK, sigmask(SIGPROF)); -# endif - - sigaction(SIGSEGV, &old_segv_act, 0); - return result; - } -# endif /* GC_OPENBSD_UTHREADS */ - static volatile int firstpass; /* Return first addressable location > p or bound. */ @@ -995,7 +941,10 @@ GC_INNER size_t GC_page_size = 0; STATIC ptr_t GC_find_limit_with_bound(ptr_t p, GC_bool up, ptr_t bound) { static volatile ptr_t result; - /* Safer if static, see that in GC_find_limit_openbsd. */ + /* Safer if static, since otherwise it may not be */ + /* preserved across the longjmp. Can safely be */ + /* static since it's only called with the */ + /* allocation lock held. */ GC_ASSERT(up ? (word)bound >= MIN_PAGE_SIZE : (word)bound <= ~(word)MIN_PAGE_SIZE); @@ -2091,11 +2040,7 @@ void GC_register_data_segments(void) ABORT_ARG2("Wrong DATASTART/END pair", ": %p .. %p", (void *)region_start, (void *)DATAEND); for (;;) { -# ifdef GC_OPENBSD_UTHREADS - ptr_t region_end = GC_find_limit_openbsd(region_start, DATAEND); -# else - ptr_t region_end = GC_find_limit_with_bound(region_start, TRUE, DATAEND); -# endif + ptr_t region_end = GC_find_limit_with_bound(region_start, TRUE, DATAEND); GC_add_roots_inner(region_start, region_end, FALSE); if ((word)region_end >= (word)DATAEND) -- cgit v1.2.1