VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
97870c34b4532 (Alex Dewar         2019-08-25 10:49:18 +0100   1) // SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   2) /*
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000   3)  * Copyright (C) 2015 Anton Ivanov (aivanov@{brocade.com,kot-begemot.co.uk})
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000   4)  * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   5)  * Copyright (C) 2004 PathScale, Inc
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700   6)  * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   7)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   8) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800   9) #include <stdlib.h>
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800  10) #include <stdarg.h>
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700  11) #include <errno.h>
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700  12) #include <signal.h>
b8f7882028ec6 (Johannes Berg      2019-08-23 12:44:27 +0200  13) #include <string.h>
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700  14) #include <strings.h>
37185b3324087 (Al Viro            2012-10-08 03:27:32 +0100  15) #include <as-layout.h>
37185b3324087 (Al Viro            2012-10-08 03:27:32 +0100  16) #include <kern_util.h>
37185b3324087 (Al Viro            2012-10-08 03:27:32 +0100  17) #include <os.h>
37185b3324087 (Al Viro            2012-10-08 03:27:32 +0100  18) #include <sysdep/mcontext.h>
57a05d83b1671 (Richard Weinberger 2016-06-12 22:03:16 +0200  19) #include <um_malloc.h>
530ba6c7cb3c2 (Jason A. Donenfeld 2017-12-14 03:23:37 +0100  20) #include <sys/ucontext.h>
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  21) #include <timetravel.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  22) 
72383d43b223c (Sergei Trofimovich 2012-12-30 01:37:31 +0300  23) void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = {
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  24) 	[SIGTRAP]	= relay_signal,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  25) 	[SIGFPE]	= relay_signal,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  26) 	[SIGILL]	= relay_signal,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  27) 	[SIGWINCH]	= winch,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  28) 	[SIGBUS]	= bus_handler,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  29) 	[SIGSEGV]	= segv_handler,
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  30) 	[SIGIO]		= sigio_handler,
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000  31) };
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  32) 
9a8c1359571c5 (Richard Weinberger 2013-07-19 11:31:36 +0200  33) static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  34) {
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000  35) 	struct uml_pt_regs r;
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800  36) 	int save_errno = errno;
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  37) 
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000  38) 	r.is_user = 0;
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  39) 	if (sig == SIGSEGV) {
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800  40) 		/* For segfaults, we want the data from the sigcontext. */
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000  41) 		get_regs_from_mc(&r, mc);
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000  42) 		GET_FAULTINFO_FROM_MC(r.faultinfo, mc);
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800  43) 	}
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  44) 
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800  45) 	/* enable signals if sig isn't IRQ signal */
68c15a2bc5658 (Johannes Berg      2019-08-23 12:44:26 +0200  46) 	if ((sig != SIGIO) && (sig != SIGWINCH))
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200  47) 		unblock_signals_trace();
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  48) 
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000  49) 	(*sig_info[sig])(sig, si, &r);
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  50) 
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  51) 	errno = save_errno;
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  52) }
75ada8ffe08ce (Jeff Dike          2008-02-04 22:31:12 -0800  53) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700  54) /*
61b63c556c087 (Jeff Dike          2007-10-16 01:27:27 -0700  55)  * These are the asynchronous signals.  SIGPROF is excluded because we want to
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  56)  * be able to profile all of UML, not just the non-critical sections.  If
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  57)  * profiling is not thread-safe, then that is not my problem.  We can disable
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  58)  * profiling when SMP is enabled in that case.
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  59)  */
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  60) #define SIGIO_BIT 0
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  61) #define SIGIO_MASK (1 << SIGIO_BIT)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  62) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000  63) #define SIGALRM_BIT 1
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000  64) #define SIGALRM_MASK (1 << SIGALRM_BIT)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  65) 
fbb42e7fe2c49 (Johannes Berg      2021-03-05 13:19:54 +0100  66) int signals_enabled;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  67) #ifdef UML_CONFIG_UML_TIME_TRAVEL_SUPPORT
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  68) static int signals_blocked;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  69) #else
39f75da7bcc82 (Alexey Dobriyan    2021-08-02 23:40:31 +0300  70) #define signals_blocked 0
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  71) #endif
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800  72) static unsigned int signals_pending;
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000  73) static unsigned int signals_active = 0;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  74) 
9a8c1359571c5 (Richard Weinberger 2013-07-19 11:31:36 +0200  75) void sig_handler(int sig, struct siginfo *si, mcontext_t *mc)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  76) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  77) 	int enabled = signals_enabled;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  78) 
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  79) 	if ((signals_blocked || !enabled) && (sig == SIGIO)) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  80) 		/*
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  81) 		 * In TT_MODE_EXTERNAL, need to still call time-travel
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  82) 		 * handlers unless signals are also blocked for the
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  83) 		 * external time message processing. This will mark
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  84) 		 * signals_pending by itself (only if necessary.)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  85) 		 */
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  86) 		if (!signals_blocked && time_travel_mode == TT_MODE_EXTERNAL)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  87) 			sigio_run_timetravel_handlers();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  88) 		else
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100  89) 			signals_pending |= SIGIO_MASK;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  90) 		return;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  91) 	}
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  92) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200  93) 	block_signals_trace();
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  94) 
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200  95) 	sig_handler_common(sig, si, mc);
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800  96) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200  97) 	set_signals_trace(enabled);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  98) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  99) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 100) static void timer_real_alarm_handler(mcontext_t *mc)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 101) {
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000 102) 	struct uml_pt_regs regs;
2ea5bc5e5bb51 (Jeff Dike          2007-05-10 22:22:32 -0700 103) 
248b74c79ebb9 (Al Viro            2011-08-18 20:05:09 +0100 104) 	if (mc != NULL)
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000 105) 		get_regs_from_mc(&regs, mc);
b8f7882028ec6 (Johannes Berg      2019-08-23 12:44:27 +0200 106) 	else
b8f7882028ec6 (Johannes Berg      2019-08-23 12:44:27 +0200 107) 		memset(&regs, 0, sizeof(regs));
5c2ffce1e9496 (Anton Ivanov       2019-01-04 15:38:21 +0000 108) 	timer_handler(SIGALRM, NULL, &regs);
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 109) }
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 110) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 111) void timer_alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 112) {
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 113) 	int enabled;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 114) 
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 115) 	enabled = signals_enabled;
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 116) 	if (!signals_enabled) {
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 117) 		signals_pending |= SIGALRM_MASK;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 118) 		return;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 119) 	}
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 120) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 121) 	block_signals_trace();
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 122) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 123) 	signals_active |= SIGALRM_MASK;
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 124) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 125) 	timer_real_alarm_handler(mc);
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 126) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 127) 	signals_active &= ~SIGALRM_MASK;
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 128) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 129) 	set_signals_trace(enabled);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 130) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 131) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 132) void deliver_alarm(void) {
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 133)     timer_alarm_handler(SIGALRM, NULL, NULL);
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 134) }
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 135) 
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 136) void timer_set_signal_handler(void)
78a26e25ce483 (Jeff Dike          2007-10-16 01:27:23 -0700 137) {
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 138) 	set_handler(SIGALRM);
78a26e25ce483 (Jeff Dike          2007-10-16 01:27:23 -0700 139) }
78a26e25ce483 (Jeff Dike          2007-10-16 01:27:23 -0700 140) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 141) void set_sigstack(void *sig_stack, int size)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 142) {
9a75551aeaa8c (Hans-Werner Hilse  2015-06-11 11:29:18 +0200 143) 	stack_t stack = {
9a75551aeaa8c (Hans-Werner Hilse  2015-06-11 11:29:18 +0200 144) 		.ss_flags = 0,
9a75551aeaa8c (Hans-Werner Hilse  2015-06-11 11:29:18 +0200 145) 		.ss_sp = sig_stack,
558f9b2f94dbd (YiFei Zhu          2021-04-20 00:56:10 -0500 146) 		.ss_size = size
9a75551aeaa8c (Hans-Werner Hilse  2015-06-11 11:29:18 +0200 147) 	};
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 148) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 149) 	if (sigaltstack(&stack, NULL) != 0)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 150) 		panic("enabling signal stack failed, errno = %d\n", errno);
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 151) }
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 152) 
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 153) static void sigusr1_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 154) {
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 155) 	uml_pm_wake();
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 156) }
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 157) 
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 158) void register_pm_wake_signal(void)
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 159) {
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 160) 	set_handler(SIGUSR1);
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 161) }
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 162) 
9a8c1359571c5 (Richard Weinberger 2013-07-19 11:31:36 +0200 163) static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = {
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 164) 	[SIGSEGV] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 165) 	[SIGBUS] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 166) 	[SIGILL] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 167) 	[SIGFPE] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 168) 	[SIGTRAP] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 169) 
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 170) 	[SIGIO] = sig_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 171) 	[SIGWINCH] = sig_handler,
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 172) 	[SIGALRM] = timer_alarm_handler,
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 173) 
92dcd3d31843f (Johannes Berg      2020-12-02 20:58:06 +0100 174) 	[SIGUSR1] = sigusr1_handler,
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 175) };
4b84c69b5f6c0 (Jeff Dike          2006-09-25 23:33:04 -0700 176) 
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200 177) static void hard_handler(int sig, siginfo_t *si, void *p)
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 178) {
4d1a535b8ec5e (Krzysztof Mazur    2017-11-15 11:12:39 +0100 179) 	ucontext_t *uc = p;
248b74c79ebb9 (Al Viro            2011-08-18 20:05:09 +0100 180) 	mcontext_t *mc = &uc->uc_mcontext;
508a92741a105 (Jeff Dike          2007-09-18 22:46:49 -0700 181) 	unsigned long pending = 1UL << sig;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 182) 
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 183) 	do {
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 184) 		int nested, bail;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 185) 
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 186) 		/*
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 187) 		 * pending comes back with one bit set for each
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 188) 		 * interrupt that arrived while setting up the stack,
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 189) 		 * plus a bit for this interrupt, plus the zero bit is
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 190) 		 * set if this is a nested interrupt.
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 191) 		 * If bail is true, then we interrupted another
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 192) 		 * handler setting up the stack.  In this case, we
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 193) 		 * have to return, and the upper handler will deal
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 194) 		 * with this interrupt.
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 195) 		 */
508a92741a105 (Jeff Dike          2007-09-18 22:46:49 -0700 196) 		bail = to_irq_stack(&pending);
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 197) 		if (bail)
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 198) 			return;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 199) 
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 200) 		nested = pending & 1;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 201) 		pending &= ~1;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 202) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 203) 		while ((sig = ffs(pending)) != 0){
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 204) 			sig--;
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 205) 			pending &= ~(1 << sig);
9a8c1359571c5 (Richard Weinberger 2013-07-19 11:31:36 +0200 206) 			(*handlers[sig])(sig, (struct siginfo *)si, mc);
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 207) 		}
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 208) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 209) 		/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 210) 		 * Again, pending comes back with a mask of signals
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 211) 		 * that arrived while tearing down the stack.  If this
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 212) 		 * is non-zero, we just go back, set up the stack
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 213) 		 * again, and handle the new interrupts.
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 214) 		 */
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 215) 		if (!nested)
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 216) 			pending = from_irq_stack(nested);
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 217) 	} while (pending);
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 218) }
c14b84949e127 (Jeff Dike          2007-05-10 22:22:34 -0700 219) 
00361683ce562 (Al Viro            2011-08-18 20:04:39 +0100 220) void set_handler(int sig)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 221) {
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 222) 	struct sigaction action;
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 223) 	int flags = SA_SIGINFO | SA_ONSTACK;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 224) 	sigset_t sig_mask;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 225) 
7eb122555c858 (Al Viro            2011-08-18 20:03:39 +0100 226) 	action.sa_sigaction = hard_handler;
4b84c69b5f6c0 (Jeff Dike          2006-09-25 23:33:04 -0700 227) 
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 228) 	/* block irq ones */
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 229) 	sigemptyset(&action.sa_mask);
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 230) 	sigaddset(&action.sa_mask, SIGIO);
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 231) 	sigaddset(&action.sa_mask, SIGWINCH);
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 232) 	sigaddset(&action.sa_mask, SIGALRM);
4b84c69b5f6c0 (Jeff Dike          2006-09-25 23:33:04 -0700 233) 
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800 234) 	if (sig == SIGSEGV)
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800 235) 		flags |= SA_NODEFER;
e6a2d1f7024f9 (Jeff Dike          2008-02-04 22:31:13 -0800 236) 
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 237) 	if (sigismember(&action.sa_mask, sig))
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 238) 		flags |= SA_RESTART; /* if it's an irq signal */
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 239) 
e87df986ed053 (Al Viro            2011-08-18 20:04:29 +0100 240) 	action.sa_flags = flags;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 241) 	action.sa_restorer = NULL;
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 242) 	if (sigaction(sig, &action, NULL) < 0)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 243) 		panic("sigaction failed - errno = %d\n", errno);
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 244) 
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 245) 	sigemptyset(&sig_mask);
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 246) 	sigaddset(&sig_mask, sig);
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 247) 	if (sigprocmask(SIG_UNBLOCK, &sig_mask, NULL) < 0)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 248) 		panic("sigprocmask failed - errno = %d\n", errno);
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 249) }
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 250) 
a374b7cb1ea64 (Johannes Berg      2020-12-02 20:58:07 +0100 251) void send_sigio_to_self(void)
a374b7cb1ea64 (Johannes Berg      2020-12-02 20:58:07 +0100 252) {
a374b7cb1ea64 (Johannes Berg      2020-12-02 20:58:07 +0100 253) 	kill(os_getpid(), SIGIO);
a374b7cb1ea64 (Johannes Berg      2020-12-02 20:58:07 +0100 254) }
a374b7cb1ea64 (Johannes Berg      2020-12-02 20:58:07 +0100 255) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 256) int change_sig(int signal, int on)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 257) {
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 258) 	sigset_t sigset;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 259) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 260) 	sigemptyset(&sigset);
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 261) 	sigaddset(&sigset, signal);
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 262) 	if (sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, NULL) < 0)
c9a3072d13e4b (WANG Cong          2008-02-04 22:30:35 -0800 263) 		return -errno;
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 264) 
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 265) 	return 0;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 266) }
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 267) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 268) void block_signals(void)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 269) {
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 270) 	signals_enabled = 0;
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 271) 	/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 272) 	 * This must return with signals disabled, so this barrier
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 273) 	 * ensures that writes are flushed out before the return.
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 274) 	 * This might matter if gcc figures out how to inline this and
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 275) 	 * decides to shuffle this code into the caller.
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 276) 	 */
fce8c41c9f68b (Jeff Dike          2008-02-04 22:31:09 -0800 277) 	barrier();
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 278) }
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 279) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 280) void unblock_signals(void)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 281) {
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 282) 	int save_pending;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 283) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 284) 	if (signals_enabled == 1)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 285) 		return;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 286) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 287) 	signals_enabled = 1;
11385539c024b (Johannes Berg      2020-12-13 22:18:18 +0100 288) #ifdef UML_CONFIG_UML_TIME_TRAVEL_SUPPORT
11385539c024b (Johannes Berg      2020-12-13 22:18:18 +0100 289) 	deliver_time_travel_irqs();
11385539c024b (Johannes Berg      2020-12-13 22:18:18 +0100 290) #endif
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 291) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 292) 	/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 293) 	 * We loop because the IRQ handler returns with interrupts off.  So,
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 294) 	 * interrupts may have arrived and we need to re-enable them and
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 295) 	 * recheck signals_pending.
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 296) 	 */
5134d8fea06ab (Jeff Dike          2008-02-08 04:22:08 -0800 297) 	while (1) {
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 298) 		/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 299) 		 * Save and reset save_pending after enabling signals.  This
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 300) 		 * way, signals_pending won't be changed while we're reading it.
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 301) 		 *
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 302) 		 * Setting signals_enabled and reading signals_pending must
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 303) 		 * happen in this order, so have the barrier here.
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 304) 		 */
fce8c41c9f68b (Jeff Dike          2008-02-04 22:31:09 -0800 305) 		barrier();
53b173327d283 (Jeff Dike          2006-11-02 22:07:22 -0800 306) 
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 307) 		save_pending = signals_pending;
fce8c41c9f68b (Jeff Dike          2008-02-04 22:31:09 -0800 308) 		if (save_pending == 0)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 309) 			return;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 310) 
cfef8f34e7cf5 (Jeff Dike          2008-02-04 22:31:16 -0800 311) 		signals_pending = 0;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 312) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 313) 		/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 314) 		 * We have pending interrupts, so disable signals, as the
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 315) 		 * handlers expect them off when they are called.  They will
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 316) 		 * be enabled again above. We need to trace this, as we're
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 317) 		 * expected to be enabling interrupts already, but any more
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 318) 		 * tracing that happens inside the handlers we call for the
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 319) 		 * pending signals will mess up the tracing state.
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 320) 		 */
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 321) 		signals_enabled = 0;
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 322) 		um_trace_signals_off();
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 323) 
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 324) 		/*
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 325) 		 * Deal with SIGIO first because the alarm handler might
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 326) 		 * schedule, leaving the pending SIGIO stranded until we come
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 327) 		 * back here.
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200 328) 		 *
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200 329) 		 * SIGIO's handler doesn't use siginfo or mcontext,
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200 330) 		 * so they can be NULL.
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 331) 		 */
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 332) 		if (save_pending & SIGIO_MASK)
d3c1cfcdb43e0 (Martin Pärtel      2012-08-02 00:49:17 +0200 333) 			sig_handler_common(SIGIO, NULL, NULL);
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 334) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 335) 		/* Do not reenter the handler */
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 336) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 337) 		if ((save_pending & SIGALRM_MASK) && (!(signals_active & SIGALRM_MASK)))
2eb5f31bc4ea2 (Anton Ivanov       2015-11-02 16:16:37 +0000 338) 			timer_real_alarm_handler(NULL);
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 339) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 340) 		/* Rerun the loop only if there is still pending SIGIO and not in TIMER handler */
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 341) 
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 342) 		if (!(signals_pending & SIGIO_MASK) && (signals_active & SIGALRM_MASK))
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 343) 			return;
d5e3f5cbe5cee (Anton Ivanov       2015-12-21 11:28:02 +0000 344) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 345) 		/* Re-enable signals and trace that we're doing so. */
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 346) 		um_trace_signals_on();
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 347) 		signals_enabled = 1;
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 348) 	}
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 349) }
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 350) 
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 351) int set_signals(int enable)
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 352) {
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 353) 	int ret;
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 354) 	if (signals_enabled == enable)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 355) 		return enable;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 356) 
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 357) 	ret = signals_enabled;
ba180fd437156 (Jeff Dike          2007-10-16 01:27:00 -0700 358) 	if (enable)
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 359) 		unblock_signals();
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 360) 	else block_signals();
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 361) 
1d7173baf286c (Jeff Dike          2006-01-18 17:42:49 -0800 362) 	return ret;
0805d89c151b4 (Gennady Sharapov   2006-01-08 01:01:29 -0800 363) }
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 364) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 365) int set_signals_trace(int enable)
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 366) {
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 367) 	int ret;
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 368) 	if (signals_enabled == enable)
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 369) 		return enable;
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 370) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 371) 	ret = signals_enabled;
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 372) 	if (enable)
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 373) 		unblock_signals_trace();
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 374) 	else
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 375) 		block_signals_trace();
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 376) 
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 377) 	return ret;
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 378) }
0dafcbe128d2a (Johannes Berg      2019-08-23 13:16:23 +0200 379) 
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 380) #ifdef UML_CONFIG_UML_TIME_TRAVEL_SUPPORT
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 381) void mark_sigio_pending(void)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 382) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 383) 	signals_pending |= SIGIO_MASK;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 384) }
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 385) 
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 386) void block_signals_hard(void)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 387) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 388) 	if (signals_blocked)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 389) 		return;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 390) 	signals_blocked = 1;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 391) 	barrier();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 392) }
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 393) 
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 394) void unblock_signals_hard(void)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 395) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 396) 	if (!signals_blocked)
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 397) 		return;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 398) 	/* Must be set to 0 before we check the pending bits etc. */
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 399) 	signals_blocked = 0;
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 400) 	barrier();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 401) 
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 402) 	if (signals_pending && signals_enabled) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 403) 		/* this is a bit inefficient, but that's not really important */
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 404) 		block_signals();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 405) 		unblock_signals();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 406) 	} else if (signals_pending & SIGIO_MASK) {
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 407) 		/* we need to run time-travel handlers even if not enabled */
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 408) 		sigio_run_timetravel_handlers();
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 409) 	}
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 410) }
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 411) #endif
d6b399a0e02a9 (Johannes Berg      2021-03-05 13:19:56 +0100 412) 
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 413) int os_is_signal_stack(void)
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 414) {
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 415) 	stack_t ss;
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 416) 	sigaltstack(NULL, &ss);
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 417) 
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 418) 	return ss.ss_flags & SS_ONSTACK;
f72c22e45e8f8 (Richard Weinberger 2013-09-23 17:38:02 +0200 419) }