Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Small cleanup:
details: https://anonhg.NetBSD.org/src/rev/61a7872e78b7
branches: trunk
changeset: 326755:61a7872e78b7
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Feb 16 17:46:36 2014 +0000
description:
Small cleanup:
- make elf_load_file() and elf_load_psection() static
- make loops consistent
- 'nload' is not used - see rev1.24
- 'ap' is not used in elf_load_file()
ok agc@ christos@
diffstat:
sys/kern/exec_elf.c | 68 ++++++++++++++++++++++++----------------------------
1 files changed, 31 insertions(+), 37 deletions(-)
diffs (193 lines):
diff -r f718eea976b0 -r 61a7872e78b7 sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Sun Feb 16 16:13:37 2014 +0000
+++ b/sys/kern/exec_elf.c Sun Feb 16 17:46:36 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.57 2014/02/15 17:39:03 christos Exp $ */
+/* $NetBSD: exec_elf.c,v 1.58 2014/02/16 17:46:36 maxv Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.57 2014/02/15 17:39:03 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.58 2014/02/16 17:46:36 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -98,10 +98,12 @@
#define coredump ELFNAMEEND(coredump)
#define elf_free_emul_arg ELFNAME(free_emul_arg)
-int elf_load_file(struct lwp *, struct exec_package *, char *,
- struct exec_vmcmd_set *, u_long *, struct elf_args *, Elf_Addr *);
-void elf_load_psection(struct exec_vmcmd_set *, struct vnode *,
- const Elf_Phdr *, Elf_Addr *, u_long *, int *, int);
+static int
+elf_load_file(struct lwp *, struct exec_package *, char *,
+ struct exec_vmcmd_set *, u_long *, Elf_Addr *);
+static void
+elf_load_psection(struct exec_vmcmd_set *, struct vnode *, const Elf_Phdr *,
+ Elf_Addr *, u_long *, int *, int);
int netbsd_elf_signature(struct lwp *, struct exec_package *, Elf_Ehdr *);
int netbsd_elf_probe(struct lwp *, struct exec_package *, void *, char *,
@@ -312,7 +314,7 @@
*
* Load a psection at the appropriate address
*/
-void
+static void
elf_load_psection(struct exec_vmcmd_set *vcset, struct vnode *vp,
const Elf_Phdr *ph, Elf_Addr *addr, u_long *size, int *prot, int flags)
{
@@ -398,17 +400,15 @@
* [stolen from coff_load_shlib()]. Made slightly generic
* so it might be used externally.
*/
-int
+static int
elf_load_file(struct lwp *l, struct exec_package *epp, char *path,
- struct exec_vmcmd_set *vcset, u_long *entryoff, struct elf_args *ap,
- Elf_Addr *last)
+ struct exec_vmcmd_set *vcset, u_long *entryoff, Elf_Addr *last)
{
int error, i;
struct vnode *vp;
struct vattr attr;
Elf_Ehdr eh;
Elf_Phdr *ph = NULL;
- const Elf_Phdr *ph0;
const Elf_Phdr *base_ph;
const Elf_Phdr *last_ph;
u_long phsize;
@@ -524,12 +524,11 @@
* Find the start and ending addresses of the psections to
* be loaded. This will give us the size.
*/
- for (i = 0, ph0 = ph, base_ph = NULL; i < eh.e_phnum;
- i++, ph0++) {
- if (ph0->p_type == PT_LOAD) {
- u_long psize = ph0->p_vaddr + ph0->p_memsz;
+ for (i = 0, base_ph = NULL; i < eh.e_phnum; i++) {
+ if (ph[i].p_type == PT_LOAD) {
+ u_long psize = ph[i].p_vaddr + ph[i].p_memsz;
if (base_ph == NULL)
- base_ph = ph0;
+ base_ph = &ph[i];
if (psize > limit)
limit = psize;
}
@@ -552,9 +551,8 @@
/*
* Load all the necessary sections
*/
- for (i = 0, ph0 = ph, base_ph = NULL, last_ph = NULL;
- i < eh.e_phnum; i++, ph0++) {
- switch (ph0->p_type) {
+ for (i = 0, base_ph = NULL, last_ph = NULL; i < eh.e_phnum; i++) {
+ switch (ph[i].p_type) {
case PT_LOAD: {
u_long size;
int prot = 0;
@@ -567,18 +565,18 @@
* properly (align down for topdown and align
* upwards for not topdown).
*/
- base_ph = ph0;
+ base_ph = &ph[i];
flags = VMCMD_BASE;
if (addr == ELF_LINK_ADDR)
- addr = ph0->p_vaddr;
+ addr = ph[i].p_vaddr;
if (use_topdown)
- addr = ELF_TRUNC(addr, ph0->p_align);
+ addr = ELF_TRUNC(addr, ph[i].p_align);
else
- addr = ELF_ROUND(addr, ph0->p_align);
+ addr = ELF_ROUND(addr, ph[i].p_align);
} else {
u_long limit = round_page(last_ph->p_vaddr
+ last_ph->p_memsz);
- u_long base = trunc_page(ph0->p_vaddr);
+ u_long base = trunc_page(ph[i].p_vaddr);
/*
* If there is a gap in between the psections,
@@ -592,10 +590,10 @@
0, VM_PROT_NONE, VMCMD_RELATIVE);
}
- addr = ph0->p_vaddr - base_ph->p_vaddr;
+ addr = ph[i].p_vaddr - base_ph->p_vaddr;
flags = VMCMD_RELATIVE;
}
- last_ph = ph0;
+ last_ph = &ph[i];
elf_load_psection(vcset, vp, &ph[i], &addr,
&size, &prot, flags);
/*
@@ -603,8 +601,8 @@
* must contain the .text section. *entryoff is
* relative to the base psection.
*/
- if (eh.e_entry >= ph0->p_vaddr &&
- eh.e_entry < (ph0->p_vaddr + size)) {
+ if (eh.e_entry >= ph[i].p_vaddr &&
+ eh.e_entry < (ph[i].p_vaddr + size)) {
*entryoff = eh.e_entry - base_ph->p_vaddr;
}
addr += size;
@@ -613,8 +611,6 @@
case PT_DYNAMIC:
case PT_PHDR:
- break;
-
case PT_NOTE:
break;
@@ -659,7 +655,7 @@
Elf_Ehdr *eh = epp->ep_hdr;
Elf_Phdr *ph, *pp;
Elf_Addr phdr = 0, computed_phdr = 0, pos = 0, end_text = 0;
- int error, i, nload;
+ int error, i;
char *interp = NULL;
u_long phsize;
struct elf_args *ap = NULL;
@@ -749,13 +745,11 @@
/*
* Load all the necessary sections
*/
- for (i = nload = 0; i < eh->e_phnum; i++) {
- Elf_Addr addr = ELFDEFNNAME(NO_ADDR);
+ for (i = 0; i < eh->e_phnum; i++) {
+ Elf_Addr addr = ELFDEFNNAME(NO_ADDR);
u_long size = 0;
int prot = 0;
- pp = &ph[i];
-
switch (ph[i].p_type) {
case PT_LOAD:
elf_load_psection(&epp->ep_vmcmds, epp->ep_vp,
@@ -792,7 +786,7 @@
break;
case PT_PHDR:
/* Note address of program headers (in text segment) */
- phdr = pp->p_vaddr;
+ phdr = ph[i].p_vaddr;
break;
default:
@@ -821,7 +815,7 @@
u_long interp_offset = 0;
if ((error = elf_load_file(l, epp, interp,
- &epp->ep_vmcmds, &interp_offset, ap, &pos)) != 0) {
+ &epp->ep_vmcmds, &interp_offset, &pos)) != 0) {
kmem_free(ap, sizeof(*ap));
goto bad;
}
Home |
Main Index |
Thread Index |
Old Index