diff options
author | Eric Wong <e@80x24.org> | 2022-11-18 07:58:17 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-11-19 22:19:03 +0000 |
commit | a604f91b061139a236c9f6d734ff0b174dcb5c24 (patch) | |
tree | 6d211b6e5191a3290568000cb9bf3172a212f84b | |
parent | 2b000285c63144bc1a03587c926c2af96f7a23e5 (diff) | |
download | mwrap-a604f91b061139a236c9f6d734ff0b174dcb5c24.tar.gz |
alloca(3) is difficult for the compiler and static checkers to deal with, and we already reserve TSD space for storing path names.
-rw-r--r-- | Mwrap.xs | 2 | ||||
-rw-r--r-- | mwrap_core.h | 21 |
2 files changed, 13 insertions, 10 deletions
@@ -153,7 +153,7 @@ mwrap_get(loc) PREINIT: STRLEN len; const char *str; - struct src_loc *k = (void *)kbuf; + struct src_loc *k = &tsd.src_loc; uintptr_t p; struct cds_lfht_iter iter; struct cds_lfht_node *cur; diff --git a/mwrap_core.h b/mwrap_core.h index 3abc3dd..09b7930 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -178,9 +178,12 @@ struct alloc_hdr { }; /* $PATHNAME:$LINENO */ -static MWRAP_TSD char kbuf[ - sizeof(struct src_loc) + PATH_MAX + sizeof(":") + UINT2STR_MAX -]; +static MWRAP_TSD union { + char kbuf[ + sizeof(struct src_loc) + PATH_MAX + sizeof(":") + UINT2STR_MAX + ]; + struct src_loc src_loc; +} tsd; static struct alloc_hdr *ptr2hdr(void *p) { @@ -290,7 +293,7 @@ static struct src_loc *assign_line(size_t size, const char *file, unsigned line) len = strlen(file); if (len > PATH_MAX) len = PATH_MAX; - k = (void *)kbuf; + k = &tsd.src_loc; k->total = size; dst = mempcpy(k->k, file, len); *dst++ = ':'; @@ -311,7 +314,6 @@ static struct src_loc * update_stats_rcu_lock(size_t *generation, size_t size, uintptr_t caller) { struct src_loc *k, *ret = 0; - static const size_t xlen = sizeof(caller); struct cds_lfht *t = CMM_LOAD_SHARED(totals); const COP *cop = NULL; @@ -326,11 +328,11 @@ update_stats_rcu_lock(size_t *generation, size_t size, uintptr_t caller) ret = assign_line(size, OutCopFILE(cop), CopLINE(cop)); #endif /* MWRAP_PERL */ if (!ret) { - k = alloca(sizeof(*k) + xlen); + k = &tsd.src_loc; k->total = size; - memcpy(k->k, &caller, xlen); + memcpy(k->k, &caller, sizeof(caller)); k->capa = 0; - hash_loc(k, xlen); + hash_loc(k, sizeof(caller)); ret = totals_add_rcu(k); } out: @@ -672,7 +674,8 @@ static void dump_destructor(void) *dump_path) { char *end = strchr(dump_path, ','); if (end) { - char *tmp = alloca(end - dump_path + 1); + char *tmp = tsd.kbuf; + assert((end - dump_path) < sizeof(tsd.kbuf)); end = mempcpy(tmp, dump_path, end - dump_path); *end = 0; dump_path = tmp; |