Deleted Added
full compact
elfcore.c (102951) elfcore.c (103299)
1/*-
2 * Copyright (c) 1998 John D. Polstra
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 John D. Polstra
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/usr.bin/gcore/elfcore.c 102951 2002-09-05 07:43:34Z iedowse $");
28__FBSDID("$FreeBSD: head/usr.bin/gcore/elfcore.c 103299 2002-09-13 16:33:35Z peter $");
29
30#include <sys/param.h>
31#include <sys/procfs.h>
29
30#include <sys/param.h>
31#include <sys/procfs.h>
32#include <sys/linker_set.h>
32#include <machine/elf.h>
33#include <vm/vm_param.h>
34#include <vm/vm.h>
35#include <vm/pmap.h>
36#include <vm/vm_map.h>
37#include <err.h>
38#include <errno.h>
39#include <fcntl.h>

--- 32 unchanged lines hidden (view full) ---

72static void elf_puthdr(vm_map_entry_t, void *, size_t *,
73 const prstatus_t *, const prfpregset_t *, const prpsinfo_t *, int numsegs);
74static void elf_putnote(void *dst, size_t *off, const char *name, int type,
75 const void *desc, size_t descsz);
76static void freemap(vm_map_entry_t);
77static void readhdrinfo(pid_t, prstatus_t *, prfpregset_t *, prpsinfo_t *);
78static vm_map_entry_t readmap(pid_t);
79
33#include <machine/elf.h>
34#include <vm/vm_param.h>
35#include <vm/vm.h>
36#include <vm/pmap.h>
37#include <vm/vm_map.h>
38#include <err.h>
39#include <errno.h>
40#include <fcntl.h>

--- 32 unchanged lines hidden (view full) ---

73static void elf_puthdr(vm_map_entry_t, void *, size_t *,
74 const prstatus_t *, const prfpregset_t *, const prpsinfo_t *, int numsegs);
75static void elf_putnote(void *dst, size_t *off, const char *name, int type,
76 const void *desc, size_t descsz);
77static void freemap(vm_map_entry_t);
78static void readhdrinfo(pid_t, prstatus_t *, prfpregset_t *, prpsinfo_t *);
79static vm_map_entry_t readmap(pid_t);
80
81static int
82elf_ident(int efd, pid_t pid, char *binfile)
83{
84 Elf_Ehdr hdr;
85 int cnt;
86 uid_t uid;
87
88 cnt = read(efd, &hdr, sizeof(hdr));
89 if (cnt != sizeof(hdr))
90 return (0);
91 if (IS_ELF(hdr))
92 return (1);
93 return (0);
94}
95
80/*
81 * Write an ELF coredump for the given pid to the given fd.
82 */
83void
96/*
97 * Write an ELF coredump for the given pid to the given fd.
98 */
99void
84elf_coredump(int fd, pid_t pid)
100elf_coredump(int efd, int fd, pid_t pid)
85{
86 vm_map_entry_t map;
87 struct sseg_closure seginfo;
88 void *hdr;
89 size_t hdrsize;
90 char memname[64];
91 int memfd;
92 Elf_Phdr *php;

--- 259 unchanged lines hidden (view full) ---

352}
353
354/*
355 * Free the memory map.
356 */
357static void
358freemap(vm_map_entry_t map)
359{
101{
102 vm_map_entry_t map;
103 struct sseg_closure seginfo;
104 void *hdr;
105 size_t hdrsize;
106 char memname[64];
107 int memfd;
108 Elf_Phdr *php;

--- 259 unchanged lines hidden (view full) ---

368}
369
370/*
371 * Free the memory map.
372 */
373static void
374freemap(vm_map_entry_t map)
375{
376
360 while (map != NULL) {
361 vm_map_entry_t next = map->next;
362 free(map);
363 map = next;
364 }
365}
366
367/*

--- 141 unchanged lines hidden (view full) ---

509 ent->protection |= VM_PROT_EXECUTE;
510
511 *linkp = ent;
512 linkp = &ent->next;
513 }
514 free(mapbuf);
515 return map;
516}
377 while (map != NULL) {
378 vm_map_entry_t next = map->next;
379 free(map);
380 map = next;
381 }
382}
383
384/*

--- 141 unchanged lines hidden (view full) ---

526 ent->protection |= VM_PROT_EXECUTE;
527
528 *linkp = ent;
529 linkp = &ent->next;
530 }
531 free(mapbuf);
532 return map;
533}
534
535struct dumpers elfdump = { elf_ident, elf_coredump };
536TEXT_SET(dumpset, elfdump);