Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Two small changes to the ELF exec code:
details: https://anonhg.NetBSD.org/src/rev/9fdbcaaf44f9
branches: trunk
changeset: 542491:9fdbcaaf44f9
user: atatat <atatat%NetBSD.org@localhost>
date: Thu Jan 30 20:03:46 2003 +0000
description:
Two small changes to the ELF exec code:
(1) ELFNAME(load_file)() now takes a pointer to the entry point
offset, instead of taking a pointer to the entry point itself. This
allows proper adjustment of the ultimate entry point at a higher level
if the object containing the entry point is moved before the exec is
finished.
(2) Introduce VMCMD_FIXED, which means the address at which a given
vmcmd describes a mapping is fixed (ie, should not be moved). Don't
set this for entries pertaining to ld.so.
Also some minor comment/whitespace tweaks.
diffstat:
sys/kern/exec_elf32.c | 22 +++++++++++++---------
sys/kern/exec_subr.c | 13 ++++++++-----
sys/kern/sysv_shm.c | 6 +++---
sys/sys/exec.h | 11 ++++++-----
4 files changed, 30 insertions(+), 22 deletions(-)
diffs (207 lines):
diff -r 7d33fe719c63 -r 9fdbcaaf44f9 sys/kern/exec_elf32.c
--- a/sys/kern/exec_elf32.c Thu Jan 30 19:59:29 2003 +0000
+++ b/sys/kern/exec_elf32.c Thu Jan 30 20:03:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf32.c,v 1.78 2003/01/19 22:52:11 simonb Exp $ */
+/* $NetBSD: exec_elf32.c,v 1.79 2003/01/30 20:03:46 atatat Exp $ */
/*-
* Copyright (c) 1994, 2000 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.78 2003/01/19 22:52:11 simonb Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.79 2003/01/30 20:03:46 atatat Exp $");
/* If not included by exec_elf64.c, ELFSIZE won't be defined. */
#ifndef ELFSIZE
@@ -313,7 +313,7 @@
*/
int
ELFNAME(load_file)(struct proc *p, struct exec_package *epp, char *path,
- struct exec_vmcmd_set *vcset, u_long *entry, struct elf_args *ap,
+ struct exec_vmcmd_set *vcset, u_long *entryoff, struct elf_args *ap,
Elf_Addr *last)
{
int error, i;
@@ -407,12 +407,12 @@
/* If entry is within this section it must be text */
if (eh.e_entry >= ph[i].p_vaddr &&
eh.e_entry < (ph[i].p_vaddr + size)) {
- *entry = addr + eh.e_entry - ph[i].p_vaddr;
- ap->arg_interp = addr;
+ *entryoff = eh.e_entry - ph[i].p_vaddr;
}
if (base_ph == NULL)
base_ph = &ph[i];
- addr += size;
+ if (ph[i].p_vaddr != 0)
+ addr += size;
break;
case PT_DYNAMIC:
@@ -547,7 +547,7 @@
if (nload++ == 2)
goto bad;
ELFNAME(load_psection)(&epp->ep_vmcmds, epp->ep_vp,
- &ph[i], &addr, &size, &prot, 0);
+ &ph[i], &addr, &size, &prot, VMCMD_FIXED);
/*
* Decide whether it's text or data by looking
@@ -601,18 +601,22 @@
/*
* Check if we found a dynamically linked binary and arrange to load
- * it's interpreter
+ * its interpreter
*/
if (interp[0]) {
struct elf_args *ap;
+ int i = epp->ep_vmcmds.evs_used;
+ u_long interp_offset;
MALLOC(ap, struct elf_args *, sizeof(struct elf_args),
M_TEMP, M_WAITOK);
if ((error = ELFNAME(load_file)(p, epp, interp,
- &epp->ep_vmcmds, &epp->ep_entry, ap, &pos)) != 0) {
+ &epp->ep_vmcmds, &interp_offset, ap, &pos)) != 0) {
FREE(ap, M_TEMP);
goto bad;
}
+ ap->arg_interp = epp->ep_vmcmds.evs_cmds[i].ev_addr;
+ epp->ep_entry = ap->arg_interp + interp_offset;
ap->arg_phaddr = phdr;
ap->arg_phentsize = eh->e_phentsize;
diff -r 7d33fe719c63 -r 9fdbcaaf44f9 sys/kern/exec_subr.c
--- a/sys/kern/exec_subr.c Thu Jan 30 19:59:29 2003 +0000
+++ b/sys/kern/exec_subr.c Thu Jan 30 20:03:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_subr.c,v 1.32 2003/01/12 05:24:17 matt Exp $ */
+/* $NetBSD: exec_subr.c,v 1.33 2003/01/30 20:03:46 atatat Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.32 2003/01/12 05:24:17 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.33 2003/01/30 20:03:46 atatat Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -138,6 +138,7 @@
{
struct uvm_object *uobj;
int error;
+ const int fixed = (cmd->ev_flags & VMCMD_FIXED) ? UVM_FLAG_FIXED : 0;
KASSERT(cmd->ev_vp->v_flag & VTEXT);
@@ -170,7 +171,7 @@
error = uvm_map(&p->p_vmspace->vm_map, &cmd->ev_addr, cmd->ev_len,
uobj, cmd->ev_offset, 0,
UVM_MAPFLAG(cmd->ev_prot, VM_PROT_ALL, UVM_INH_COPY,
- UVM_ADV_NORMAL, UVM_FLAG_COPYONW|UVM_FLAG_FIXED));
+ UVM_ADV_NORMAL, UVM_FLAG_COPYONW|fixed));
if (error) {
uobj->pgops->pgo_detach(uobj);
}
@@ -188,6 +189,7 @@
{
int error;
long diff;
+ const int fixed = (cmd->ev_flags & VMCMD_FIXED) ? UVM_FLAG_FIXED : 0;
if (cmd->ev_len == 0)
return 0;
@@ -201,7 +203,7 @@
round_page(cmd->ev_len), NULL, UVM_UNKNOWN_OFFSET, 0,
UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
UVM_ADV_NORMAL,
- UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
+ fixed|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
if (error)
return error;
@@ -257,6 +259,7 @@
{
int error;
long diff;
+ const int fixed = (cmd->ev_flags & VMCMD_FIXED) ? UVM_FLAG_FIXED : 0;
diff = cmd->ev_addr - trunc_page(cmd->ev_addr);
cmd->ev_addr -= diff; /* required by uvm_map */
@@ -266,7 +269,7 @@
round_page(cmd->ev_len), NULL, UVM_UNKNOWN_OFFSET, 0,
UVM_MAPFLAG(cmd->ev_prot, UVM_PROT_ALL, UVM_INH_COPY,
UVM_ADV_NORMAL,
- UVM_FLAG_FIXED|UVM_FLAG_COPYONW));
+ fixed|UVM_FLAG_COPYONW));
return error;
}
diff -r 7d33fe719c63 -r 9fdbcaaf44f9 sys/kern/sysv_shm.c
--- a/sys/kern/sysv_shm.c Thu Jan 30 19:59:29 2003 +0000
+++ b/sys/kern/sysv_shm.c Thu Jan 30 20:03:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysv_shm.c,v 1.65 2003/01/18 10:06:36 thorpej Exp $ */
+/* $NetBSD: sysv_shm.c,v 1.66 2003/01/30 20:03:46 atatat Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.65 2003/01/18 10:06:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.66 2003/01/30 20:03:46 atatat Exp $");
#define SYSVSHM
@@ -302,7 +302,7 @@
else
return EINVAL;
} else {
- /* This is just a hint to vm_mmap() about where to put it. */
+ /* This is just a hint to uvm_mmap() about where to put it. */
attach_va =
round_page((vaddr_t)p->p_vmspace->vm_taddr +
MAXTSIZ + MAXDSIZ);
diff -r 7d33fe719c63 -r 9fdbcaaf44f9 sys/sys/exec.h
--- a/sys/sys/exec.h Thu Jan 30 19:59:29 2003 +0000
+++ b/sys/sys/exec.h Thu Jan 30 20:03:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.h,v 1.89 2003/01/18 09:53:18 thorpej Exp $ */
+/* $NetBSD: exec.h,v 1.90 2003/01/30 20:03:47 atatat Exp $ */
/*-
* Copyright (c) 1994 Christopher G. Demetriou
@@ -169,6 +169,7 @@
int ev_flags;
#define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */
#define VMCMD_BASE 0x0002 /* marks a base entry */
+#define VMCMD_FIXED 0x0004 /* entry must be mapped at ev_addr */
};
#ifdef _KERNEL
@@ -231,12 +232,12 @@
vcp->ev_len = (len); \
vcp->ev_addr = (addr); \
if ((vcp->ev_vp = (vp)) != NULLVP) \
- VREF(vp); \
- vcp->ev_offset = (offset); \
- vcp->ev_prot = (prot); \
+ VREF(vp); \
+ vcp->ev_offset = (offset); \
+ vcp->ev_prot = (prot); \
vcp->ev_flags = (flags); \
} while (/* CONSTCOND */ 0)
-#endif /* EXEC_DEBUG */
+#endif /* DEBUG */
#endif /* _KERNEL */
Home |
Main Index |
Thread Index |
Old Index