2 * Copyright (c) 2007 Sandvine Incorporated
3 * Copyright (c) 1998 John D. Polstra
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/endian.h>
32 #include <sys/param.h>
33 #include <sys/procfs.h>
34 #include <sys/ptrace.h>
35 #include <sys/queue.h>
36 #include <sys/linker_set.h>
38 #include <sys/sysctl.h>
41 #include <machine/elf.h>
42 #include <vm/vm_param.h>
45 #include <vm/vm_map.h>
61 * Code for generating ELF core dumps.
64 typedef void (*segment_callback)(vm_map_entry_t, void *);
66 /* Closure for cb_put_phdr(). */
68 Elf_Phdr *phdr; /* Program header to fill in */
69 Elf_Off offset; /* Offset of segment in core file */
72 /* Closure for cb_size_segment(). */
74 int count; /* Count of writable segments. */
75 size_t size; /* Total size of all writable segments. */
78 #ifdef ELFCORE_COMPAT_32
79 typedef struct fpreg32 elfcore_fpregset_t;
80 typedef struct reg32 elfcore_gregset_t;
81 typedef struct prpsinfo32 elfcore_prpsinfo_t;
82 typedef struct prstatus32 elfcore_prstatus_t;
83 static void elf_convert_gregset(elfcore_gregset_t *rd, struct reg *rs);
84 static void elf_convert_fpregset(elfcore_fpregset_t *rd, struct fpreg *rs);
86 typedef fpregset_t elfcore_fpregset_t;
87 typedef gregset_t elfcore_gregset_t;
88 typedef prpsinfo_t elfcore_prpsinfo_t;
89 typedef prstatus_t elfcore_prstatus_t;
90 #define elf_convert_gregset(d,s) *d = *s
91 #define elf_convert_fpregset(d,s) *d = *s
94 typedef void* (*notefunc_t)(void *, size_t *);
96 static void cb_put_phdr(vm_map_entry_t, void *);
97 static void cb_size_segment(vm_map_entry_t, void *);
98 static void each_dumpable_segment(vm_map_entry_t, segment_callback,
100 static void elf_detach(void); /* atexit() handler. */
101 static void *elf_note_fpregset(void *, size_t *);
102 static void *elf_note_prpsinfo(void *, size_t *);
103 static void *elf_note_prstatus(void *, size_t *);
104 static void *elf_note_thrmisc(void *, size_t *);
105 #if defined(__i386__) || defined(__amd64__)
106 static void *elf_note_x86_xstate(void *, size_t *);
108 #if defined(__powerpc__)
109 static void *elf_note_powerpc_vmx(void *, size_t *);
111 static void *elf_note_procstat_auxv(void *, size_t *);
112 static void *elf_note_procstat_files(void *, size_t *);
113 static void *elf_note_procstat_groups(void *, size_t *);
114 static void *elf_note_procstat_osrel(void *, size_t *);
115 static void *elf_note_procstat_proc(void *, size_t *);
116 static void *elf_note_procstat_psstrings(void *, size_t *);
117 static void *elf_note_procstat_rlimit(void *, size_t *);
118 static void *elf_note_procstat_umask(void *, size_t *);
119 static void *elf_note_procstat_vmmap(void *, size_t *);
120 static void elf_puthdr(int, pid_t, vm_map_entry_t, void *, size_t, size_t,
122 static void elf_putnote(int, notefunc_t, void *, struct sbuf *);
123 static void elf_putnotes(pid_t, struct sbuf *, size_t *);
124 static void freemap(vm_map_entry_t);
125 static vm_map_entry_t readmap(pid_t);
126 static void *procstat_sysctl(void *, int, size_t, size_t *sizep);
128 static pid_t g_pid; /* Pid being dumped, global for elf_detach */
129 static int g_status; /* proc status after ptrace attach */
132 elf_ident(int efd, pid_t pid __unused, char *binfile __unused)
138 cnt = read(efd, &hdr, sizeof(hdr));
139 if (cnt != sizeof(hdr))
143 switch (hdr.e_ident[EI_DATA]) {
145 machine = le16toh(hdr.e_machine);
148 machine = be16toh(hdr.e_machine);
153 if (!ELF_MACHINE_OK(machine))
167 * Forward any pending signals. SIGSTOP is generated by ptrace
168 * itself, so ignore it.
170 sig = WIFSTOPPED(g_status) ? WSTOPSIG(g_status) : 0;
173 ptrace(PT_DETACH, g_pid, (caddr_t)1, sig);
178 * Write an ELF coredump for the given pid to the given fd.
181 elf_coredump(int efd, int fd, pid_t pid)
184 struct sseg_closure seginfo;
187 size_t hdrsize, notesz, segoff;
192 /* Attach to process to dump. */
194 if (atexit(elf_detach) != 0)
197 ptrace(PT_ATTACH, pid, NULL, 0);
200 if (waitpid(pid, &g_status, 0) == -1)
203 /* Get the program's memory map. */
206 /* Size the program segments. */
209 each_dumpable_segment(map, cb_size_segment, &seginfo);
212 * Build the header and the notes using sbuf and write to the file.
214 sb = sbuf_new_auto();
215 hdrsize = sizeof(Elf_Ehdr) + sizeof(Elf_Phdr) * (1 + seginfo.count);
216 if (seginfo.count + 1 >= PN_XNUM)
217 hdrsize += sizeof(Elf_Shdr);
218 /* Start header + notes section. */
219 sbuf_start_section(sb, NULL);
220 /* Make empty header subsection. */
221 sbuf_start_section(sb, &old_len);
223 sbuf_end_section(sb, old_len, hdrsize, 0);
225 elf_putnotes(pid, sb, ¬esz);
226 /* Align up to a page boundary for the program segments. */
227 sbuf_end_section(sb, -1, PAGE_SIZE, 0);
228 if (sbuf_finish(sb) != 0)
229 err(1, "sbuf_finish");
231 segoff = sbuf_len(sb);
232 /* Fill in the header. */
233 elf_puthdr(efd, pid, map, hdr, hdrsize, notesz, segoff, seginfo.count);
235 n = write(fd, hdr, segoff);
239 errx(1, "short write");
241 /* Write the contents of all of the writable segments. */
242 php = (Elf_Phdr *)((char *)hdr + sizeof(Elf_Ehdr)) + 1;
243 for (i = 0; i < seginfo.count; i++) {
244 struct ptrace_io_desc iorequest;
245 uintmax_t nleft = php->p_filesz;
247 iorequest.piod_op = PIOD_READ_D;
248 iorequest.piod_offs = (caddr_t)(uintptr_t)php->p_vaddr;
254 if (nleft > sizeof(buf))
258 iorequest.piod_addr = buf;
259 iorequest.piod_len = nwant;
260 ptrace(PT_IO, pid, (caddr_t)&iorequest, 0);
261 ngot = iorequest.piod_len;
262 if ((size_t)ngot < nwant)
263 errx(1, "short read wanted %zu, got %zd",
265 ngot = write(fd, buf, nwant);
267 err(1, "write of segment %d failed", i);
268 if ((size_t)ngot != nwant)
269 errx(1, "short write");
271 iorequest.piod_offs += ngot;
280 * A callback for each_dumpable_segment() to write out the segment's
281 * program header entry.
284 cb_put_phdr(vm_map_entry_t entry, void *closure)
286 struct phdr_closure *phc = (struct phdr_closure *)closure;
287 Elf_Phdr *phdr = phc->phdr;
289 phc->offset = round_page(phc->offset);
291 phdr->p_type = PT_LOAD;
292 phdr->p_offset = phc->offset;
293 phdr->p_vaddr = entry->start;
295 phdr->p_filesz = phdr->p_memsz = entry->end - entry->start;
296 phdr->p_align = PAGE_SIZE;
298 if (entry->protection & VM_PROT_READ)
299 phdr->p_flags |= PF_R;
300 if (entry->protection & VM_PROT_WRITE)
301 phdr->p_flags |= PF_W;
302 if (entry->protection & VM_PROT_EXECUTE)
303 phdr->p_flags |= PF_X;
305 phc->offset += phdr->p_filesz;
310 * A callback for each_dumpable_segment() to gather information about
311 * the number of segments and their total size.
314 cb_size_segment(vm_map_entry_t entry, void *closure)
316 struct sseg_closure *ssc = (struct sseg_closure *)closure;
319 ssc->size += entry->end - entry->start;
323 * For each segment in the given memory map, call the given function
324 * with a pointer to the map entry and some arbitrary caller-supplied
328 each_dumpable_segment(vm_map_entry_t map, segment_callback func, void *closure)
330 vm_map_entry_t entry;
332 for (entry = map; entry != NULL; entry = entry->next)
333 (*func)(entry, closure);
337 elf_putnotes(pid_t pid, struct sbuf *sb, size_t *sizep)
340 size_t threads, old_len;
345 threads = ptrace(PT_GETNUMLWPS, pid, NULL, 0);
347 err(1, "PT_GETNUMLWPS");
348 tids = malloc(threads * sizeof(*tids));
350 errx(1, "out of memory");
352 ptrace(PT_GETLWPLIST, pid, (void *)tids, threads);
354 err(1, "PT_GETLWPLIST");
356 sbuf_start_section(sb, &old_len);
357 elf_putnote(NT_PRPSINFO, elf_note_prpsinfo, &pid, sb);
359 for (i = 0; i < threads; ++i) {
360 elf_putnote(NT_PRSTATUS, elf_note_prstatus, tids + i, sb);
361 elf_putnote(NT_FPREGSET, elf_note_fpregset, tids + i, sb);
362 elf_putnote(NT_THRMISC, elf_note_thrmisc, tids + i, sb);
363 #if defined(__i386__) || defined(__amd64__)
364 elf_putnote(NT_X86_XSTATE, elf_note_x86_xstate, tids + i, sb);
366 #if defined(__powerpc__)
367 elf_putnote(NT_PPC_VMX, elf_note_powerpc_vmx, tids + i, sb);
371 #ifndef ELFCORE_COMPAT_32
372 elf_putnote(NT_PROCSTAT_PROC, elf_note_procstat_proc, &pid, sb);
373 elf_putnote(NT_PROCSTAT_FILES, elf_note_procstat_files, &pid, sb);
374 elf_putnote(NT_PROCSTAT_VMMAP, elf_note_procstat_vmmap, &pid, sb);
375 elf_putnote(NT_PROCSTAT_GROUPS, elf_note_procstat_groups, &pid, sb);
376 elf_putnote(NT_PROCSTAT_UMASK, elf_note_procstat_umask, &pid, sb);
377 elf_putnote(NT_PROCSTAT_RLIMIT, elf_note_procstat_rlimit, &pid, sb);
378 elf_putnote(NT_PROCSTAT_OSREL, elf_note_procstat_osrel, &pid, sb);
379 elf_putnote(NT_PROCSTAT_PSSTRINGS, elf_note_procstat_psstrings, &pid,
381 elf_putnote(NT_PROCSTAT_AUXV, elf_note_procstat_auxv, &pid, sb);
384 size = sbuf_end_section(sb, old_len, 1, 0);
386 err(1, "sbuf_end_section");
392 * Emit one note section to sbuf.
395 elf_putnote(int type, notefunc_t notefunc, void *arg, struct sbuf *sb)
402 desc = notefunc(arg, &descsz);
403 note.n_namesz = 8; /* strlen("FreeBSD") + 1 */
404 note.n_descsz = descsz;
407 sbuf_bcat(sb, ¬e, sizeof(note));
408 sbuf_start_section(sb, &old_len);
409 sbuf_bcat(sb, "FreeBSD", note.n_namesz);
410 sbuf_end_section(sb, old_len, sizeof(Elf32_Size), 0);
413 sbuf_start_section(sb, &old_len);
414 sbuf_bcat(sb, desc, descsz);
415 sbuf_end_section(sb, old_len, sizeof(Elf32_Size), 0);
420 * Generate the ELF coredump header.
423 elf_puthdr(int efd, pid_t pid, vm_map_entry_t map, void *hdr, size_t hdrsize,
424 size_t notesz, size_t segoff, int numsegs)
426 Elf_Ehdr *ehdr, binhdr;
429 struct phdr_closure phc;
432 cnt = read(efd, &binhdr, sizeof(binhdr));
434 err(1, "Failed to re-read ELF header");
435 else if (cnt != sizeof(binhdr))
436 errx(1, "Failed to re-read ELF header");
438 ehdr = (Elf_Ehdr *)hdr;
440 ehdr->e_ident[EI_MAG0] = ELFMAG0;
441 ehdr->e_ident[EI_MAG1] = ELFMAG1;
442 ehdr->e_ident[EI_MAG2] = ELFMAG2;
443 ehdr->e_ident[EI_MAG3] = ELFMAG3;
444 ehdr->e_ident[EI_CLASS] = ELF_CLASS;
445 ehdr->e_ident[EI_DATA] = ELF_DATA;
446 ehdr->e_ident[EI_VERSION] = EV_CURRENT;
447 ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
448 ehdr->e_ident[EI_ABIVERSION] = 0;
449 ehdr->e_ident[EI_PAD] = 0;
450 ehdr->e_type = ET_CORE;
451 ehdr->e_machine = binhdr.e_machine;
452 ehdr->e_version = EV_CURRENT;
454 ehdr->e_phoff = sizeof(Elf_Ehdr);
455 ehdr->e_flags = binhdr.e_flags;
456 ehdr->e_ehsize = sizeof(Elf_Ehdr);
457 ehdr->e_phentsize = sizeof(Elf_Phdr);
458 ehdr->e_shentsize = sizeof(Elf_Shdr);
459 ehdr->e_shstrndx = SHN_UNDEF;
460 if (numsegs + 1 < PN_XNUM) {
461 ehdr->e_phnum = numsegs + 1;
464 ehdr->e_phnum = PN_XNUM;
467 ehdr->e_shoff = ehdr->e_phoff +
468 (numsegs + 1) * ehdr->e_phentsize;
470 shdr = (Elf_Shdr *)((char *)hdr + ehdr->e_shoff);
471 memset(shdr, 0, sizeof(*shdr));
473 * A special first section is used to hold large segment and
474 * section counts. This was proposed by Sun Microsystems in
475 * Solaris and has been adopted by Linux; the standard ELF
476 * tools are already familiar with the technique.
478 * See table 7-7 of the Solaris "Linker and Libraries Guide"
479 * (or 12-7 depending on the version of the document) for more
482 shdr->sh_type = SHT_NULL;
483 shdr->sh_size = ehdr->e_shnum;
484 shdr->sh_link = ehdr->e_shstrndx;
485 shdr->sh_info = numsegs + 1;
489 * Fill in the program header entries.
491 phdr = (Elf_Phdr *)((char *)hdr + ehdr->e_phoff);
493 /* The note segement. */
494 phdr->p_type = PT_NOTE;
495 phdr->p_offset = hdrsize;
498 phdr->p_filesz = notesz;
500 phdr->p_flags = PF_R;
501 phdr->p_align = sizeof(Elf32_Size);
504 /* All the writable segments from the program. */
507 each_dumpable_segment(map, cb_put_phdr, &phc);
511 * Free the memory map.
514 freemap(vm_map_entry_t map)
517 while (map != NULL) {
518 vm_map_entry_t next = map->next;
525 * Read the process's memory map using kinfo_getvmmap(), and return a list of
526 * VM map entries. Only the non-device read/writable segments are
527 * returned. The map entries in the list aren't fully filled in; only
528 * the items we need are present.
530 static vm_map_entry_t
533 vm_map_entry_t ent, *linkp, map;
534 struct kinfo_vmentry *vmentl, *kve;
537 vmentl = kinfo_getvmmap(pid, &nitems);
539 err(1, "cannot retrieve mappings for %u process", pid);
543 for (i = 0; i < nitems; i++) {
547 * Ignore 'malformed' segments or ones representing memory
548 * mapping with MAP_NOCORE on.
549 * If the 'full' support is disabled, just dump the most
550 * meaningful data segments.
552 if ((kve->kve_protection & KVME_PROT_READ) == 0 ||
553 (kve->kve_flags & KVME_FLAG_NOCOREDUMP) != 0 ||
554 kve->kve_type == KVME_TYPE_DEAD ||
555 kve->kve_type == KVME_TYPE_UNKNOWN ||
556 ((pflags & PFLAGS_FULL) == 0 &&
557 kve->kve_type != KVME_TYPE_DEFAULT &&
558 kve->kve_type != KVME_TYPE_VNODE &&
559 kve->kve_type != KVME_TYPE_SWAP &&
560 kve->kve_type != KVME_TYPE_PHYS))
563 ent = calloc(1, sizeof(*ent));
565 errx(1, "out of memory");
566 ent->start = (vm_offset_t)kve->kve_start;
567 ent->end = (vm_offset_t)kve->kve_end;
568 ent->protection = VM_PROT_READ | VM_PROT_WRITE;
569 if ((kve->kve_protection & KVME_PROT_EXEC) != 0)
570 ent->protection |= VM_PROT_EXECUTE;
580 * Miscellaneous note out functions.
584 elf_note_prpsinfo(void *arg, size_t *sizep)
588 elfcore_prpsinfo_t *psinfo;
589 struct kinfo_proc kip;
594 psinfo = calloc(1, sizeof(*psinfo));
596 errx(1, "out of memory");
597 psinfo->pr_version = PRPSINFO_VERSION;
598 psinfo->pr_psinfosz = sizeof(*psinfo);
602 name[2] = KERN_PROC_PID;
605 if (sysctl(name, 4, &kip, &len, NULL, 0) == -1)
606 err(1, "kern.proc.pid.%u", pid);
607 if (kip.ki_pid != pid)
608 err(1, "kern.proc.pid.%u", pid);
609 strlcpy(psinfo->pr_fname, kip.ki_comm, sizeof(psinfo->pr_fname));
610 name[2] = KERN_PROC_ARGS;
611 len = sizeof(psinfo->pr_psargs) - 1;
612 if (sysctl(name, 4, psinfo->pr_psargs, &len, NULL, 0) == 0 && len > 0) {
613 cp = psinfo->pr_psargs;
616 cp = memchr(cp, '\0', end - cp);
622 strlcpy(psinfo->pr_psargs, kip.ki_comm,
623 sizeof(psinfo->pr_psargs));
624 psinfo->pr_pid = pid;
626 *sizep = sizeof(*psinfo);
631 elf_note_prstatus(void *arg, size_t *sizep)
634 elfcore_prstatus_t *status;
637 tid = *(lwpid_t *)arg;
638 status = calloc(1, sizeof(*status));
640 errx(1, "out of memory");
641 status->pr_version = PRSTATUS_VERSION;
642 status->pr_statussz = sizeof(*status);
643 status->pr_gregsetsz = sizeof(elfcore_gregset_t);
644 status->pr_fpregsetsz = sizeof(elfcore_fpregset_t);
645 status->pr_osreldate = __FreeBSD_version;
646 status->pr_pid = tid;
647 ptrace(PT_GETREGS, tid, (void *)&greg, 0);
648 elf_convert_gregset(&status->pr_reg, &greg);
650 *sizep = sizeof(*status);
655 elf_note_fpregset(void *arg, size_t *sizep)
658 elfcore_fpregset_t *fpregset;
661 tid = *(lwpid_t *)arg;
662 fpregset = calloc(1, sizeof(*fpregset));
663 if (fpregset == NULL)
664 errx(1, "out of memory");
665 ptrace(PT_GETFPREGS, tid, (void *)&fpreg, 0);
666 elf_convert_fpregset(fpregset, &fpreg);
668 *sizep = sizeof(*fpregset);
673 elf_note_thrmisc(void *arg, size_t *sizep)
676 struct ptrace_lwpinfo lwpinfo;
679 tid = *(lwpid_t *)arg;
680 thrmisc = calloc(1, sizeof(*thrmisc));
682 errx(1, "out of memory");
683 ptrace(PT_LWPINFO, tid, (void *)&lwpinfo,
685 memset(&thrmisc->_pad, 0, sizeof(thrmisc->_pad));
686 strcpy(thrmisc->pr_tname, lwpinfo.pl_tdname);
688 *sizep = sizeof(*thrmisc);
692 #if defined(__i386__) || defined(__amd64__)
694 elf_note_x86_xstate(void *arg, size_t *sizep)
698 static bool xsave_checked = false;
699 static struct ptrace_xstate_info info;
701 tid = *(lwpid_t *)arg;
702 if (!xsave_checked) {
703 if (ptrace(PT_GETXSTATE_INFO, tid, (void *)&info,
706 xsave_checked = true;
708 if (info.xsave_len == 0) {
712 xstate = calloc(1, info.xsave_len);
713 ptrace(PT_GETXSTATE, tid, xstate, 0);
714 *(uint64_t *)(xstate + X86_XSTATE_XCR0_OFFSET) = info.xsave_mask;
715 *sizep = info.xsave_len;
720 #if defined(__powerpc__)
722 elf_note_powerpc_vmx(void *arg, size_t *sizep)
726 static bool has_vmx = true;
729 tid = *(lwpid_t *)arg;
731 if (ptrace(PT_GETVRREGS, tid, (void *)&info,
739 vmx = calloc(1, sizeof(*vmx));
740 memcpy(vmx, &info, sizeof(*vmx));
741 *sizep = sizeof(*vmx);
747 procstat_sysctl(void *arg, int what, size_t structsz, size_t *sizep)
751 int name[4], structsize;
755 structsize = structsz;
761 if (sysctl(name, 4, NULL, &len, NULL, 0) == -1)
762 err(1, "kern.proc.%d.%u", what, pid);
763 buf = calloc(1, sizeof(structsize) + len * 4 / 3);
765 errx(1, "out of memory");
766 bcopy(&structsize, buf, sizeof(structsize));
767 p = (char *)buf + sizeof(structsize);
768 if (sysctl(name, 4, p, &len, NULL, 0) == -1)
769 err(1, "kern.proc.%d.%u", what, pid);
771 *sizep = sizeof(structsize) + len;
776 elf_note_procstat_proc(void *arg, size_t *sizep)
779 return (procstat_sysctl(arg, KERN_PROC_PID | KERN_PROC_INC_THREAD,
780 sizeof(struct kinfo_proc), sizep));
784 elf_note_procstat_files(void *arg, size_t *sizep)
787 return (procstat_sysctl(arg, KERN_PROC_FILEDESC,
788 sizeof(struct kinfo_file), sizep));
792 elf_note_procstat_vmmap(void *arg, size_t *sizep)
795 return (procstat_sysctl(arg, KERN_PROC_VMMAP,
796 sizeof(struct kinfo_vmentry), sizep));
800 elf_note_procstat_groups(void *arg, size_t *sizep)
803 return (procstat_sysctl(arg, KERN_PROC_GROUPS, sizeof(gid_t), sizep));
807 elf_note_procstat_umask(void *arg, size_t *sizep)
810 return (procstat_sysctl(arg, KERN_PROC_UMASK, sizeof(u_short), sizep));
814 elf_note_procstat_osrel(void *arg, size_t *sizep)
817 return (procstat_sysctl(arg, KERN_PROC_OSREL, sizeof(int), sizep));
821 elf_note_procstat_psstrings(void *arg, size_t *sizep)
824 return (procstat_sysctl(arg, KERN_PROC_PS_STRINGS,
825 sizeof(vm_offset_t), sizep));
829 elf_note_procstat_auxv(void *arg, size_t *sizep)
832 return (procstat_sysctl(arg, KERN_PROC_AUXV,
833 sizeof(Elf_Auxinfo), sizep));
837 elf_note_procstat_rlimit(void *arg, size_t *sizep)
841 int i, name[5], structsize;
845 structsize = sizeof(struct rlimit) * RLIM_NLIMITS;
846 buf = calloc(1, sizeof(structsize) + structsize);
848 errx(1, "out of memory");
849 bcopy(&structsize, buf, sizeof(structsize));
850 p = (char *)buf + sizeof(structsize);
853 name[2] = KERN_PROC_RLIMIT;
855 len = sizeof(struct rlimit);
856 for (i = 0; i < RLIM_NLIMITS; i++) {
858 if (sysctl(name, 5, p, &len, NULL, 0) == -1)
859 err(1, "kern.proc.rlimit.%u", pid);
860 if (len != sizeof(struct rlimit))
861 errx(1, "kern.proc.rlimit.%u: short read", pid);
865 *sizep = sizeof(structsize) + structsize;
869 struct dumpers __elfN(dump) = { elf_ident, elf_coredump };
870 TEXT_SET(dumpset, __elfN(dump));