Module: kamailio
Branch: master
Commit: 1397682006dd7fc7df0cb95d92ff6424f7ad506f
URL:
https://github.com/kamailio/kamailio/commit/1397682006dd7fc7df0cb95d92ff642…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-08-22T11:10:36+02:00
core: mem - shm api extended to enable setting func field of the chunk
- implemented for q_malloc(), being needed for reviving tls extra debug mode
---
Modified: src/core/mem/memapi.h
Modified: src/core/mem/q_malloc.c
Modified: src/core/mem/shm.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1397682006dd7fc7df0cb95d92ff642…
Patch:
https://github.com/kamailio/kamailio/commit/1397682006dd7fc7df0cb95d92ff642…
---
diff --git a/src/core/mem/memapi.h b/src/core/mem/memapi.h
index b9448b4ace7..8b3b0c1e5a2 100644
--- a/src/core/mem/memapi.h
+++ b/src/core/mem/memapi.h
@@ -60,6 +60,8 @@ typedef void (*sr_mem_destroy_f)(void);
typedef void (*sr_mem_mod_get_stats_f)(void *mbp, void **p);
typedef void (*sr_mem_mod_free_stats_f)(void *mbp);
+typedef void (*sr_setfunc_f)(void *mbp, void *p, char *func);
+
/*private memory api*/
typedef struct sr_pkg_api
{
@@ -142,6 +144,8 @@ typedef struct sr_shm_api
sr_shm_glock_f xglock;
/*memory managing global unlock*/
sr_shm_gunlock_f xgunlock;
+ /*memory chunk set func pointer*/
+ sr_setfunc_f xsetfunc;
} sr_shm_api_t;
#endif
diff --git a/src/core/mem/q_malloc.c b/src/core/mem/q_malloc.c
index a3b9161ca3b..e1b48ecd63f 100644
--- a/src/core/mem/q_malloc.c
+++ b/src/core/mem/q_malloc.c
@@ -788,6 +788,29 @@ void *qm_reallocxf(void *qmp, void *p, size_t size)
}
+void qm_setfunc(void *qmp, void *p, char *func)
+{
+#ifndef DBG_QM_MALLOC
+ LM_ERR("used with invalid compile options\n");
+ return;
+#else
+ struct qm_block *qm;
+ struct qm_frag *f;
+
+ qm = (struct qm_block *)qmp;
+
+ if((p) && (p > (void *)qm->last_frag_end || p < (void
*)qm->first_frag)) {
+ LM_CRIT("BUG: bad pointer %p (out of memory block!) - "
+ "aborting\n",
+ p);
+ abort();
+ }
+ f = (struct qm_frag *)((char *)p - sizeof(struct qm_frag));
+
+ f->func = func;
+#endif
+}
+
void qm_check(struct qm_block *qm)
{
struct qm_frag *f;
@@ -1507,6 +1530,7 @@ int qm_malloc_init_shm_manager(void)
ma.xfmodstats = qm_shm_mod_free_stats;
ma.xglock = qm_shm_glock;
ma.xgunlock = qm_shm_gunlock;
+ ma.xsetfunc = qm_setfunc;
if(shm_init_api(&ma) < 0) {
LM_ERR("cannot initialize the core shm api\n");
diff --git a/src/core/mem/shm.h b/src/core/mem/shm.h
index 4db3a0e0101..c83c9dd48a6 100644
--- a/src/core/mem/shm.h
+++ b/src/core/mem/shm.h
@@ -99,6 +99,7 @@ extern sr_shm_api_t _shm_root;
#define shm_global_lock() _shm_root.xglock(_shm_root.mem_block)
#define shm_global_unlock() _shm_root.xgunlock(_shm_root.mem_block)
+#define shm_setfunc(p, f) _shm_root.xsetfunc(_shm_root.mem_block, (p), (f))
void *shm_core_get_pool(void);
int shm_init_api(sr_shm_api_t *ap);