-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix recursive malloc during pthread_create (E2K)
(fix of commit 9ddbbae) Issue #411 (bdwgc). Use of malloc/free inside an asynchronous signal is not safe and may lead to a crash inside malloc, e.g. if the signal occurs when malloc is called from pthread_create. Also, malloc cannot be used by the code executed during stop-the-world if the collector is built with enabled malloc redirection. This commit replaces malloc/free used to get procedure (register) stack with alloca or GC_INTERNAL_MALLOC (the latter is not used during stop-the-world). This commit also prevents accessing freed procedure stack buffers from GC_push_all_stacks when the world is not stopped. * include/private/gc_priv.h [E2K] (GC_get_procedure_stack): Change the arguments to accept buf and its size; update the comment. * include/private/gc_priv.h [E2K] (PROCEDURE_STACK_ALLOCA_AND_STORE): Define macro. * include/private/gc_priv.h [E2K && THREADS] (GC_alloc_and_get_procedure_stack): New function declaration. * include/private/pthread_support.h [E2K || IA64] (GC_Thread_Rep.backing_store_end): Add comment. * mach_dep.c [E2K] (GC_get_procedure_stack): Change the implementation to according to the updated declaration (do allocate the buffer internally); remove FIXME. * mach_dep.c [E2K && THREADS] (GC_alloc_and_get_procedure_stack): Implement. * mark_rts.c [!THREADS] (GC_push_current_stack): Use PROCEDURE_STACK_ALLOCA_AND_STORE() instead of GC_get_procedure_stack(); do no call free(). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && E2K] (GC_push_all_stacks): Likewise. * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && E2K] (GC_store_stack_ptr): Do not declare bs_lo and stack_size local variables; do not call GC_get_procedure_stack(). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && E2K] (GC_suspend_handler_inner): Declare bs_lo and stack_size local variables; call PROCEDURE_STACK_ALLOCA_AND_STORE(); set backing_store_end and backing_store_ptr fields of me (and clear these fields before function return); do not call free(). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && E2K] (GC_push_all_stacks): Define is_stopped local variable; move stack_size local variable declaration to the innermost scope (where it is used); do not call GC_push_all_register_sections() if the procedure stack buffer has been already freed. * pthread_support.c (first_thread): Update comment; move upper to be before GC_push_thread_structures. * pthread_support.c [E2K] (GC_push_thread_structures): Push also first_thread.backing_store_end. * pthread_support.c [E2K] (GC_do_blocking_inner, GC_call_with_gc_active): Do no declare bs_lo local variable; call GC_alloc_and_get_procedure_stack (holding the lock) instead of GC_get_procedure_stack; call GC_INTERNAL_FREE() instead of free(); update comment.
- Loading branch information
Showing
6 changed files
with
134 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.