|
|
Message-ID: <69e536f01742a1c62bbda3a6342415dc54234c91.camel@posteo.net>
Date: Wed, 09 Sep 2026 15:12:35 +0000
From: John Scott <jscott@...teo.net>
To: libc-coord@...ts.openwall.com, Pavel Labath <labath@...gle.com>
Subject: Re: An async-signal-safe way to get
thread’s stack
From reading the sacred scriptures, I'm hopeful that POSIX may provide what's needed, for at least some cases, as follows:
(And bear in mind that I know almost nothing about your use case or how these interfaces are actually used in practice; my knowledge comes merely from reading the standard here.)
Refer to the definition of SA_SIGINFO at https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaction.html where it specifies the prototype for such a signal-catching function as
> void func(int signo, siginfo_t *info, void *context);
where
> the third argument can be cast to a pointer to an object of type ucontext_t to refer to the receiving thread's context that was interrupted when the signal was delivered.
Indeed, although the <ucontext.h> functions are no longer in the standard, the ucontext_t and stack_t types are still defined in <signal.h> https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html
> The <signal.h> header shall define the ucontext_t type as a structure that shall include at least the following members:
> ...
> stack_t uc_stack The stack used by this context.
So, regardless of whether the signal handler is using an alternate signal stack, one can access ((ucontext_t *)context)->uc_stack within such a signal handler to obtain a stack_t, which is a structure that shall contain at least the following members describing the stack of the thread which was interrupted:
> void *ss_sp Stack base or pointer.
> size_t ss_size Stack size.
> int ss_flags Flags.
Valid flag values starting with SS_ are defined for XSI systems, and I think implementations are allowed to expose other SS_ constants too.
Maybe this gets you somewhere 🤷
Download attachment "signature.asc" of type "application/pgp-signature" (412 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.