| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $ */ | | 1 | /* $NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | | 7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -30,53 +30,57 @@ | | | @@ -30,53 +30,57 @@ |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | /* | | 38 | /* |
39 | * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format. | | 39 | * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format. |
40 | */ | | 40 | */ |
41 | | | 41 | |
42 | #include <sys/cdefs.h> | | 42 | #include <sys/cdefs.h> |
43 | __KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $"); | | 43 | __KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $"); |
44 | | | 44 | |
45 | #ifdef _KERNEL_OPT | | 45 | #ifdef _KERNEL_OPT |
46 | #include "opt_coredump.h" | | 46 | #include "opt_coredump.h" |
47 | #include "opt_compat_netbsd32.h" | | 47 | #include "opt_compat_netbsd32.h" |
48 | #endif | | 48 | #endif |
49 | | | 49 | |
50 | #ifndef ELFSIZE | | 50 | #ifndef ELFSIZE |
51 | #define ELFSIZE 32 | | 51 | #define ELFSIZE 32 |
52 | #endif | | 52 | #endif |
53 | | | 53 | |
54 | #include <sys/param.h> | | 54 | #include <sys/param.h> |
55 | #include <sys/systm.h> | | 55 | #include <sys/systm.h> |
56 | #include <sys/proc.h> | | 56 | #include <sys/proc.h> |
57 | #include <sys/vnode.h> | | 57 | #include <sys/vnode.h> |
58 | #include <sys/exec.h> | | 58 | #include <sys/exec.h> |
59 | #include <sys/exec_elf.h> | | 59 | #include <sys/exec_elf.h> |
60 | #include <sys/ptrace.h> | | 60 | #include <sys/ptrace.h> |
61 | #include <sys/kmem.h> | | 61 | #include <sys/kmem.h> |
62 | #include <sys/kauth.h> | | 62 | #include <sys/kauth.h> |
63 | | | 63 | |
64 | #include <machine/reg.h> | | 64 | #include <machine/reg.h> |
65 | | | 65 | |
66 | #include <uvm/uvm_extern.h> | | 66 | #include <uvm/uvm_extern.h> |
67 | | | 67 | |
68 | #ifdef COREDUMP | | 68 | #ifdef COREDUMP |
69 | | | 69 | |
| | | 70 | #ifdef COMPAT_NETBSD32 |
| | | 71 | #include <machine/netbsd32_machdep.h> |
| | | 72 | #endif |
| | | 73 | |
70 | struct writesegs_state { | | 74 | struct writesegs_state { |
71 | Elf_Phdr *psections; | | 75 | Elf_Phdr *psections; |
72 | proc_t *p; | | 76 | proc_t *p; |
73 | off_t secoff; | | 77 | off_t secoff; |
74 | size_t npsections; | | 78 | size_t npsections; |
75 | }; | | 79 | }; |
76 | | | 80 | |
77 | /* | | 81 | /* |
78 | * We need to know how big the 'notes' are before we write the main header. | | 82 | * We need to know how big the 'notes' are before we write the main header. |
79 | * To avoid problems with double-processing we save the data. | | 83 | * To avoid problems with double-processing we save the data. |
80 | */ | | 84 | */ |
81 | struct note_buf { | | 85 | struct note_buf { |
82 | struct note_buf *nb_next; | | 86 | struct note_buf *nb_next; |
| @@ -479,36 +483,47 @@ ELFNAMEEND(coredump_note)(struct lwp *l, | | | @@ -479,36 +483,47 @@ ELFNAMEEND(coredump_note)(struct lwp *l, |
479 | elf_reg intreg; | | 483 | elf_reg intreg; |
480 | #ifdef PT_GETFPREGS | | 484 | #ifdef PT_GETFPREGS |
481 | elf_fpreg freg; | | 485 | elf_fpreg freg; |
482 | size_t freglen; | | 486 | size_t freglen; |
483 | #endif | | 487 | #endif |
484 | | | 488 | |
485 | snprintf(name, sizeof(name), "%s@%d", | | 489 | snprintf(name, sizeof(name), "%s@%d", |
486 | ELF_NOTE_NETBSD_CORE_NAME, l->l_lid); | | 490 | ELF_NOTE_NETBSD_CORE_NAME, l->l_lid); |
487 | | | 491 | |
488 | error = elf_process_read_regs(l, &intreg); | | 492 | error = elf_process_read_regs(l, &intreg); |
489 | if (error) | | 493 | if (error) |
490 | return (error); | | 494 | return (error); |
491 | | | 495 | |
492 | ELFNAMEEND(coredump_savenote)(ns, PT_GETREGS, name, &intreg, | | 496 | ELFNAMEEND(coredump_savenote)(ns, |
493 | sizeof(intreg)); | | 497 | #if ELFSIZE == 32 && defined(PT32_GETREGS) |
| | | 498 | PT32_GETREGS, |
| | | 499 | #else |
| | | 500 | PT_GETREGS, |
| | | 501 | #endif |
| | | 502 | name, &intreg, sizeof(intreg)); |
494 | | | 503 | |
495 | #ifdef PT_GETFPREGS | | 504 | #ifdef PT_GETFPREGS |
496 | freglen = sizeof(freg); | | 505 | freglen = sizeof(freg); |
497 | error = elf_process_read_fpregs(l, &freg, &freglen); | | 506 | error = elf_process_read_fpregs(l, &freg, &freglen); |
498 | if (error) | | 507 | if (error) |
499 | return (error); | | 508 | return (error); |
500 | | | 509 | |
501 | ELFNAMEEND(coredump_savenote)(ns, PT_GETFPREGS, name, &freg, freglen); | | 510 | ELFNAMEEND(coredump_savenote)(ns, |
| | | 511 | # if ELFSIZE == 32 && defined(PT32_GETFPREGS) |
| | | 512 | PT32_GETFPREGS, |
| | | 513 | # else |
| | | 514 | PT_GETFPREGS, |
| | | 515 | # endif |
| | | 516 | name, &freg, freglen); |
502 | #endif | | 517 | #endif |
503 | /* XXX Add hook for machdep per-LWP notes. */ | | 518 | /* XXX Add hook for machdep per-LWP notes. */ |
504 | return (0); | | 519 | return (0); |
505 | } | | 520 | } |
506 | | | 521 | |
507 | static void | | 522 | static void |
508 | save_note_bytes(struct note_state *ns, const void *data, size_t len) | | 523 | save_note_bytes(struct note_state *ns, const void *data, size_t len) |
509 | { | | 524 | { |
510 | struct note_buf *nb = ns->ns_last; | | 525 | struct note_buf *nb = ns->ns_last; |
511 | size_t copylen; | | 526 | size_t copylen; |
512 | unsigned char *wp; | | 527 | unsigned char *wp; |
513 | | | 528 | |
514 | /* | | 529 | /* |