summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2017-05-11 17:26:34 +0000
committerjhb <jhb@FreeBSD.org>2017-05-11 17:26:34 +0000
commit1ab4373cafea8d13701d093b10df86fbd869d37b (patch)
treeecdc1a75821e4bc72e1fd3cf5d2e341984409943 /sys
parent7a83feafdc958c9ea4db14fb1d02cb5bae615e3e (diff)
downloadFreeBSD-src-1ab4373cafea8d13701d093b10df86fbd869d37b.zip
FreeBSD-src-1ab4373cafea8d13701d093b10df86fbd869d37b.tar.gz
MFC 313407,313449: Copy ELF machine/flags from binaries to core dumps.
313407: Copy the e_machine and e_flags fields from the binary into an ELF core dump. In the kernel, cache the machine and flags fields from ELF header to use in the ELF header of a core dump. For gcore, the copy these fields over from the ELF header in the binary. This matters for platforms which encode ABI information in the flags field (such as o32 vs n32 on MIPS). 313449: Trim trailing whitespace (mostly introduced in r313407). Sponsored by: DARPA / AFRL
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/imgact_elf.c10
-rw-r--r--sys/kern/kern_fork.c2
-rw-r--r--sys/sys/proc.h8
3 files changed, 12 insertions, 8 deletions
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 491b9dd..6ae6d67 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1079,6 +1079,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
imgp->interpreted = 0;
imgp->reloc_base = addr;
imgp->proc->p_osrel = osrel;
+ imgp->proc->p_elf_machine = hdr->e_machine;
+ imgp->proc->p_elf_flags = hdr->e_flags;
ret:
free(interp_buf, M_TEMP);
@@ -1682,15 +1684,11 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs,
ehdr->e_ident[EI_ABIVERSION] = 0;
ehdr->e_ident[EI_PAD] = 0;
ehdr->e_type = ET_CORE;
-#if defined(COMPAT_FREEBSD32) && __ELF_WORD_SIZE == 32
- ehdr->e_machine = ELF_ARCH32;
-#else
- ehdr->e_machine = ELF_ARCH;
-#endif
+ ehdr->e_machine = td->td_proc->p_elf_machine;
ehdr->e_version = EV_CURRENT;
ehdr->e_entry = 0;
ehdr->e_phoff = sizeof(Elf_Ehdr);
- ehdr->e_flags = 0;
+ ehdr->e_flags = td->td_proc->p_elf_flags;
ehdr->e_ehsize = sizeof(Elf_Ehdr);
ehdr->e_phentsize = sizeof(Elf_Phdr);
ehdr->e_phnum = numsegs + 1;
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index bb92861..c7680aa 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -408,6 +408,8 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *
bcopy(&p1->p_startcopy, &p2->p_startcopy,
__rangeof(struct proc, p_startcopy, p_endcopy));
+ p2->p_elf_machine = p1->p_elf_machine;
+ p2->p_elf_flags = p1->p_elf_flags;
pargs_hold(p2->p_args);
PROC_UNLOCK(p1);
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 2439e11..5946298 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -316,7 +316,7 @@ struct thread {
} td_state; /* (t) thread state */
union {
register_t tdu_retval[2];
- off_t tdu_off;
+ off_t tdu_off;
} td_uretoff; /* (k) Syscall aux returns. */
#define td_retval td_uretoff.tdu_retval
u_int td_cowgen; /* (k) Generation of COW pointers. */
@@ -626,8 +626,10 @@ struct proc {
our subtree. */
u_int p_xexit; /* (c) Exit code. */
u_int p_xsig; /* (c) Stop/kill sig. */
+
/* End area that is copied on creation. */
-#define p_endcopy p_xsig
+#define p_endcopy p_pgrp
+
struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */
struct knlist *p_klist; /* (c) Knotes attached to this proc. */
int p_numthreads; /* (c) Number of threads. */
@@ -657,6 +659,8 @@ struct proc {
LIST_ENTRY(proc) p_orphan; /* (e) List of orphan processes. */
LIST_HEAD(, proc) p_orphans; /* (e) Pointer to list of orphans. */
u_int p_ptevents; /* (c) ptrace() event mask. */
+ uint16_t p_elf_machine; /* (x) ELF machine type */
+ uint64_t p_elf_flags; /* (x) ELF flags */
};
#define p_session p_pgrp->pg_session
OpenPOWER on IntegriCloud