diff options
Diffstat (limited to 'libdw/libdwP.h')
-rw-r--r-- | libdw/libdwP.h | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/libdw/libdwP.h b/libdw/libdwP.h index eebb7d12..36c2acd9 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -31,9 +31,11 @@ #include <libintl.h> #include <stdbool.h> +#include <pthread.h> #include <libdw.h> #include <dwarf.h> +#include "atomics.h" /* gettext helper macros. */ @@ -218,16 +220,22 @@ struct Dwarf /* Similar for addrx/constx, which will come from .debug_addr section. */ struct Dwarf_CU *fake_addr_cu; - /* Internal memory handling. This is basically a simplified + /* Supporting lock for internal memory handling. Ensures threads that have + an entry in the mem_tails array are not disturbed by new threads doing + allocations for this Dwarf. */ + pthread_rwlock_t mem_rwl; + + /* Internal memory handling. This is basically a simplified thread-local reimplementation of obstacks. Unfortunately the standard obstack implementation is not usable in libraries. */ + size_t mem_stacks; struct libdw_memblock { size_t size; size_t remaining; struct libdw_memblock *prev; char mem[0]; - } *mem_tail; + } **mem_tails; /* Default size of allocated memory blocks. */ size_t mem_default_size; @@ -570,9 +578,9 @@ libdw_valid_user_form (int form) extern void __libdw_seterrno (int value) internal_function; -/* Memory handling, the easy parts. This macro does not do any locking. */ +/* Memory handling, the easy parts. */ #define libdw_alloc(dbg, type, tsize, cnt) \ - ({ struct libdw_memblock *_tail = (dbg)->mem_tail; \ + ({ struct libdw_memblock *_tail = __libdw_alloc_tail(dbg); \ size_t _required = (tsize) * (cnt); \ type *_result = (type *) (_tail->mem + (_tail->size - _tail->remaining));\ size_t _padding = ((__alignof (type) \ @@ -591,6 +599,23 @@ extern void __libdw_seterrno (int value) internal_function; #define libdw_typed_alloc(dbg, type) \ libdw_alloc (dbg, type, sizeof (type), 1) +/* Can only be used to undo the last libdw_alloc. */ +#define libdw_unalloc(dbg, type, tsize, cnt) \ + ({ struct libdw_memblock *_tail = __libdw_thread_tail (dbg); \ + size_t _required = (tsize) * (cnt); \ + /* We cannot know the padding, it is lost. */ \ + _tail->remaining += _required; }) \ + +#define libdw_typed_unalloc(dbg, type) \ + libdw_unalloc (dbg, type, sizeof (type), 1) + +/* Callback to choose a thread-local memory allocation stack. */ +extern struct libdw_memblock *__libdw_alloc_tail (Dwarf* dbg) + __nonnull_attribute__ (1); + +extern struct libdw_memblock *__libdw_thread_tail (Dwarf* dbg) + __nonnull_attribute__ (1); + /* Callback to allocate more. */ extern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align) __attribute__ ((__malloc__)) __nonnull_attribute__ (1); |