Skip to content

Commit

Permalink
Fix I_HOLD_LOCK assertion violation in child process
Browse files Browse the repository at this point in the history
Issue #682 (bdwgc).

Update `GC_lock_holder` in `fork_child_proc()` as value of
`thread_id_self()` might differ from that of the parent process.

* include/private/gc_locks.h [(NN_PLATFORM_CTR || NINTENDO_SWITCH)
&& GC_ASSERTIONS] (SET_LOCK_HOLDER): Define macro (to no-op).
* pthread_support.c [CAN_HANDLE_FORK] (fork_child_proc): Call
`SET_LOCK_HOLDER()` at the beginning of function.
  • Loading branch information
ivmai committed Dec 12, 2024
1 parent bee3ff9 commit 25c2b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/private/gc_locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern void GC_lock(void);
extern void GC_unlock(void);
# define UNCOND_LOCK() GC_lock()
# define UNCOND_UNLOCK() GC_unlock()
# ifdef GC_ASSERTIONS
# define SET_LOCK_HOLDER() (void)0
# endif
# endif

# if (!defined(AO_HAVE_test_and_set_acquire) || defined(GC_WIN32_THREADS) \
Expand Down
5 changes: 5 additions & 0 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,11 @@ GC_ATTR_NO_SANITIZE_THREAD
static void
fork_child_proc(void)
{
# ifdef GC_ASSERTIONS
/* Update GC_lock_holder as value of thread_id_self() might */
/* differ from that of the parent process. */
SET_LOCK_HOLDER();
# endif
GC_release_dirty_lock();
# ifndef GC_DISABLE_INCREMENTAL
GC_dirty_update_child();
Expand Down

0 comments on commit 25c2b6a

Please sign in to comment.