]>
Commit | Line | Data |
---|---|---|
e3366964 AM |
1 | From 9cf12d57c58a82cfe3e6fee26d1ea55dfe49f9c4 Mon Sep 17 00:00:00 2001 |
2 | From: Pedro Alves <palves@redhat.com> | |
3 | Date: Tue, 26 Jul 2016 19:35:40 +0100 | |
4 | Subject: [PATCH] Fix PR gdb/20287 - x32 and "gdb_static_assert (sizeof (nat_siginfo_t) == sizeof (siginfo_t))" | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=utf8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | Building an x32 gdb trips on a static assertion: | |
10 | ||
11 | In file included from .../src/gdb/common/common-defs.h:71:0, | |
12 | from .../src/gdb/nat/amd64-linux-siginfo.c:21: | |
13 | .../src/gdb/common/gdb_assert.h:26:66: error: size of array â\80\98never_defined_just_used_for_checkingâ\80\99 is negative | |
14 | extern int never_defined_just_used_for_checking[(expr) ? 1 : -1] | |
15 | ^ | |
16 | .../src/gdb/nat/amd64-linux-siginfo.c:113:1: note: in expansion of macro â\80\98gdb_static_assertâ\80\99 | |
17 | gdb_static_assert (sizeof (nat_siginfo_t) == sizeof (siginfo_t)); | |
18 | ^ | |
19 | ||
20 | The problem is that the way nat_siginfo_t is defined, it can only | |
21 | match the host's siginfo_t object when gdb is built as a 64-bit | |
22 | program. | |
23 | ||
24 | Several bits of nat_siginfo_t are off: | |
25 | ||
26 | - nat_siginfo_t's _pad field's definition is: | |
27 | ||
28 | int _pad[((128 / sizeof (int)) - 4)]; | |
29 | ||
30 | while /usr/include/bits/siginfo.h has: | |
31 | ||
32 | # define __SI_MAX_SIZE 128 | |
33 | # if __WORDSIZE == 64 | |
34 | # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4) | |
35 | # else | |
36 | # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3) | |
37 | # endif | |
38 | ||
39 | and __WORDSIZE == 32 for x32. This is what causes the size of | |
40 | nat_siginfo_t to be wrong and the assertion to fail. | |
41 | ||
42 | - the nat_clock_t type is incorrect for 64-bit. We have this: | |
43 | ||
44 | /* For native 64-bit, clock_t in _sigchld is 64bit aligned at 4 bytes. */ | |
45 | typedef long __attribute__ ((__aligned__ (4))) nat_clock_t; | |
46 | ||
47 | however, /usr/include/bits/siginfo.h has: | |
48 | ||
49 | # if defined __x86_64__ && __WORDSIZE == 32 | |
50 | /* si_utime and si_stime must be 4 byte aligned for x32 to match the | |
51 | kernel. We align siginfo_t to 8 bytes so that si_utime and si_stime | |
52 | are actually aligned to 8 bytes since their offsets are multiple of | |
53 | 8 bytes. */ | |
54 | typedef __clock_t __attribute__ ((__aligned__ (4))) __sigchld_clock_t; | |
55 | # define __SI_ALIGNMENT __attribute__ ((__aligned__ (8))) | |
56 | # else | |
57 | typedef __clock_t __sigchld_clock_t; | |
58 | # define __SI_ALIGNMENT | |
59 | # endif | |
60 | ||
61 | So we're currently forcing 4-byte alignment on clock_t, when it | |
62 | should only be so for x32, not 64-bit. | |
63 | ||
64 | The fix: | |
65 | ||
66 | - Leaves nat_siginfo_t strictly for the 64-bit ABI. | |
67 | ||
68 | - Adds a new typedef for the siginfo type that ptrace uses | |
69 | (ptrace_siginfo_t). An x32 gdb always gets/sets an x32 siginfo_t | |
70 | type with PTRACE_GETSIGINFO/PTRACE_SETSIGINFO. | |
71 | ||
72 | - Uses this new ptrace_siginfo_t type instead of nat_siginfo_t as the | |
73 | intermediate conversion type. | |
74 | ||
75 | diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c | |
76 | index 391a646..fea6ee2 100644 | |
77 | --- a/gdb/amd64-linux-nat.c | |
78 | +++ b/gdb/amd64-linux-nat.c | |
79 | @@ -321,25 +321,25 @@ ps_get_thread_area (const struct ps_prochandle *ph, | |
80 | } | |
81 | \f | |
82 | ||
83 | -/* Convert a native/host siginfo object, into/from the siginfo in the | |
84 | +/* Convert a ptrace/host siginfo object, into/from the siginfo in the | |
85 | layout of the inferiors' architecture. Returns true if any | |
86 | conversion was done; false otherwise. If DIRECTION is 1, then copy | |
87 | - from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to | |
88 | + from INF to PTRACE. If DIRECTION is 0, copy from PTRACE to | |
89 | INF. */ | |
90 | ||
91 | static int | |
92 | -amd64_linux_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction) | |
93 | +amd64_linux_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction) | |
94 | { | |
95 | struct gdbarch *gdbarch = get_frame_arch (get_current_frame ()); | |
96 | ||
97 | /* Is the inferior 32-bit? If so, then do fixup the siginfo | |
98 | object. */ | |
99 | if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) | |
100 | - return amd64_linux_siginfo_fixup_common (native, inf, direction, | |
101 | + return amd64_linux_siginfo_fixup_common (ptrace, inf, direction, | |
102 | FIXUP_32); | |
103 | /* No fixup for native x32 GDB. */ | |
104 | else if (gdbarch_addr_bit (gdbarch) == 32 && sizeof (void *) == 8) | |
105 | - return amd64_linux_siginfo_fixup_common (native, inf, direction, | |
106 | + return amd64_linux_siginfo_fixup_common (ptrace, inf, direction, | |
107 | FIXUP_X32); | |
108 | else | |
109 | return 0; | |
110 | diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c | |
111 | index 5080dec..4e6dbce 100644 | |
112 | --- a/gdb/gdbserver/linux-x86-low.c | |
113 | +++ b/gdb/gdbserver/linux-x86-low.c | |
114 | @@ -624,14 +624,14 @@ x86_debug_reg_state (pid_t pid) | |
115 | as debugging it with a 32-bit GDBSERVER, we do the 32-bit <-> 64-bit | |
116 | conversion in-place ourselves. */ | |
117 | ||
118 | -/* Convert a native/host siginfo object, into/from the siginfo in the | |
119 | +/* Convert a ptrace/host siginfo object, into/from the siginfo in the | |
120 | layout of the inferiors' architecture. Returns true if any | |
121 | conversion was done; false otherwise. If DIRECTION is 1, then copy | |
122 | - from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to | |
123 | + from INF to PTRACE. If DIRECTION is 0, copy from PTRACE to | |
124 | INF. */ | |
125 | ||
126 | static int | |
127 | -x86_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction) | |
128 | +x86_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction) | |
129 | { | |
130 | #ifdef __x86_64__ | |
131 | unsigned int machine; | |
132 | @@ -640,11 +640,11 @@ x86_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction) | |
133 | ||
134 | /* Is the inferior 32-bit? If so, then fixup the siginfo object. */ | |
135 | if (!is_64bit_tdesc ()) | |
136 | - return amd64_linux_siginfo_fixup_common (native, inf, direction, | |
137 | + return amd64_linux_siginfo_fixup_common (ptrace, inf, direction, | |
138 | FIXUP_32); | |
139 | /* No fixup for native x32 GDB. */ | |
140 | else if (!is_elf64 && sizeof (void *) == 8) | |
141 | - return amd64_linux_siginfo_fixup_common (native, inf, direction, | |
142 | + return amd64_linux_siginfo_fixup_common (ptrace, inf, direction, | |
143 | FIXUP_X32); | |
144 | #endif | |
145 | ||
146 | diff --git a/gdb/nat/amd64-linux-siginfo.c b/gdb/nat/amd64-linux-siginfo.c | |
147 | index 72b3042..9f7df0c 100644 | |
148 | --- a/gdb/nat/amd64-linux-siginfo.c | |
149 | +++ b/gdb/nat/amd64-linux-siginfo.c | |
150 | @@ -21,23 +21,29 @@ | |
151 | #include "common-defs.h" | |
152 | #include "amd64-linux-siginfo.h" | |
153 | ||
154 | -/* The nat_* types below define the most complete kernel siginfo type | |
155 | - known for the architecture, independent of the system/libc headers. */ | |
156 | +#define GDB_SI_SIZE 128 | |
157 | + | |
158 | +/* The types below define the most complete kernel siginfo types known | |
159 | + for the architecture, independent of the system/libc headers. They | |
160 | + are named from a 64-bit kernel's perspective: | |
161 | + | |
162 | + | layout | type | | |
163 | + |--------+----------------------| | |
164 | + | 64-bit | nat_siginfo_t | | |
165 | + | 32-bit | compat_siginfo_t | | |
166 | + | x32 | compat_x32_siginfo_t | | |
167 | +*/ | |
168 | + | |
169 | +#ifndef __ILP32__ | |
170 | ||
171 | typedef int nat_int_t; | |
172 | -typedef void* nat_uptr_t; | |
173 | +typedef unsigned long nat_uptr_t; | |
174 | ||
175 | typedef int nat_time_t; | |
176 | typedef int nat_timer_t; | |
177 | ||
178 | -/* For native 64-bit, clock_t in _sigchld is 64bit aligned at 4 bytes. */ | |
179 | -typedef long __attribute__ ((__aligned__ (4))) nat_clock_t; | |
180 | - | |
181 | -struct nat_timeval | |
182 | -{ | |
183 | - nat_time_t tv_sec; | |
184 | - int tv_usec; | |
185 | -}; | |
186 | +/* For native 64-bit, clock_t in _sigchld is 64-bit. */ | |
187 | +typedef long nat_clock_t; | |
188 | ||
189 | typedef union nat_sigval | |
190 | { | |
191 | @@ -106,11 +112,9 @@ typedef struct nat_siginfo | |
192 | int _fd; | |
193 | } _sigpoll; | |
194 | } _sifields; | |
195 | -} nat_siginfo_t __attribute__ ((__aligned__ (8))); | |
196 | - | |
197 | -/* Sanity check for the siginfo structure size. */ | |
198 | +} nat_siginfo_t; | |
199 | ||
200 | -gdb_static_assert (sizeof (nat_siginfo_t) == sizeof (siginfo_t)); | |
201 | +#endif /* __ILP32__ */ | |
202 | ||
203 | /* These types below (compat_*) define a siginfo type that is layout | |
204 | compatible with the siginfo type exported by the 32-bit userspace | |
205 | @@ -286,62 +290,71 @@ typedef struct compat_x32_siginfo | |
206 | #define si_overrun si_timer2 | |
207 | #endif | |
208 | ||
209 | +/* The type of the siginfo object the kernel returns in | |
210 | + PTRACE_GETSIGINFO. If gdb is built as a x32 program, we get a x32 | |
211 | + siginfo. */ | |
212 | +#ifdef __ILP32__ | |
213 | +typedef compat_x32_siginfo_t ptrace_siginfo_t; | |
214 | +#else | |
215 | +typedef nat_siginfo_t ptrace_siginfo_t; | |
216 | +#endif | |
217 | + | |
218 | /* Convert the system provided siginfo into compatible siginfo. */ | |
219 | ||
220 | static void | |
221 | -compat_siginfo_from_siginfo (compat_siginfo_t *to, siginfo_t *from) | |
222 | +compat_siginfo_from_siginfo (compat_siginfo_t *to, const siginfo_t *from) | |
223 | { | |
224 | - nat_siginfo_t from_nat; | |
225 | + ptrace_siginfo_t from_ptrace; | |
226 | ||
227 | - memcpy (&from_nat, from, sizeof (from_nat)); | |
228 | + memcpy (&from_ptrace, from, sizeof (from_ptrace)); | |
229 | memset (to, 0, sizeof (*to)); | |
230 | ||
231 | - to->si_signo = from_nat.si_signo; | |
232 | - to->si_errno = from_nat.si_errno; | |
233 | - to->si_code = from_nat.si_code; | |
234 | + to->si_signo = from_ptrace.si_signo; | |
235 | + to->si_errno = from_ptrace.si_errno; | |
236 | + to->si_code = from_ptrace.si_code; | |
237 | ||
238 | if (to->si_code == SI_TIMER) | |
239 | { | |
240 | - to->cpt_si_timerid = from_nat.cpt_si_timerid; | |
241 | - to->cpt_si_overrun = from_nat.cpt_si_overrun; | |
242 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
243 | + to->cpt_si_timerid = from_ptrace.cpt_si_timerid; | |
244 | + to->cpt_si_overrun = from_ptrace.cpt_si_overrun; | |
245 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
246 | } | |
247 | else if (to->si_code == SI_USER) | |
248 | { | |
249 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
250 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
251 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
252 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
253 | } | |
254 | else if (to->si_code < 0) | |
255 | { | |
256 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
257 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
258 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
259 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
260 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
261 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
262 | } | |
263 | else | |
264 | { | |
265 | switch (to->si_signo) | |
266 | { | |
267 | case SIGCHLD: | |
268 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
269 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
270 | - to->cpt_si_status = from_nat.cpt_si_status; | |
271 | - to->cpt_si_utime = from_nat.cpt_si_utime; | |
272 | - to->cpt_si_stime = from_nat.cpt_si_stime; | |
273 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
274 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
275 | + to->cpt_si_status = from_ptrace.cpt_si_status; | |
276 | + to->cpt_si_utime = from_ptrace.cpt_si_utime; | |
277 | + to->cpt_si_stime = from_ptrace.cpt_si_stime; | |
278 | break; | |
279 | case SIGILL: | |
280 | case SIGFPE: | |
281 | case SIGSEGV: | |
282 | case SIGBUS: | |
283 | - to->cpt_si_addr = (intptr_t) from_nat.cpt_si_addr; | |
284 | + to->cpt_si_addr = from_ptrace.cpt_si_addr; | |
285 | break; | |
286 | case SIGPOLL: | |
287 | - to->cpt_si_band = from_nat.cpt_si_band; | |
288 | - to->cpt_si_fd = from_nat.cpt_si_fd; | |
289 | + to->cpt_si_band = from_ptrace.cpt_si_band; | |
290 | + to->cpt_si_fd = from_ptrace.cpt_si_fd; | |
291 | break; | |
292 | default: | |
293 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
294 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
295 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
296 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
297 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
298 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
299 | break; | |
300 | } | |
301 | } | |
302 | @@ -350,124 +363,124 @@ compat_siginfo_from_siginfo (compat_siginfo_t *to, siginfo_t *from) | |
303 | /* Convert the compatible siginfo into system siginfo. */ | |
304 | ||
305 | static void | |
306 | -siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from) | |
307 | +siginfo_from_compat_siginfo (siginfo_t *to, const compat_siginfo_t *from) | |
308 | { | |
309 | - nat_siginfo_t to_nat; | |
310 | + ptrace_siginfo_t to_ptrace; | |
311 | ||
312 | - memset (&to_nat, 0, sizeof (to_nat)); | |
313 | + memset (&to_ptrace, 0, sizeof (to_ptrace)); | |
314 | ||
315 | - to_nat.si_signo = from->si_signo; | |
316 | - to_nat.si_errno = from->si_errno; | |
317 | - to_nat.si_code = from->si_code; | |
318 | + to_ptrace.si_signo = from->si_signo; | |
319 | + to_ptrace.si_errno = from->si_errno; | |
320 | + to_ptrace.si_code = from->si_code; | |
321 | ||
322 | - if (to_nat.si_code == SI_TIMER) | |
323 | + if (to_ptrace.si_code == SI_TIMER) | |
324 | { | |
325 | - to_nat.cpt_si_timerid = from->cpt_si_timerid; | |
326 | - to_nat.cpt_si_overrun = from->cpt_si_overrun; | |
327 | - to_nat.cpt_si_ptr = (void *) (intptr_t) from->cpt_si_ptr; | |
328 | + to_ptrace.cpt_si_timerid = from->cpt_si_timerid; | |
329 | + to_ptrace.cpt_si_overrun = from->cpt_si_overrun; | |
330 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
331 | } | |
332 | - else if (to_nat.si_code == SI_USER) | |
333 | + else if (to_ptrace.si_code == SI_USER) | |
334 | { | |
335 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
336 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
337 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
338 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
339 | } | |
340 | - if (to_nat.si_code < 0) | |
341 | + if (to_ptrace.si_code < 0) | |
342 | { | |
343 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
344 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
345 | - to_nat.cpt_si_ptr = (void *) (intptr_t) from->cpt_si_ptr; | |
346 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
347 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
348 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
349 | } | |
350 | else | |
351 | { | |
352 | - switch (to_nat.si_signo) | |
353 | + switch (to_ptrace.si_signo) | |
354 | { | |
355 | case SIGCHLD: | |
356 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
357 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
358 | - to_nat.cpt_si_status = from->cpt_si_status; | |
359 | - to_nat.cpt_si_utime = from->cpt_si_utime; | |
360 | - to_nat.cpt_si_stime = from->cpt_si_stime; | |
361 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
362 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
363 | + to_ptrace.cpt_si_status = from->cpt_si_status; | |
364 | + to_ptrace.cpt_si_utime = from->cpt_si_utime; | |
365 | + to_ptrace.cpt_si_stime = from->cpt_si_stime; | |
366 | break; | |
367 | case SIGILL: | |
368 | case SIGFPE: | |
369 | case SIGSEGV: | |
370 | case SIGBUS: | |
371 | - to_nat.cpt_si_addr = (void *) (intptr_t) from->cpt_si_addr; | |
372 | - to_nat.cpt_si_addr_lsb = (short) from->cpt_si_addr_lsb; | |
373 | + to_ptrace.cpt_si_addr = from->cpt_si_addr; | |
374 | + to_ptrace.cpt_si_addr_lsb = from->cpt_si_addr_lsb; | |
375 | break; | |
376 | case SIGPOLL: | |
377 | - to_nat.cpt_si_band = from->cpt_si_band; | |
378 | - to_nat.cpt_si_fd = from->cpt_si_fd; | |
379 | + to_ptrace.cpt_si_band = from->cpt_si_band; | |
380 | + to_ptrace.cpt_si_fd = from->cpt_si_fd; | |
381 | break; | |
382 | default: | |
383 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
384 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
385 | - to_nat.cpt_si_ptr = (void* ) (intptr_t) from->cpt_si_ptr; | |
386 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
387 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
388 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
389 | break; | |
390 | } | |
391 | } | |
392 | - memcpy (to, &to_nat, sizeof (to_nat)); | |
393 | + memcpy (to, &to_ptrace, sizeof (to_ptrace)); | |
394 | } | |
395 | ||
396 | /* Convert the system provided siginfo into compatible x32 siginfo. */ | |
397 | ||
398 | static void | |
399 | compat_x32_siginfo_from_siginfo (compat_x32_siginfo_t *to, | |
400 | - siginfo_t *from) | |
401 | + const siginfo_t *from) | |
402 | { | |
403 | - nat_siginfo_t from_nat; | |
404 | + ptrace_siginfo_t from_ptrace; | |
405 | ||
406 | - memcpy (&from_nat, from, sizeof (from_nat)); | |
407 | + memcpy (&from_ptrace, from, sizeof (from_ptrace)); | |
408 | memset (to, 0, sizeof (*to)); | |
409 | ||
410 | - to->si_signo = from_nat.si_signo; | |
411 | - to->si_errno = from_nat.si_errno; | |
412 | - to->si_code = from_nat.si_code; | |
413 | + to->si_signo = from_ptrace.si_signo; | |
414 | + to->si_errno = from_ptrace.si_errno; | |
415 | + to->si_code = from_ptrace.si_code; | |
416 | ||
417 | if (to->si_code == SI_TIMER) | |
418 | { | |
419 | - to->cpt_si_timerid = from_nat.cpt_si_timerid; | |
420 | - to->cpt_si_overrun = from_nat.cpt_si_overrun; | |
421 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
422 | + to->cpt_si_timerid = from_ptrace.cpt_si_timerid; | |
423 | + to->cpt_si_overrun = from_ptrace.cpt_si_overrun; | |
424 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
425 | } | |
426 | else if (to->si_code == SI_USER) | |
427 | { | |
428 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
429 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
430 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
431 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
432 | } | |
433 | else if (to->si_code < 0) | |
434 | { | |
435 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
436 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
437 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
438 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
439 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
440 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
441 | } | |
442 | else | |
443 | { | |
444 | switch (to->si_signo) | |
445 | { | |
446 | case SIGCHLD: | |
447 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
448 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
449 | - to->cpt_si_status = from_nat.cpt_si_status; | |
450 | - memcpy (&to->cpt_si_utime, &from_nat.cpt_si_utime, | |
451 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
452 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
453 | + to->cpt_si_status = from_ptrace.cpt_si_status; | |
454 | + memcpy (&to->cpt_si_utime, &from_ptrace.cpt_si_utime, | |
455 | sizeof (to->cpt_si_utime)); | |
456 | - memcpy (&to->cpt_si_stime, &from_nat.cpt_si_stime, | |
457 | + memcpy (&to->cpt_si_stime, &from_ptrace.cpt_si_stime, | |
458 | sizeof (to->cpt_si_stime)); | |
459 | break; | |
460 | case SIGILL: | |
461 | case SIGFPE: | |
462 | case SIGSEGV: | |
463 | case SIGBUS: | |
464 | - to->cpt_si_addr = (intptr_t) from_nat.cpt_si_addr; | |
465 | + to->cpt_si_addr = from_ptrace.cpt_si_addr; | |
466 | break; | |
467 | case SIGPOLL: | |
468 | - to->cpt_si_band = from_nat.cpt_si_band; | |
469 | - to->cpt_si_fd = from_nat.cpt_si_fd; | |
470 | + to->cpt_si_band = from_ptrace.cpt_si_band; | |
471 | + to->cpt_si_fd = from_ptrace.cpt_si_fd; | |
472 | break; | |
473 | default: | |
474 | - to->cpt_si_pid = from_nat.cpt_si_pid; | |
475 | - to->cpt_si_uid = from_nat.cpt_si_uid; | |
476 | - to->cpt_si_ptr = (intptr_t) from_nat.cpt_si_ptr; | |
477 | + to->cpt_si_pid = from_ptrace.cpt_si_pid; | |
478 | + to->cpt_si_uid = from_ptrace.cpt_si_uid; | |
479 | + to->cpt_si_ptr = from_ptrace.cpt_si_ptr; | |
480 | break; | |
481 | } | |
482 | } | |
483 | @@ -479,98 +492,105 @@ compat_x32_siginfo_from_siginfo (compat_x32_siginfo_t *to, | |
484 | /* Convert the compatible x32 siginfo into system siginfo. */ | |
485 | static void | |
486 | siginfo_from_compat_x32_siginfo (siginfo_t *to, | |
487 | - compat_x32_siginfo_t *from) | |
488 | + const compat_x32_siginfo_t *from) | |
489 | { | |
490 | - nat_siginfo_t to_nat; | |
491 | + ptrace_siginfo_t to_ptrace; | |
492 | ||
493 | - memset (&to_nat, 0, sizeof (to_nat)); | |
494 | - to_nat.si_signo = from->si_signo; | |
495 | - to_nat.si_errno = from->si_errno; | |
496 | - to_nat.si_code = from->si_code; | |
497 | + memset (&to_ptrace, 0, sizeof (to_ptrace)); | |
498 | + to_ptrace.si_signo = from->si_signo; | |
499 | + to_ptrace.si_errno = from->si_errno; | |
500 | + to_ptrace.si_code = from->si_code; | |
501 | ||
502 | - if (to_nat.si_code == SI_TIMER) | |
503 | + if (to_ptrace.si_code == SI_TIMER) | |
504 | { | |
505 | - to_nat.cpt_si_timerid = from->cpt_si_timerid; | |
506 | - to_nat.cpt_si_overrun = from->cpt_si_overrun; | |
507 | - to_nat.cpt_si_ptr = (void *) (intptr_t) from->cpt_si_ptr; | |
508 | + to_ptrace.cpt_si_timerid = from->cpt_si_timerid; | |
509 | + to_ptrace.cpt_si_overrun = from->cpt_si_overrun; | |
510 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
511 | } | |
512 | - else if (to_nat.si_code == SI_USER) | |
513 | + else if (to_ptrace.si_code == SI_USER) | |
514 | { | |
515 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
516 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
517 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
518 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
519 | } | |
520 | - if (to_nat.si_code < 0) | |
521 | + if (to_ptrace.si_code < 0) | |
522 | { | |
523 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
524 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
525 | - to_nat.cpt_si_ptr = (void *) (intptr_t) from->cpt_si_ptr; | |
526 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
527 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
528 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
529 | } | |
530 | else | |
531 | { | |
532 | - switch (to_nat.si_signo) | |
533 | + switch (to_ptrace.si_signo) | |
534 | { | |
535 | case SIGCHLD: | |
536 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
537 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
538 | - to_nat.cpt_si_status = from->cpt_si_status; | |
539 | - memcpy (&to_nat.cpt_si_utime, &from->cpt_si_utime, | |
540 | - sizeof (to_nat.cpt_si_utime)); | |
541 | - memcpy (&to_nat.cpt_si_stime, &from->cpt_si_stime, | |
542 | - sizeof (to_nat.cpt_si_stime)); | |
543 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
544 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
545 | + to_ptrace.cpt_si_status = from->cpt_si_status; | |
546 | + memcpy (&to_ptrace.cpt_si_utime, &from->cpt_si_utime, | |
547 | + sizeof (to_ptrace.cpt_si_utime)); | |
548 | + memcpy (&to_ptrace.cpt_si_stime, &from->cpt_si_stime, | |
549 | + sizeof (to_ptrace.cpt_si_stime)); | |
550 | break; | |
551 | case SIGILL: | |
552 | case SIGFPE: | |
553 | case SIGSEGV: | |
554 | case SIGBUS: | |
555 | - to_nat.cpt_si_addr = (void *) (intptr_t) from->cpt_si_addr; | |
556 | + to_ptrace.cpt_si_addr = from->cpt_si_addr; | |
557 | break; | |
558 | case SIGPOLL: | |
559 | - to_nat.cpt_si_band = from->cpt_si_band; | |
560 | - to_nat.cpt_si_fd = from->cpt_si_fd; | |
561 | + to_ptrace.cpt_si_band = from->cpt_si_band; | |
562 | + to_ptrace.cpt_si_fd = from->cpt_si_fd; | |
563 | break; | |
564 | default: | |
565 | - to_nat.cpt_si_pid = from->cpt_si_pid; | |
566 | - to_nat.cpt_si_uid = from->cpt_si_uid; | |
567 | - to_nat.cpt_si_ptr = (void* ) (intptr_t) from->cpt_si_ptr; | |
568 | + to_ptrace.cpt_si_pid = from->cpt_si_pid; | |
569 | + to_ptrace.cpt_si_uid = from->cpt_si_uid; | |
570 | + to_ptrace.cpt_si_ptr = from->cpt_si_ptr; | |
571 | break; | |
572 | } | |
573 | } | |
574 | - memcpy (to, &to_nat, sizeof (to_nat)); | |
575 | + memcpy (to, &to_ptrace, sizeof (to_ptrace)); | |
576 | } | |
577 | ||
578 | -/* Convert a native/host siginfo object, into/from the siginfo in the | |
579 | +/* Convert a ptrace siginfo object, into/from the siginfo in the | |
580 | layout of the inferiors' architecture. Returns true if any | |
581 | conversion was done; false otherwise. If DIRECTION is 1, then copy | |
582 | - from INF to NATIVE. If DIRECTION is 0, then copy from NATIVE to INF. */ | |
583 | + from INF to PTRACE. If DIRECTION is 0, then copy from NATIVE to | |
584 | + INF. */ | |
585 | ||
586 | int | |
587 | -amd64_linux_siginfo_fixup_common (siginfo_t *native, gdb_byte *inf, | |
588 | +amd64_linux_siginfo_fixup_common (siginfo_t *ptrace, gdb_byte *inf, | |
589 | int direction, | |
590 | enum amd64_siginfo_fixup_mode mode) | |
591 | { | |
592 | if (mode == FIXUP_32) | |
593 | { | |
594 | - gdb_assert (sizeof (siginfo_t) == sizeof (compat_siginfo_t)); | |
595 | - | |
596 | if (direction == 0) | |
597 | - compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, native); | |
598 | + compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, ptrace); | |
599 | else | |
600 | - siginfo_from_compat_siginfo (native, (struct compat_siginfo *) inf); | |
601 | + siginfo_from_compat_siginfo (ptrace, (struct compat_siginfo *) inf); | |
602 | ||
603 | return 1; | |
604 | } | |
605 | else if (mode == FIXUP_X32) | |
606 | { | |
607 | - gdb_assert (sizeof (siginfo_t) == sizeof (compat_x32_siginfo_t)); | |
608 | - | |
609 | if (direction == 0) | |
610 | compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf, | |
611 | - native); | |
612 | + ptrace); | |
613 | else | |
614 | - siginfo_from_compat_x32_siginfo (native, | |
615 | + siginfo_from_compat_x32_siginfo (ptrace, | |
616 | (struct compat_x32_siginfo *) inf); | |
617 | ||
618 | return 1; | |
619 | } | |
620 | return 0; | |
621 | } | |
622 | + | |
623 | +/* Sanity check for the siginfo structure sizes. */ | |
624 | + | |
625 | +gdb_static_assert (sizeof (siginfo_t) == GDB_SI_SIZE); | |
626 | +#ifndef __ILP32__ | |
627 | +gdb_static_assert (sizeof (nat_siginfo_t) == GDB_SI_SIZE); | |
628 | +#endif | |
629 | +gdb_static_assert (sizeof (compat_x32_siginfo_t) == GDB_SI_SIZE); | |
630 | +gdb_static_assert (sizeof (compat_siginfo_t) == GDB_SI_SIZE); | |
631 | +gdb_static_assert (sizeof (ptrace_siginfo_t) == GDB_SI_SIZE); | |
632 | -- | |
633 | 1.7.1 | |
634 |