blob: bb07eee412cb9e9790a37e136df2aae8a42e5937 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18
19 Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
20 */
21
22#include <errno.h>
23#include <signal.h>
24#include <string.h>
25#include <sys/syscall.h>
26#include <bits/kernel_sigaction.h>
27
28#define SA_RESTORER 0x04000000
29
30extern __typeof(sigaction) __libc_sigaction;
31
32
33#ifdef __NR_rt_sigaction
34
35# if _MIPS_SIM != _ABIO32
36# ifdef __NR_rt_sigreturn
37static void restore_rt(void) __asm__ ("__restore_rt");
38# endif
39# ifdef __NR_sigreturn
40static void restore(void) __asm__ ("__restore");
41# endif
42# endif
43
44/* If ACT is not NULL, change the action for SIG to *ACT.
45 If OACT is not NULL, put the old action for SIG in *OACT. */
46int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
47{
48# if _MIPS_SIM != _ABIO32
49 struct sigaction kact;
50 if (act) {
51 memcpy(&kact, act, sizeof(kact));
52 kact.sa_restorer = &restore_rt;
53 act = &kact;
54 }
55# endif
56
57 /* NB: kernel (as of 2.6.25) will return EINVAL
58 * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
59 return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
60}
61
62#else
63
64extern void restore(void) __asm__ ("__restore") attribute_hidden;
65
66/* If ACT is not NULL, change the action for SIG to *ACT.
67 If OACT is not NULL, put the old action for SIG in *OACT. */
68int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
69{
70 int result;
71 struct old_kernel_sigaction kact, koact;
72
73 if (act) {
74 kact.k_sa_handler = act->sa_handler;
75 kact.sa_mask = act->sa_mask.__val[0];
76 kact.sa_flags = act->sa_flags;
77# if _MIPS_SIM == _ABIO32
78 kact.sa_restorer = act->sa_restorer;
79# else
80 kact.sa_restorer = &restore_rt;
81# endif
82 }
83 result = __syscall_sigaction(sig,
84 act ? &kact : NULL,
85 oact ? &koact : NULL);
86 if (result < 0) {
87 __set_errno(-result);
88 return -1;
89 }
90 if (oact) {
91 oact->sa_handler = koact.k_sa_handler;
92 oact->sa_mask.__val[0] = koact.sa_mask;
93 oact->sa_flags = koact.sa_flags;
94 oact->sa_restorer = koact.sa_restorer;
95 }
96 return result;
97}
98
99#endif
100
101
102#ifndef LIBC_SIGACTION
103# ifndef __UCLIBC_HAS_THREADS__
104strong_alias(__libc_sigaction,sigaction)
105libc_hidden_def(sigaction)
106# else
107weak_alias(__libc_sigaction,sigaction)
108libc_hidden_weak(sigaction)
109# endif
110#endif
111
112
113/* NOTE: Please think twice before making any changes to the bits of
114 code below. GDB needs some intimate knowledge about it to
115 recognize them as signal trampolines, and make backtraces through
116 signal handlers work right. Important are both the names
117 (__restore_rt) and the exact instruction sequence.
118 If you ever feel the need to make any changes, please notify the
119 appropriate GDB maintainer. */
120
121#define RESTORE(name, syscall) RESTORE2(name, syscall)
122#define RESTORE2(name, syscall) \
123__asm__ ( \
124 ".align 4\n" \
125 "__" #name ":\n" \
126 " li $2, " #syscall "\n" \
127 " syscall\n" \
128);
129
130/* The return code for realtime-signals. */
131#if _MIPS_SIM != _ABIO32
132# ifdef __NR_rt_sigreturn
133RESTORE(restore_rt, __NR_rt_sigreturn)
134# endif
135# ifdef __NR_sigreturn
136RESTORE(restore, __NR_sigreturn)
137# endif
138#endif