diff --git a/src/dice/loader.c b/src/dice/loader.c index be5651db..861612d1 100644 --- a/src/dice/loader.c +++ b/src/dice/loader.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ #include @@ -25,13 +25,13 @@ int ps_dispatch_max(void); void ps_init_(); static DICE_CTOR void -_init() +init_() { ps_init_(); } static void -_load_plugin(const char *path) +load_plugin_(const char *path) { log_debug("[%4d] LOAD: %s", DICE_MODULE_PRIO, path); void *handle = dlopen(path, RTLD_GLOBAL | RTLD_LAZY); @@ -41,7 +41,7 @@ _load_plugin(const char *path) } static char * -_strdup(const char *str) +strdup_(const char *str) { if (str == NULL) return NULL; @@ -60,7 +60,7 @@ PS_SUBSCRIBE(CHAIN_CONTROL, EVENT_DICE_INIT, { log_debug("[%4d] LOAD: builtin modules: 0..%d", DICE_MODULE_PRIO, ps_dispatch_max()); if (envvar != NULL) { - char *plugins = _strdup(envvar); + char *plugins = strdup_(envvar); assert(plugins); char *path = strtok(plugins, ":"); @@ -68,7 +68,7 @@ PS_SUBSCRIBE(CHAIN_CONTROL, EVENT_DICE_INIT, { // skip first path = strtok(NULL, ":"); while (path != NULL) { - _load_plugin(path); + load_plugin_(path); path = strtok(NULL, ":"); } mempool_free(plugins); diff --git a/src/dice/mempool.c b/src/dice/mempool.c index cf5d22a2..c2ba89b4 100644 --- a/src/dice/mempool.c +++ b/src/dice/mempool.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ #include @@ -12,7 +12,7 @@ #include #include -static size_t _sizes[] = {32, +static size_t sizes_[] = {32, 128, 512, 1024, @@ -21,15 +21,15 @@ static size_t _sizes[] = {32, 1 * 1024 * 1024, 4 * 1024 * 1024, 8 * 1024 * 1024}; -#define NSTACKS (sizeof(_sizes) / sizeof(size_t)) +#define NSTACKS (sizeof(sizes_) / sizeof(size_t)) #define MEMPOOL_SIZE (1024 * 1024 * 200) static unsigned int -_bucketize(size_t size) +bucketize_(size_t size) { unsigned int i = 0; - for (; i < NSTACKS && size > _sizes[i]; i++) + for (; i < NSTACKS && size > sizes_[i]; i++) ; assert(i < NSTACKS); return i; @@ -54,7 +54,7 @@ typedef struct mempool { entry_t *stack[NSTACKS]; } mempool_t; -static mempool_t _mp; +static mempool_t mp_; /* bypass malloc interceptor */ REAL_DECL(void *, malloc, size_t n); @@ -62,13 +62,13 @@ REAL_DECL(void *, malloc, size_t n); DICE_HIDE void mempool_init(size_t cap) { - memset(&_mp.stack, 0, sizeof(entry_t *) * NSTACKS); - _mp.allocated = 0; - _mp.pool.capacity = cap; - _mp.pool.next = 0; - _mp.pool.memory = REAL_CALL(malloc, 0, cap); - assert(_mp.pool.memory); - memset(_mp.pool.memory, 0, cap); + memset(&mp_.stack, 0, sizeof(entry_t *) * NSTACKS); + mp_.allocated = 0; + mp_.pool.capacity = cap; + mp_.pool.next = 0; + mp_.pool.memory = REAL_CALL(malloc, 0, cap); + assert(mp_.pool.memory); + memset(mp_.pool.memory, 0, cap); // caslock already initialized with 0 } @@ -76,24 +76,24 @@ static inline void mempool_ensure_initd(void) { // assumes protected by lock - if (_mp.pool.memory == NULL) + if (mp_.pool.memory == NULL) mempool_init(MEMPOOL_SIZE); } DICE_MODULE_INIT({ - caslock_acquire(&_mp.lock); + caslock_acquire(&mp_.lock); mempool_ensure_initd(); - caslock_release(&_mp.lock); + caslock_release(&mp_.lock); }) DICE_HIDE_IF void * mempool_alloc(size_t n) { - mempool_t *mp = &_mp; + mempool_t *mp = &mp_; entry_t *e = NULL; size_t size = n + sizeof(entry_t); - unsigned bucket = _bucketize(size); - size = _sizes[bucket]; + unsigned bucket = bucketize_(size); + size = sizes_[bucket]; entry_t **stack = &mp->stack[bucket]; assert(stack); @@ -138,12 +138,12 @@ mempool_realloc(void *ptr, size_t size) DICE_HIDE_IF void mempool_free(void *ptr) { - mempool_t *mp = &_mp; + mempool_t *mp = &mp_; assert(ptr); entry_t *e = (entry_t *)ptr - 1; size_t size = e->size + sizeof(entry_t); - unsigned bucket = _bucketize(size); - size = _sizes[bucket]; + unsigned bucket = bucketize_(size); + size = sizes_[bucket]; entry_t **stack = &mp->stack[bucket]; // Mempool is used from rogue thread, serialization is necessary diff --git a/src/dice/pubsub.c b/src/dice/pubsub.c index f80ca5d0..5413a03f 100644 --- a/src/dice/pubsub.c +++ b/src/dice/pubsub.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ #include @@ -33,7 +33,7 @@ struct chain { struct type types[MAX_TYPES]; }; -static struct chain _chains[MAX_CHAINS]; +static struct chain chains_[MAX_CHAINS]; // ----------------------------------------------------------------------------- // initializer @@ -46,23 +46,23 @@ ps_initd_(void) NONE, START, BLOCK, - } _state = NONE; + } state_ = NONE; static bool ready = false; if (likely(ready)) { return true; } - switch (_state) { + switch (state_) { case NONE: // This must be the main thread, at latest the thread creation. - _state = START; + state_ = START; PS_PUBLISH(CHAIN_CONTROL, EVENT_DICE_INIT, 0, 0); ready = true; PS_PUBLISH(CHAIN_CONTROL, EVENT_DICE_READY, 0, 0); return true; case START: - _state = BLOCK; + state_ = BLOCK; return true; case BLOCK: // The publication above is still running, drop nested publications. @@ -87,7 +87,7 @@ DICE_MODULE_INIT() // ----------------------------------------------------------------------------- static void -_ps_subscribe_sorted(struct sub **cur, chain_id chain, type_id type, +ps_subscribe_sorted_(struct sub **cur, chain_id chain, type_id type, ps_callback_f cb, int prio, bool any_type) { // any_type is set if this subscription was from ANY_TYPE @@ -101,7 +101,7 @@ _ps_subscribe_sorted(struct sub **cur, chain_id chain, type_id type, next = *cur; goto insert; } else { - _ps_subscribe_sorted(&(*cur)->next, chain, type, cb, prio, any_type); + ps_subscribe_sorted_(&(*cur)->next, chain, type, cb, prio, any_type); return; } @@ -117,20 +117,20 @@ _ps_subscribe_sorted(struct sub **cur, chain_id chain, type_id type, } static int -_ps_subscribe_type(chain_id chain, type_id type, ps_callback_f cb, int prio, +ps_subscribe_type_(chain_id chain, type_id type, ps_callback_f cb, int prio, bool any_type) { (void)prio; if (type > MAX_TYPES) return PS_INVALID; - struct type *ev = &_chains[chain].types[type]; + struct type *ev = &chains_[chain].types[type]; // increment the idx of next subscription ev->count++; // register subscription - _ps_subscribe_sorted(&ev->head, chain, type, cb, prio, any_type); + ps_subscribe_sorted_(&ev->head, chain, type, cb, prio, any_type); return PS_OK; } @@ -150,11 +150,11 @@ ps_subscribe(chain_id chain, type_id type, ps_callback_f cb, int prio) if (chain > MAX_CHAINS) return PS_INVALID; if (type != ANY_TYPE) - return _ps_subscribe_type(chain, type, cb, prio, false); + return ps_subscribe_type_(chain, type, cb, prio, false); int err; for (size_t i = 1; i < MAX_TYPES; i++) - if ((err = _ps_subscribe_type(chain, i, cb, prio, true)) != 0) + if ((err = ps_subscribe_type_(chain, i, cb, prio, true)) != 0) return err; return PS_OK; @@ -165,7 +165,7 @@ ps_subscribe(chain_id chain, type_id type, ps_callback_f cb, int prio) // ----------------------------------------------------------------------------- static enum ps_err -_ps_publish(const chain_id chain, const type_id type, void *event, +ps_publish_(const chain_id chain, const type_id type, void *event, metadata_t *md) { if (unlikely(chain >= MAX_CHAINS)) @@ -173,7 +173,7 @@ _ps_publish(const chain_id chain, const type_id type, void *event, if (unlikely(type == ANY_TYPE || type >= MAX_TYPES)) return PS_INVALID; - struct type *ev = &_chains[chain].types[type]; + struct type *ev = &chains_[chain].types[type]; struct sub *cur = ev->head; while (cur) { // now we call the callback and abort the chain if the subscriber @@ -215,5 +215,5 @@ ps_publish(const chain_id chain, const type_id type, void *event, if (likely(err == PS_DROP_EVENT)) return PS_DROP_EVENT; - return _ps_publish(chain, type, event, md); + return ps_publish_(chain, type, event, md); } diff --git a/src/dice/rbtree.c b/src/dice/rbtree.c index 4497119b..94f35c5d 100644 --- a/src/dice/rbtree.c +++ b/src/dice/rbtree.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ #include @@ -9,7 +9,7 @@ #define RIGHT 1 static void -_rotate(struct rbtree *tree, struct rbnode *x, int dir) +rotate_(struct rbtree *tree, struct rbnode *x, int dir) { struct rbnode *y = (dir == LEFT) ? x->right : x->left; if (dir == LEFT) { @@ -37,7 +37,7 @@ _rotate(struct rbtree *tree, struct rbnode *x, int dir) } static void -_insert_fixup(struct rbtree *tree, struct rbnode *z) +insert_fixup_(struct rbtree *tree, struct rbnode *z) { while (z->parent && z->parent->color == RB_RED) { struct rbnode *gp = z->parent->parent; @@ -53,11 +53,11 @@ _insert_fixup(struct rbtree *tree, struct rbnode *z) if ((dir == LEFT && z == z->parent->right) || (dir == RIGHT && z == z->parent->left)) { z = z->parent; - _rotate(tree, z, dir); + rotate_(tree, z, dir); } z->parent->color = RB_BLACK; gp->color = RB_RED; - _rotate(tree, gp, !dir); + rotate_(tree, gp, !dir); } } tree->root->color = RB_BLACK; @@ -94,11 +94,11 @@ rbtree_insert(struct rbtree *tree, struct rbnode *z) else parent->right = z; - _insert_fixup(tree, z); + insert_fixup_(tree, z); } static struct rbnode * -_minimum(struct rbnode *node) +minimum_(struct rbnode *node) { while (node && node->left) node = node->left; @@ -106,7 +106,7 @@ _minimum(struct rbnode *node) } static void -_transplant(struct rbtree *tree, struct rbnode *u, struct rbnode *v) +transplant_(struct rbtree *tree, struct rbnode *u, struct rbnode *v) { if (!u->parent) tree->root = v; @@ -119,7 +119,7 @@ _transplant(struct rbtree *tree, struct rbnode *u, struct rbnode *v) } static void -_remove_fixup(struct rbtree *tree, struct rbnode *x, struct rbnode *x_parent) +remove_fixup_(struct rbtree *tree, struct rbnode *x, struct rbnode *x_parent) { while ((!x || x->color == RB_BLACK) && x != tree->root) { int left = (x == x_parent->left); @@ -128,7 +128,7 @@ _remove_fixup(struct rbtree *tree, struct rbnode *x, struct rbnode *x_parent) if (w->color == RB_RED) { w->color = RB_BLACK; x_parent->color = RB_RED; - _rotate(tree, x_parent, left ? LEFT : RIGHT); + rotate_(tree, x_parent, left ? LEFT : RIGHT); w = left ? x_parent->right : x_parent->left; } @@ -145,7 +145,7 @@ _remove_fixup(struct rbtree *tree, struct rbnode *x, struct rbnode *x_parent) if (!left && w->right) w->right->color = RB_BLACK; w->color = RB_RED; - _rotate(tree, w, left ? RIGHT : LEFT); + rotate_(tree, w, left ? RIGHT : LEFT); w = left ? x_parent->right : x_parent->left; } @@ -155,7 +155,7 @@ _remove_fixup(struct rbtree *tree, struct rbnode *x, struct rbnode *x_parent) w->right->color = RB_BLACK; if (!left && w->left) w->left->color = RB_BLACK; - _rotate(tree, x_parent, left ? LEFT : RIGHT); + rotate_(tree, x_parent, left ? LEFT : RIGHT); x = tree->root; } } @@ -175,29 +175,29 @@ rbtree_remove(struct rbtree *tree, struct rbnode *z) if (!z->left) { x = z->right; x_parent = z->parent; - _transplant(tree, z, z->right); + transplant_(tree, z, z->right); } else if (!z->right) { x = z->left; x_parent = z->parent; - _transplant(tree, z, z->left); + transplant_(tree, z, z->left); } else { - y = _minimum(z->right); + y = minimum_(z->right); y_color_orig = y->color; x = y->right; x_parent = y->parent == z ? y : y->parent; if (y->parent != z) { - _transplant(tree, y, y->right); + transplant_(tree, y, y->right); y->right = z->right; y->right->parent = y; } - _transplant(tree, z, y); + transplant_(tree, z, y); y->left = z->left; y->left->parent = y; y->color = z->color; } if (y_color_orig == RB_BLACK) - _remove_fixup(tree, x, x_parent); + remove_fixup_(tree, x, x_parent); } DICE_HIDE_IF struct rbnode * @@ -216,7 +216,7 @@ rbtree_find(const struct rbtree *tree, const struct rbnode *key) DICE_HIDE_IF struct rbnode * rbtree_min(const struct rbtree *tree) { - return _minimum(tree->root); + return minimum_(tree->root); } DICE_HIDE_IF struct rbnode * diff --git a/src/mod/pthread_create.c b/src/mod/pthread_create.c index 26d0d9df..ec462f91 100644 --- a/src/mod/pthread_create.c +++ b/src/mod/pthread_create.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ #include @@ -28,7 +28,7 @@ INTERPOSE(void, pthread_exit, void *ptr) } static void * -_trampoline(void *targ) +trampoline_(void *targ) { trampoline_t *t = (trampoline_t *)targ; void *arg = t->arg; @@ -57,7 +57,7 @@ INTERPOSE(int, pthread_create, pthread_t *thread, const pthread_attr_t *attr, metadata_t md = {0}; PS_PUBLISH(INTERCEPT_BEFORE, EVENT_THREAD_CREATE, &ev, &md); - ev.ret = REAL(pthread_create, thread, attr, _trampoline, t); + ev.ret = REAL(pthread_create, thread, attr, trampoline_, t); PS_PUBLISH(INTERCEPT_AFTER, EVENT_THREAD_CREATE, &ev, &md); return ev.ret; } diff --git a/src/mod/self.c b/src/mod/self.c index ba2dff4b..84455acb 100644 --- a/src/mod/self.c +++ b/src/mod/self.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD * ----------------------------------------------------------------------------- * Thread "self-awareness" @@ -66,14 +66,14 @@ struct tls_item { char data[]; }; -static void _cleanup_threads(pthread_t id); +static void cleanup_threads_(pthread_t id); // ----------------------------------------------------------------------------- // tls items // ----------------------------------------------------------------------------- DICE_HIDE int -_tls_cmp(const struct rbnode *a, const struct rbnode *b) +tls_cmp_(const struct rbnode *a, const struct rbnode *b) { const struct tls_item *ea = container_of(a, struct tls_item, node); const struct tls_item *eb = container_of(b, struct tls_item, node); @@ -81,13 +81,13 @@ _tls_cmp(const struct rbnode *a, const struct rbnode *b) } DICE_HIDE void -_tls_init(struct self *self) +tls_init_(struct self *self) { - rbtree_init(&self->tls, _tls_cmp); + rbtree_init(&self->tls, tls_cmp_); } DICE_HIDE void -_tls_fini(struct self *self) +tls_fini_(struct self *self) { // TODO: iterate over all items and mempool_free them (void)self; @@ -146,51 +146,51 @@ static struct { vatomic64_t count; pthread_key_t cache_key; quack_t retired; -} _threads; +} threads_; static void -_thread_cache_destruct(void *arg) +thread_cache_destruct_(void *arg) { (void)arg; } static void -_thread_cache_init(void) +thread_cache_init_(void) { - if (pthread_key_create(&_threads.cache_key, _thread_cache_destruct) != 0) + if (pthread_key_create(&threads_.cache_key, thread_cache_destruct_) != 0) abort(); } static void -_thread_cache_del(struct self *self) +thread_cache_del_(struct self *self) { (void)self; - if (pthread_setspecific(_threads.cache_key, NULL) != 0) + if (pthread_setspecific(threads_.cache_key, NULL) != 0) log_fatal("could not del key"); } static void -_thread_cache_set(struct self *self) +thread_cache_set_(struct self *self) { - if (pthread_setspecific(_threads.cache_key, self) != 0) + if (pthread_setspecific(threads_.cache_key, self) != 0) log_fatal("could not set key"); } DICE_HIDE struct self * -_thread_cache_get(void) +thread_cache_get_(void) { - return (struct self *)pthread_getspecific(_threads.cache_key); + return (struct self *)pthread_getspecific(threads_.cache_key); } #if defined(__linux__) static uint64_t -_thread_oid(void) +thread_oid_(void) { return (uint64_t)gettid(); } static bool -_thread_dead(struct self *self) +thread_dead_(struct self *self) { return kill((pid_t)self->oid, 0) != 0; } @@ -198,13 +198,13 @@ _thread_dead(struct self *self) #else // !linux static uint64_t -_thread_oid(void) +thread_oid_(void) { return 0; } static bool -_thread_dead(struct self *self) +thread_dead_(struct self *self) { // pthread_kill with signal 0 does not do anything with the thread, but // if an ESRCH error indicates the thread does not exist. See: @@ -221,37 +221,37 @@ _thread_dead(struct self *self) #endif // !linux DICE_HIDE struct self * -_create_self() +create_self_() { struct self *self; self = mempool_alloc(sizeof(struct self)); self->guard = 0; - self->tid = vatomic64_inc_get(&_threads.count); + self->tid = vatomic64_inc_get(&threads_.count); self->pid = pthread_self(); - self->oid = _thread_oid(); + self->oid = thread_oid_(); self->retired = false; - _tls_init(self); + tls_init_(self); return self; } static void -_destroy_self(struct self *self) +destroy_self_(struct self *self) { - _tls_fini(self); + tls_fini_(self); mempool_free(self); } static void -_init_threads(void) +init_threads_(void) { - _thread_cache_init(); - caslock_init(&_threads.lock); - quack_init(&_threads.retired); + thread_cache_init_(); + caslock_init(&threads_.lock); + quack_init(&threads_.retired); } static struct self * -_get_self(void) +get_self_(void) { // When a thread is created, it won't find its self object anywhere and this // function will return NULL. A new self object will be created and stored @@ -269,15 +269,15 @@ _get_self(void) // stack. pthread_t pid = pthread_self(); - struct self *self = _thread_cache_get(); + struct self *self = thread_cache_get_(); if (self) return self; // We now search the retired stack. To avoid not seeing our self object // while other threads are searching theirs, we have to ensure mutual // exlusion here. - caslock_acquire(&_threads.lock); - struct quack_node_s *item = quack_popall(&_threads.retired); + caslock_acquire(&threads_.lock); + struct quack_node_s *item = quack_popall(&threads_.retired); struct quack_node_s *next = NULL; for (; item; item = next) { @@ -287,21 +287,21 @@ _get_self(void) if (self == NULL && it->pid == pid) self = it; - quack_push(&_threads.retired, item); + quack_push(&threads_.retired, item); } - caslock_release(&_threads.lock); + caslock_release(&threads_.lock); assert(self == NULL || self->retired); return self; } static void -_retire_self(struct self *self) +retire_self_(struct self *self) { assert(self); assert(!self->retired); self->retired = true; - _thread_cache_del(self); - quack_push(&_threads.retired, &self->retired_node); + thread_cache_del_(self); + quack_push(&threads_.retired, &self->retired_node); } // ----------------------------------------------------------------------------- @@ -321,7 +321,7 @@ _retire_self(struct self *self) } while (0) DICE_HIDE enum ps_err -_self_handle_before(const chain_id chain, const type_id type, void *event, +self_handle_before_(const chain_id chain, const type_id type, void *event, struct self *self) { (void)chain; @@ -338,7 +338,7 @@ _self_handle_before(const chain_id chain, const type_id type, void *event, } DICE_HIDE enum ps_err -_self_handle_after(const chain_id chain, const type_id type, void *event, +self_handle_after_(const chain_id chain, const type_id type, void *event, struct self *self) { (void)chain; @@ -355,7 +355,7 @@ _self_handle_after(const chain_id chain, const type_id type, void *event, } DICE_HIDE enum ps_err -_self_handle_event(const chain_id chain, const type_id type, void *event, +self_handle_event_(const chain_id chain, const type_id type, void *event, struct self *self) { (void)chain; @@ -372,32 +372,32 @@ _self_handle_event(const chain_id chain, const type_id type, void *event, } static struct self * -_get_or_create_self(bool publish) +get_or_create_self_(bool publish) { - struct self *self = _get_self(); + struct self *self = get_self_(); if (likely(self)) { return self; } - self = _create_self(); + self = create_self_(); - _thread_cache_set(self); + thread_cache_set_(self); if (publish) - _self_handle_event(CAPTURE_EVENT, EVENT_SELF_INIT, 0, self); + self_handle_event_(CAPTURE_EVENT, EVENT_SELF_INIT, 0, self); return self; } PS_SUBSCRIBE(INTERCEPT_EVENT, ANY_TYPE, { - return _self_handle_event(chain, type, event, _get_or_create_self(true)); + return self_handle_event_(chain, type, event, get_or_create_self_(true)); }) PS_SUBSCRIBE(INTERCEPT_BEFORE, ANY_TYPE, { if (type == EVENT_THREAD_CREATE) - _cleanup_threads(0); - return _self_handle_before(chain, type, event, _get_or_create_self(true)); + cleanup_threads_(0); + return self_handle_before_(chain, type, event, get_or_create_self_(true)); }) PS_SUBSCRIBE(INTERCEPT_AFTER, ANY_TYPE, { - return _self_handle_after(chain, type, event, _get_or_create_self(true)); + return self_handle_after_(chain, type, event, get_or_create_self_(true)); }) // ----------------------------------------------------------------------------- @@ -405,23 +405,23 @@ PS_SUBSCRIBE(INTERCEPT_AFTER, ANY_TYPE, { // ----------------------------------------------------------------------------- static void -_self_fini(struct self *self) +self_fini_(struct self *self) { if (self == NULL) return; // announce thread self is really over - _self_handle_event(CAPTURE_EVENT, EVENT_SELF_FINI, 0, self); + self_handle_event_(CAPTURE_EVENT, EVENT_SELF_FINI, 0, self); // free self resources - _destroy_self(self); + destroy_self_(self); } static void -_cleanup_threads(pthread_t pid) +cleanup_threads_(pthread_t pid) { - caslock_acquire(&_threads.lock); - struct quack_node_s *item = quack_popall(&_threads.retired); + caslock_acquire(&threads_.lock); + struct quack_node_s *item = quack_popall(&threads_.retired); struct quack_node_s *next = NULL; for (; item; item = next) { @@ -429,30 +429,30 @@ _cleanup_threads(pthread_t pid) struct self *self = container_of(item, struct self, retired_node); - if ((pid != 0 && self->pid == pid) || (pid == 0 && _thread_dead(self))) - _self_fini(self); + if ((pid != 0 && self->pid == pid) || (pid == 0 && thread_dead_(self))) + self_fini_(self); else - quack_push(&_threads.retired, item); + quack_push(&threads_.retired, item); } - caslock_release(&_threads.lock); + caslock_release(&threads_.lock); } PS_SUBSCRIBE(INTERCEPT_EVENT, EVENT_THREAD_EXIT, { - struct self *self = _get_or_create_self(true); - _self_handle_event(chain, type, event, self); - _retire_self(self); + struct self *self = get_or_create_self_(true); + self_handle_event_(chain, type, event, self); + retire_self_(self); return PS_STOP_CHAIN; }) PS_SUBSCRIBE(INTERCEPT_AFTER, EVENT_THREAD_JOIN, { - struct self *self = _get_or_create_self(true); + struct self *self = get_or_create_self_(true); struct pthread_join_event *ev = EVENT_PAYLOAD(ev); - _self_handle_after(chain, type, event, self); + self_handle_after_(chain, type, event, self); return PS_STOP_CHAIN; }) -DICE_MODULE_INIT({ _init_threads(); }) +DICE_MODULE_INIT({ init_threads_(); }) DICE_MODULE_FINI({ - _cleanup_threads(0); - _self_fini(_get_self()); + cleanup_threads_(0); + self_fini_(get_self_()); }) diff --git a/src/mod/stacktrace.c b/src/mod/stacktrace.c index 631c601a..b2f95a93 100644 --- a/src/mod/stacktrace.c +++ b/src/mod/stacktrace.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Copyright (C) 2025 Huawei Technologies Co., Ltd. * SPDX-License-Identifier: 0BSD */ /******************************************************************************* @@ -17,12 +17,12 @@ DICE_MODULE_INIT() -static void _check_main_start(void *caller); +static void check_main_start_(void *caller); void __tsan_func_entry(void *caller) { - _check_main_start(INTERPOSE_PC); + check_main_start_(INTERPOSE_PC); stacktrace_event_t ev = {.caller = caller, .pc = INTERPOSE_PC}; metadata_t md = {0}; @@ -42,17 +42,17 @@ __tsan_func_exit(void) * -------------------------------------------------------------------------- */ #if !defined(DICE_MAIN_START_DISABLE) static void -_main_exit() +main_exit_() { PS_PUBLISH(INTERCEPT_EVENT, EVENT_THREAD_EXIT, 0, 0); log_debug("main thread exits"); } static void -_main_start() +main_start_() { log_debug("main thread starts"); PS_PUBLISH(INTERCEPT_EVENT, EVENT_THREAD_START, 0, 0); - atexit(_main_exit); + atexit(main_exit_); } #endif @@ -62,7 +62,7 @@ _main_start() #if defined(DICE_MAIN_START_DISABLE) static inline void -_check_main_start(void *retpc) +check_main_start_(void *retpc) { (void)retpc; } @@ -80,7 +80,7 @@ _check_main_start(void *retpc) #include static int -_phdr_cb(struct dl_phdr_info *info, size_t size, void *data) +phdr_cb_(struct dl_phdr_info *info, size_t size, void *data) { (void)size; const char *exe = (const char *)data; @@ -92,7 +92,7 @@ _phdr_cb(struct dl_phdr_info *info, size_t size, void *data) } static void * -_find_main_address(void) +find_main_address_(void) { char exe[PATH_MAX]; ssize_t n = readlink("/proc/curproc/exe", exe, sizeof(exe) - 1); @@ -110,7 +110,7 @@ _find_main_address(void) // 2) runtime slide (ASLR) of the main executable uintptr_t slide = 0; - int rc = dl_iterate_phdr(_phdr_cb, exe); + int rc = dl_iterate_phdr(phdr_cb_, exe); if (rc > 1) slide = (uintptr_t)(rc - 1); // see phdr_cb trick above @@ -120,20 +120,20 @@ _find_main_address(void) #define MAX_MAIN_THREAD_DISTANCE 128 static inline void -_check_main_start(void *retpc) +check_main_start_(void *retpc) { - static void *_main_ptr = NULL; - static bool _started = false; - if (_main_ptr == NULL) - _main_ptr = _find_main_address(); + static void *main_ptr_ = NULL; + static bool started_ = false; + if (main_ptr_ == NULL) + main_ptr_ = find_main_address_(); - if (!_started) { - uintptr_t diff = (uintptr_t)retpc - (uintptr_t)_main_ptr; + if (!started_) { + uintptr_t diff = (uintptr_t)retpc - (uintptr_t)main_ptr_; log_debug("diff: 0x%lx=%lu", diff, diff); if (diff < MAX_MAIN_THREAD_DISTANCE) { - _started = true; - _main_start(); + started_ = true; + main_start_(); } } } @@ -141,7 +141,7 @@ _check_main_start(void *retpc) #elif defined(__linux__) static inline void -_check_main_start(void *retpc) +check_main_start_(void *retpc) { (void)retpc; } @@ -160,7 +160,7 @@ INTERPOSE(int, __libc_start_main, main_f mainf, int argc, char **ubp_av, void (*init)(void), void (*fini)(void), void (*rtld_fini)(void), void *stack_end) { - _main_start(); + main_start_(); return REAL_CALL(__libc_start_main, 0, mainf, argc, ubp_av, init, fini, rtld_fini, stack_end); } @@ -170,7 +170,7 @@ INTERPOSE(int, __libc_start_main, main_f mainf, int argc, char **ubp_av, INTERPOSE(int, __libc_start_main, main_f mainf, int argc, char **argv, void (*init)(void), void (*fini)(void), void (*rtld_fini)(void)) { - _main_start(); + main_start_(); return REAL_CALL(__libc_start_main, 0, mainf, argc, argv, init, fini, rtld_fini); }