diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-02-02 01:12:43 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-02-04 00:29:23 +0300 |
commit | 73b67bab7ecc943abd2e3253a26127212442833a (patch) | |
tree | 75de90140f8c78edb5637ebb38a73e4bf74705d0 /mach_dep.c | |
parent | 6c8923eef141c0de98d369af5ab270caa7d51b67 (diff) | |
download | bdwgc-73b67bab7ecc943abd2e3253a26127212442833a.tar.gz |
Use mmap to allocate procedure stack buffers on E2K
(fix of commit 990dcdba1)
Issue #411 (bdwgc).
This commit prevents stack overflow in case of a big procedure stack
to be saved.
If a procedure stack requires less than 1 memory page for the buffer,
then the buffer is still allocated on the local stack.
* include/private/gc_priv.h [E2K] (PS_ALLOCA_BUF, ALLOCA_SAFE_LIMIT,
FREE_PROCEDURE_STACK_LOCAL): Define macro.
* include/private/gc_priv.h [E2K] (PROCEDURE_STACK_ALLOCA_AND_STORE):
Rename to GET_PROCEDURE_STACK_LOCAL; update comment; modify
implementation to call GC_mmap_procedure_stack_buf (and
GC_unmap_procedure_stack_buf) if size > ALLOCA_SAFE_LIMIT.
* include/private/gc_priv.h [E2K] (GC_mmap_procedure_stack_buf,
GC_unmap_procedure_stack_buf): Declare function.
* include/private/gc_priv.h [E2K && THREADS]
(GC_alloc_and_get_procedure_stack): Refine comment.
* mach_dep.c [E2K]: Include sys/mman.h.
* mach_dep.c [E2K] (GC_mmap_procedure_stack_buf,
GC_unmap_procedure_stack_buf): Implement.
* mark_rts.c [E2K && !THREADS] (GC_push_current_stack): Rename
PROCEDURE_STACK_ALLOCA_AND_STORE to GET_PROCEDURE_STACK_LOCAL; call
FREE_PROCEDURE_STACK_LOCAL() when bs_lo is not needed.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && E2K]
(GC_suspend_handler_inner, GC_push_all_stacks): Likewise.
Diffstat (limited to 'mach_dep.c')
-rw-r--r-- | mach_dep.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -28,9 +28,9 @@ #ifdef E2K # include <errno.h> -# include <sys/syscall.h> - # include <asm/e2k_syswork.h> +# include <sys/mman.h> +# include <sys/syscall.h> # define VA_SIZE 48 # define E2K_PSHTP_SIZE 12 @@ -103,6 +103,24 @@ return NULL; } + GC_INNER ptr_t GC_mmap_procedure_stack_buf(size_t aligned_sz) + { + void *buf = mmap(NULL, aligned_sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, 0 /* fd */, 0 /* offset */); + if (MAP_FAILED == buf) + ABORT_ARG2("Could not map memory for procedure stack", + ": requested %lu bytes, errno= %d", + (unsigned long)aligned_sz, errno); + return (ptr_t)buf; + } + + GC_INNER void GC_unmap_procedure_stack_buf(ptr_t buf, size_t sz) + { + if (munmap(buf, ROUNDUP_PAGESIZE(sz)) == -1) + ABORT_ARG1("munmap failed (for procedure stack space)", + ": errno= %d", errno); + } + # ifdef THREADS GC_INNER size_t GC_alloc_and_get_procedure_stack(ptr_t *pbuf) { |