mpn_submul_1 for x86-64.
[glibc/history.git] / stdio-common / psiginfo.c
blob9fc2911fd182c2251ab24bcaeacb46e49eb051e8
1 /* Copyright (C) 2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <libintl.h>
20 #include <signal.h>
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <not-cancel.h>
29 /* Defined in sys_siglist.c. */
30 extern const char *const _sys_siglist[];
31 extern const char *const _sys_siglist_internal[] attribute_hidden;
34 #define MF(l) MF1 (l)
35 #define MF1(l) str_##l
36 #define C(s1, s2) C1 (s1, s2)
37 #define C1(s1, s2) s1##s2
39 #define NOW SIGILL
40 #include "psiginfo-define.h"
42 #define NOW SIGFPE
43 #include "psiginfo-define.h"
45 #define NOW SIGSEGV
46 #include "psiginfo-define.h"
48 #define NOW SIGBUS
49 #include "psiginfo-define.h"
51 #define NOW SIGTRAP
52 #include "psiginfo-define.h"
54 #define NOW SIGCLD
55 #include "psiginfo-define.h"
57 #define NOW SIGPOLL
58 #include "psiginfo-define.h"
61 /* Print out on stderr a line consisting of the test in S, a colon, a space,
62 a message describing the meaning of the signal number PINFO and a newline.
63 If S is NULL or "", the colon and space are omitted. */
64 void
65 psiginfo (const siginfo_t *pinfo, const char *s)
67 char buf[512];
68 FILE *fp = fmemopen (buf, sizeof (buf), "w");
69 if (fp == NULL)
71 const char *colon;
73 if (s == NULL || *s == '\0')
74 s = colon = "";
75 else
76 colon = ": ";
78 __fxprintf (NULL, "%s%ssignal %d\n", s, colon, pinfo->si_signo);
79 return;
82 if (s != NULL && *s != '\0')
83 fprintf (fp, "%s: ", s);
85 const char *desc;
86 if (pinfo->si_signo >= 0 && pinfo->si_signo < NSIG
87 && (desc = INTUSE(_sys_siglist)[pinfo->si_signo]) != NULL)
89 fprintf (fp, "%s (", _(desc));
91 const char *base = NULL;
92 const uint8_t *offarr = NULL;
93 size_t offarr_len = 0;
94 switch (pinfo->si_signo)
96 #define H(sig) \
97 case sig: \
98 base = C(codestrs_, sig).str; \
99 offarr = C (codes_, sig); \
100 offarr_len = sizeof (C (codes_, sig)) / sizeof (C (codes_, sig)[0]);\
101 break
103 H (SIGILL);
104 H (SIGFPE);
105 H (SIGSEGV);
106 H (SIGBUS);
107 H (SIGTRAP);
108 H (SIGCHLD);
109 H (SIGPOLL);
112 const char *str = NULL;
113 if (offarr != NULL
114 && pinfo->si_code >= 1 && pinfo->si_code <= offarr_len)
115 str = base + offarr[pinfo->si_code - 1];
116 else
117 switch (pinfo->si_code)
119 case SI_USER:
120 str = N_("Signal sent by kill()");
121 break;
122 case SI_QUEUE:
123 str = N_("Signal sent by sigqueue()");
124 break;
125 case SI_TIMER:
126 str = N_("Signal generated by the expiration of a timer");
127 break;
128 case SI_ASYNCIO:
129 str = N_("\
130 Signal generated by the completion of an asynchronous I/O request");
131 break;
132 case SI_MESGQ:
133 str = N_("\
134 Signal generated by the arrival of a message on an empty message queue");
135 break;
136 #ifdef SI_TKILL
137 case SI_TKILL:
138 str = N_("Signal sent by tkill()");
139 break;
140 #endif
141 #ifdef SI_ASYNCNL
142 case SI_ASYNCNL:
143 str = N_("\
144 Signal generated by the completion of an asynchronous name lookup request");
145 break;
146 #endif
147 #ifdef SI_SIGIO
148 case SI_SIGIO:
149 str = N_("\
150 Signal generated by the completion of an I/O request");
151 break;
152 #endif
153 #ifdef SI_KERNEL
154 case SI_KERNEL:
155 str = N_("Signal sent by the kernel");
156 break;
157 #endif
160 if (str != NULL)
161 fprintf (fp, "%s ", _(str));
162 else
163 fprintf (fp, "%d ", pinfo->si_code);
165 if (pinfo->si_signo == SIGILL || pinfo->si_signo == SIGFPE
166 || pinfo->si_signo == SIGSEGV || pinfo->si_signo == SIGBUS)
167 fprintf (fp, "[%p])", pinfo->si_addr);
168 else if (pinfo->si_signo == SIGCHLD)
169 fprintf (fp, "%ld %d %ld)", (long int) pinfo->si_pid, pinfo->si_status,
170 (long int) pinfo->si_uid);
171 else if (pinfo->si_signo == SIGPOLL)
172 fprintf (fp, "%ld)", pinfo->si_band);
173 else
174 fprintf (fp, "%ld %ld)",
175 (long int) pinfo->si_pid, (long int) pinfo->si_uid);
177 else
178 fprintf (fp, _("Unknown signal %d\n"), pinfo->si_signo);
180 fclose (fp);
182 write_not_cancel (STDERR_FILENO, buf, strlen (buf));