blob: a1beaf0666f4de3dd11fa8bd01990c8cdf6e7450 [file] [log] [blame]
yaberauneya7b3f2222009-11-26 12:04:07 +00001/*
2 * Copyright (c) 2009 Cisco Systems, Inc. All Rights Reserved.
Garrett Coopercdb5d0f2010-02-26 04:55:11 -08003 * Copyright (c) 2009 FUJITSU LIMITED. All Rights Reserved.
yaberauneya7b3f2222009-11-26 12:04:07 +00004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * Further, this software is distributed without any warranty that it is
14 * free of the rightful claim of any third person regarding infringement
15 * or the like. Any license provided herein, whether implied or
16 * otherwise, applies only to this software file. Patent licenses, if
17 * any, provided herein do not apply to combinations of this program with
18 * other software, or any other product whatsoever.
19 *
20 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080021 * with this program; if not, write the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
yaberauneya7b3f2222009-11-26 12:04:07 +000023 *
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080024 * Author: Liu Bo <liubo2009@cn.fujitsu.com>
25 * Author: Garrett Cooper <yanegomi@gmail.com>
26 *
yaberauneya7b3f2222009-11-26 12:04:07 +000027 */
28
29#ifndef __LTP_SIGNAL_H
30#define __LTP_SIGNAL_H
31
yaberauneya402ec1f2009-11-30 20:38:48 +000032#include <errno.h>
yaberauneya7b3f2222009-11-26 12:04:07 +000033#include <signal.h>
yaberauneya402ec1f2009-11-30 20:38:48 +000034#include <stdio.h>
35#include "config.h"
yaberauneya7b3f2222009-11-26 12:04:07 +000036
37#define SIGSETSIZE (_NSIG / 8)
38
yaberauneya402ec1f2009-11-30 20:38:48 +000039#ifdef LTP_RT_SIG_TEST
40
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080041#ifdef __x86_64__
yaberauneya402ec1f2009-11-30 20:38:48 +000042
43/*
44 * From asm/signal.h -- this value isn't exported anywhere outside of glibc and
45 * asm/signal.h and is only required for the rt_sig* function family because
46 * sigaction(2), et all, appends this if necessary to
47 * (struct sigaction).sa_flags. HEH.
48 *
49 * I do #undef though, just in case...
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080050 *
51 * Also, from .../arch/x86/kernel/signal.c:448 for v2.6.30 (something or
52 * other):
yaberauneya402ec1f2009-11-30 20:38:48 +000053 *
54 * x86-64 should always use SA_RESTORER.
55 *
56 * -- thus SA_RESTORER must always be defined along with
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080057 * (struct sigaction).sa_restorer for this architecture.
yaberauneya402ec1f2009-11-30 20:38:48 +000058 */
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080059#undef SA_RESTORER
60#define HAVE_SA_RESTORER
61#define SA_RESTORER 0x04000000
yaberauneya402ec1f2009-11-30 20:38:48 +000062
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080063struct kernel_sigaction {
Garrett Cooper181f8dc2010-02-26 20:23:40 -080064 __sighandler_t k_sa_handler;
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080065 unsigned long sa_flags;
66 void (*sa_restorer) (void);
67 sigset_t sa_mask;
68};
yaberauneya402ec1f2009-11-30 20:38:48 +000069
Cyril Hrubisf8b7fd82012-10-04 14:29:22 +020070void (*restore_rt)(void);
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080071
Cyril Hrubisf8b7fd82012-10-04 14:29:22 +020072static void handler_h(int signal)
yaberauneya402ec1f2009-11-30 20:38:48 +000073{
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080074 return;
yaberauneya402ec1f2009-11-30 20:38:48 +000075}
76
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080077/* Setup an initial signal handler for signal number = sig for x86_64. */
Cyril Hrubisf8b7fd82012-10-04 14:29:22 +020078static inline int sig_initial(int sig)
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080079{
Garrett Cooper181f8dc2010-02-26 20:23:40 -080080 int ret_code = -1;
Garrett Coopercdb5d0f2010-02-26 04:55:11 -080081 struct sigaction act, oact;
82
83 act.sa_handler = handler_h;
Garrett Cooper181f8dc2010-02-26 20:23:40 -080084 /* Clear out the signal set. */
85 if (sigemptyset(&act.sa_mask) < 0) {
86 /* Add the signal to the mask set. */
87 } else if (sigaddset(&act.sa_mask, sig) < 0) {
88 /* Set act.sa_restorer via syscall(2) */
89 } else if (sigaction(sig, &act, &oact) < 0) {
90 /* Copy oact.sa_restorer via syscall(2) */
91 } else if (sigaction(sig, &act, &oact) < 0) {
92 /* And voila -- we just tricked the kernel into giving us our
93 * restorer function! */
94 } else {
95 restore_rt = oact.sa_restorer;
96 ret_code = 0;
97 }
98
99 return ret_code;
100
Garrett Coopercdb5d0f2010-02-26 04:55:11 -0800101}
102
103#endif /* __x86_64__ */
104
105#endif /* LTP_RT_SIG_TEST */
yaberauneya402ec1f2009-11-30 20:38:48 +0000106
yaberauneya7b3f2222009-11-26 12:04:07 +0000107#endif