* [musl] Do we have any requirements for the notify method which is registered into the timer_create of Musl, such as not using tsd
@ 2024-09-22 11:19 JinCheng Li
2024-10-04 16:17 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: JinCheng Li @ 2024-09-22 11:19 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]
Hi
I found when using timer_create in hwasan, after call 'notify' function once, musl will call cleanup_fromsig and run __pthread_tsd_run_dtors. Then the hwasan tsd destructor will be done and cleared. After then we step into notify the second time, and becauese the hwasan tsd has been cleared, when the hwasan check has been triggered, sigv will happened. Why MUSL need do pthread_cleanup_push ,pthread_cleanup_pop and clear all tsd after notify? Does this mean that timed callbacks involving tsd may have issues executing in the timer_create of musl, for example the tsd in hwasan.
static void cleanup_fromsig(void *p)
{
pthread_t self = __pthread_self();
__pthread_tsd_run_dtors();
self->cancel = 0;
self->cancelbuf = 0;
self->canceldisable = 0;
self->cancelasync = 0;
__reset_tls();
longjmp(p, 1);
}
...
for (;;) {
siginfo_t si;
while (sigwaitinfo(SIGTIMER_SET, &si) < 0);
if (si.si_code == SI_TIMER && !setjmp(jb)) {
pthread_cleanup_push(cleanup_fromsig, jb);
notify(val);
pthread_cleanup_pop(1);
}
if (self->timer_id < 0) break;
}
...
Best
Li
[-- Attachment #2: Type: text/html, Size: 8136 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] Do we have any requirements for the notify method which is registered into the timer_create of Musl, such as not using tsd
2024-09-22 11:19 [musl] Do we have any requirements for the notify method which is registered into the timer_create of Musl, such as not using tsd JinCheng Li
@ 2024-10-04 16:17 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2024-10-04 16:17 UTC (permalink / raw)
To: JinCheng Li; +Cc: musl
On Sun, Sep 22, 2024 at 11:19:53AM +0000, JinCheng Li wrote:
> Hi
>
> I found when using timer_create in hwasan, after call 'notify'
> function once, musl will call cleanup_fromsig and run
> __pthread_tsd_run_dtors. Then the hwasan tsd destructor will be done
> and cleared. After then we step into notify the second time, and
> becauese the hwasan tsd has been cleared, when the hwasan check has
> been triggered, sigv will happened. Why MUSL need do
> pthread_cleanup_push ,pthread_cleanup_pop and clear all tsd after
> notify? Does this mean that timed callbacks involving tsd may have
> issues executing in the timer_create of musl, for example the tsd in
> hwasan.
Semantically, each SIGEV_THREAD timer event arrives in a *newly
created thread*, which does not preserve any thread-local state from a
previous timer expiration event.
musl's implementation of SIGEV_THREAD reuses the same kernel-level
thread for each expiration event so that we have reserved the
resources for it and can ensure that there are no missed expiration
events due to lack of resources to create a new thread. To do this, we
make a "new application-level thread" by re-initializing the
kernel-level thread's state and the memory it uses for stack/TLS/TSD
to the values that should be seen in a newly created thread.
I don't know how hwasan works or what it needs to do to handle these
threads the way it wants to.
Rich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-04 16:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-22 11:19 [musl] Do we have any requirements for the notify method which is registered into the timer_create of Musl, such as not using tsd JinCheng Li
2024-10-04 16:17 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).