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