yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Cisco Systems, Inc. All Rights Reserved. |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2009 FUJITSU LIMITED. All Rights Reserved. |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 4 | * |
| 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 Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 21 | * with this program; if not, write the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 23 | * |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 24 | * Author: Liu Bo <liubo2009@cn.fujitsu.com> |
| 25 | * Author: Garrett Cooper <yanegomi@gmail.com> |
| 26 | * |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #ifndef __LTP_SIGNAL_H |
| 30 | #define __LTP_SIGNAL_H |
| 31 | |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 32 | #include <errno.h> |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 33 | #include <signal.h> |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 34 | #include <stdio.h> |
| 35 | #include "config.h" |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 36 | |
Stanislav Kholmanskikh | 0eccc58 | 2013-08-14 11:31:41 +0400 | [diff] [blame] | 37 | /* |
| 38 | * For all but __mips__: |
| 39 | * |
| 40 | * _COMPAT_NSIG / _COMPAT_NSIG_BPW == 2. |
| 41 | * |
| 42 | * For __mips__: |
| 43 | * |
| 44 | * _COMPAT_NSIG / _COMPAT_NSIG_BPW == 4. |
| 45 | * |
| 46 | * See asm/compat.h under the kernel source for more details. |
| 47 | * |
| 48 | * Multiply that by a fudge factor of 4 and you have your SIGSETSIZE. |
| 49 | */ |
| 50 | #if defined __mips__ |
| 51 | #define SIGSETSIZE 16 |
| 52 | #else |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 53 | #define SIGSETSIZE (_NSIG / 8) |
Stanislav Kholmanskikh | 0eccc58 | 2013-08-14 11:31:41 +0400 | [diff] [blame] | 54 | #endif |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 55 | |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 56 | #ifdef LTP_RT_SIG_TEST |
| 57 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 58 | #ifdef __x86_64__ |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * From asm/signal.h -- this value isn't exported anywhere outside of glibc and |
| 62 | * asm/signal.h and is only required for the rt_sig* function family because |
| 63 | * sigaction(2), et all, appends this if necessary to |
| 64 | * (struct sigaction).sa_flags. HEH. |
| 65 | * |
| 66 | * I do #undef though, just in case... |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 67 | * |
| 68 | * Also, from .../arch/x86/kernel/signal.c:448 for v2.6.30 (something or |
| 69 | * other): |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 70 | * |
| 71 | * x86-64 should always use SA_RESTORER. |
| 72 | * |
| 73 | * -- thus SA_RESTORER must always be defined along with |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 74 | * (struct sigaction).sa_restorer for this architecture. |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 75 | */ |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 76 | #undef SA_RESTORER |
| 77 | #define HAVE_SA_RESTORER |
| 78 | #define SA_RESTORER 0x04000000 |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 79 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 80 | struct kernel_sigaction { |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 81 | __sighandler_t k_sa_handler; |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 82 | unsigned long sa_flags; |
| 83 | void (*sa_restorer) (void); |
| 84 | sigset_t sa_mask; |
| 85 | }; |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 86 | |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 87 | void (*restore_rt)(void); |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 88 | |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 89 | static void handler_h(int signal) |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 90 | { |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 91 | return; |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 94 | /* Setup an initial signal handler for signal number = sig for x86_64. */ |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 95 | static inline int sig_initial(int sig) |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 96 | { |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 97 | int ret_code = -1; |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 98 | struct sigaction act, oact; |
| 99 | |
| 100 | act.sa_handler = handler_h; |
Jan Stancek | c5532e4 | 2013-05-14 11:59:33 +0200 | [diff] [blame] | 101 | act.sa_flags = 0; |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 102 | /* Clear out the signal set. */ |
| 103 | if (sigemptyset(&act.sa_mask) < 0) { |
| 104 | /* Add the signal to the mask set. */ |
| 105 | } else if (sigaddset(&act.sa_mask, sig) < 0) { |
| 106 | /* Set act.sa_restorer via syscall(2) */ |
| 107 | } else if (sigaction(sig, &act, &oact) < 0) { |
| 108 | /* Copy oact.sa_restorer via syscall(2) */ |
| 109 | } else if (sigaction(sig, &act, &oact) < 0) { |
| 110 | /* And voila -- we just tricked the kernel into giving us our |
| 111 | * restorer function! */ |
| 112 | } else { |
| 113 | restore_rt = oact.sa_restorer; |
| 114 | ret_code = 0; |
| 115 | } |
| 116 | |
| 117 | return ret_code; |
| 118 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | #endif /* __x86_64__ */ |
| 122 | |
| 123 | #endif /* LTP_RT_SIG_TEST */ |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 124 | |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 125 | #endif |