diff options
Diffstat (limited to 'mwrap_core.h')
-rw-r--r-- | mwrap_core.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/mwrap_core.h b/mwrap_core.h index 3fd67f1..9e4f065 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -13,6 +13,7 @@ typedef void COP; #endif +/* set a sensible max to avoid stack overflows */ #ifndef MWRAP_BT_MAX # define MWRAP_BT_MAX 32 #endif @@ -136,14 +137,14 @@ static void *my_mempcpy(void *dest, const void *src, size_t n) #define SRC_LOC_BT(bt) union stk_bt bt; do { \ - uint32_t depth = locating ? 1 : bt_req_depth; \ + uint32_t depth = locating ? 1 : CMM_LOAD_SHARED(bt_req_depth); \ switch (depth) { \ case 0: \ case 1: bt.sl.bt_len = 1; bt.sl.bt[0] = RETURN_ADDRESS(0); break; \ default: /* skip 1st level of BT since thats our function */ \ - mwrap_assert(bt_req_depth <= MWRAP_BT_MAX); \ + mwrap_assert(depth <= MWRAP_BT_MAX); \ ++locating; \ - long n = (long)backtrace(bt_dst(&bt), bt_req_depth); \ + long n = (long)backtrace(bt_dst(&bt), depth); \ --locating; \ bt.sl.bt_len = n <= 1 ? 0 : (uint32_t)n - 1; \ if (n > 1) mwrap_assert(bt.sl.bt[0] == RETURN_ADDRESS(0)); \ @@ -1026,9 +1027,9 @@ __attribute__((constructor)) static void mwrap_ctor(void) char *end; unsigned long n = strtoul(bt, &end, 10); if (n && !errno && (*end == ',' || *end == 0)) { - if (n >= MWRAP_BT_MAX) + if (n > MWRAP_BT_MAX) n = MWRAP_BT_MAX; - bt_req_depth = (uint32_t)n; + CMM_STORE_SHARED(bt_req_depth, (uint32_t)n); } } } |