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 | |
| 37 | #define SIGSETSIZE (_NSIG / 8) |
| 38 | |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 39 | #ifdef LTP_RT_SIG_TEST |
| 40 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 41 | #ifdef __x86_64__ |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 42 | |
| 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 Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 50 | * |
| 51 | * Also, from .../arch/x86/kernel/signal.c:448 for v2.6.30 (something or |
| 52 | * other): |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 53 | * |
| 54 | * x86-64 should always use SA_RESTORER. |
| 55 | * |
| 56 | * -- thus SA_RESTORER must always be defined along with |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 57 | * (struct sigaction).sa_restorer for this architecture. |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 58 | */ |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 59 | #undef SA_RESTORER |
| 60 | #define HAVE_SA_RESTORER |
| 61 | #define SA_RESTORER 0x04000000 |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 62 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 63 | struct kernel_sigaction { |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 64 | __sighandler_t k_sa_handler; |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 65 | unsigned long sa_flags; |
| 66 | void (*sa_restorer) (void); |
| 67 | sigset_t sa_mask; |
| 68 | }; |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 69 | |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 70 | void (*restore_rt)(void); |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 71 | |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 72 | static void handler_h(int signal) |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 73 | { |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 74 | return; |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 77 | /* Setup an initial signal handler for signal number = sig for x86_64. */ |
Cyril Hrubis | f8b7fd8 | 2012-10-04 14:29:22 +0200 | [diff] [blame] | 78 | static inline int sig_initial(int sig) |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 79 | { |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 80 | int ret_code = -1; |
Garrett Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 81 | struct sigaction act, oact; |
| 82 | |
| 83 | act.sa_handler = handler_h; |
Garrett Cooper | 181f8dc | 2010-02-26 20:23:40 -0800 | [diff] [blame] | 84 | /* 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 Cooper | cdb5d0f | 2010-02-26 04:55:11 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #endif /* __x86_64__ */ |
| 104 | |
| 105 | #endif /* LTP_RT_SIG_TEST */ |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 106 | |
yaberauneya | 7b3f222 | 2009-11-26 12:04:07 +0000 | [diff] [blame] | 107 | #endif |