We rely on errno to determine whether a syscall has failed, so we
need to ensure that accessing errno is async-signal-safe. Currently,
we preserve the errno in sig_handler_common(), but it doesn't cover
every possible case. Let's do it in hard_handler() instead, which
is the signal handler we actually register.
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
Link: https://patch.msgid.link/20260106001228.1531146-2-tiwei.btw@antgroup.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
{
struct uml_pt_regs r;
- int save_errno = errno;
r.is_user = 0;
if (sig == SIGSEGV) {
unblock_signals_trace();
(*sig_info[sig])(sig, si, &r, mc);
-
- errno = save_errno;
}
/*
{
ucontext_t *uc = p;
mcontext_t *mc = &uc->uc_mcontext;
+ int save_errno = errno;
(*handlers[sig])(sig, (struct siginfo *)si, mc);
+
+ errno = save_errno;
}
void set_handler(int sig)