From 9027a0b429ad3f2f3f0eb77210f22c4a1d21ee4a Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 19 Jan 2022 22:07:41 +0300 Subject: Support malloc redirection on E2K (single-threaded mode only) Issue #413 (bdwgc). * include/private/gc_priv.h [E2K_USE_SCRATCH] (GC_e2k_ps_buffer, GC_e2k_ps_capacity): Define macro. * include/private/gcconfig.h [E2K && LINUX && REDIRECT_MALLOC && !GC_LINUX_THREADS] (E2K_USE_SCRATCH): Likewise. * include/private/gc_priv.h [E2K_USE_SCRATCH] (_GC_arrays): Add _e2k_ps_buffer and _e2k_ps_capacity fields; add comment. * include/private/gcconfig.h [E2K && LINUX && REDIRECT_MALLOC && GC_LINUX_THREADS && !CPPCHECK]: Issue an error directive. * mach_dep.c [E2K && E2K_USE_SCRATCH] (GC_free_procedure_stack): Do not call free(); assert that buf is non-null but GC_e2k_ps_buffer is null; set GC_e2k_ps_buffer to buf. * mach_dep.c [E2K && E2K_USE_SCRATCH] (GC_get_procedure_stack): Initialize buf local variable to GC_e2k_ps_buffer; initialize buf_sz local variable to GC_e2k_ps_capacity; clear GC_e2k_ps_buffer value; change FIXME item to TODO one; pass buf to GC_scratch_recycle_no_gww() instead of free(); call GC_scratch_alloc() instead of malloc(). * mach_dep.c [E2K && LOG_E2K_ALLOCS] (GC_get_procedure_stack): Call GC_log_printf() to print buf_sz, new_sz and GC_gc_no values if errno is ENOMEM. * mach_dep.c [E2K] (GC_get_procedure_stack): Ensure buf_sz (word)GC_e2k_ps_capacity); + GC_scratch_recycle_no_gww(buf, GC_e2k_ps_capacity); + buf = GC_scratch_alloc((size_t)new_sz); + GC_e2k_ps_capacity = (size_t)new_sz; + /* TODO: support malloc redirection if multi-threaded */ +# else + free(buf); + buf = malloc((size_t)new_sz); +# endif if (NULL == buf) ABORT_ARG1("Could not allocate memory for procedure stack", ", %lu bytes requested", (unsigned long)new_sz); @@ -100,13 +127,13 @@ get_stack_index(&ps); } - if (buf_sz != new_sz) + if (buf_sz < new_sz) ABORT_ARG2("Buffer size mismatch while reading procedure stack", ": buf_sz= %lu, new_sz= %lu", (unsigned long)buf_sz, (unsigned long)new_sz); GC_ASSERT(buf != NULL); *buf_ptr = buf; - return (size_t)buf_sz; + return (size_t)new_sz; } ptr_t GC_save_regs_in_stack(void) { -- cgit v1.2.1