Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/lib/libsa To avoid backwards seeks on sequential devices...
details: https://anonhg.NetBSD.org/src/rev/901394748eef
branches: trunk
changeset: 517266:901394748eef
user: scw <scw%NetBSD.org@localhost>
date: Fri Nov 09 18:31:08 2001 +0000
description:
To avoid backwards seeks on sequential devices (eq. QIC tapes), read all
the program headers in one operation into an internal buffer.
diffstat:
sys/lib/libsa/loadfile_elf32.c | 68 +++++++++++++++++++++++------------------
1 files changed, 38 insertions(+), 30 deletions(-)
diffs (123 lines):
diff -r 65ea4df49365 -r 901394748eef sys/lib/libsa/loadfile_elf32.c
--- a/sys/lib/libsa/loadfile_elf32.c Fri Nov 09 18:27:59 2001 +0000
+++ b/sys/lib/libsa/loadfile_elf32.c Fri Nov 09 18:31:08 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile_elf32.c,v 1.4 2001/10/31 21:24:09 thorpej Exp $ */
+/* $NetBSD: loadfile_elf32.c,v 1.5 2001/11/09 18:31:08 scw Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -308,6 +308,7 @@
int flags;
{
Elf_Shdr *shp;
+ Elf_Phdr *phdr;
int i, j;
size_t sz;
int first;
@@ -316,20 +317,24 @@
internalize_ehdr(elf->e_ident[EI_DATA], elf);
+ sz = elf->e_phnum * sizeof(Elf_Phdr);
+ phdr = ALLOC(sz);
+
+ if (lseek(fd, elf->e_phoff, SEEK_SET) == -1) {
+ WARN(("lseek phdr"));
+ FREE(phdr, sz);
+ return 1;
+ }
+ if (read(fd, phdr, sz) != sz) {
+ WARN(("read program headers"));
+ FREE(phdr, sz);
+ return 1;
+ }
+
for (first = 1, i = 0; i < elf->e_phnum; i++) {
- Elf_Phdr phdr;
- if (lseek(fd, elf->e_phoff + sizeof(phdr) * i, SEEK_SET)
- == -1) {
- WARN(("lseek phdr"));
- return 1;
- }
- if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) {
- WARN(("read phdr"));
- return 1;
- }
- internalize_phdr(elf->e_ident[EI_DATA], &phdr);
- if (phdr.p_type != PT_LOAD ||
- (phdr.p_flags & (PF_W|PF_X)) == 0)
+ internalize_phdr(elf->e_ident[EI_DATA], &phdr[i]);
+ if (phdr[i].p_type != PT_LOAD ||
+ (phdr[i].p_flags & (PF_W|PF_X)) == 0)
continue;
#define IS_TEXT(p) (p.p_flags & PF_X)
@@ -338,48 +343,51 @@
/*
* XXX: Assume first address is lowest
*/
- if ((IS_TEXT(phdr) && (flags & LOAD_TEXT)) ||
- (IS_DATA(phdr) && (flags & LOAD_DATA))) {
+ if ((IS_TEXT(phdr[i]) && (flags & LOAD_TEXT)) ||
+ (IS_DATA(phdr[i]) && (flags & LOAD_DATA))) {
/* Read in segment. */
PROGRESS(("%s%lu", first ? "" : "+",
- (u_long)phdr.p_filesz));
+ (u_long)phdr[i].p_filesz));
- if (lseek(fd, phdr.p_offset, SEEK_SET) == -1) {
+ if (lseek(fd, phdr[i].p_offset, SEEK_SET) == -1) {
WARN(("lseek text"));
+ FREE(phdr, sz);
return 1;
}
- if (READ(fd, phdr.p_vaddr, phdr.p_filesz) !=
- phdr.p_filesz) {
+ if (READ(fd, phdr[i].p_vaddr, phdr[i].p_filesz) !=
+ phdr[i].p_filesz) {
WARN(("read text"));
+ FREE(phdr, sz);
return 1;
}
first = 0;
}
- if ((IS_TEXT(phdr) && (flags & (LOAD_TEXT|COUNT_TEXT))) ||
- (IS_DATA(phdr) && (flags & (LOAD_DATA|COUNT_TEXT)))) {
- pos = phdr.p_vaddr;
+ if ((IS_TEXT(phdr[i]) && (flags & (LOAD_TEXT|COUNT_TEXT))) ||
+ (IS_DATA(phdr[i]) && (flags & (LOAD_DATA|COUNT_TEXT)))) {
+ pos = phdr[i].p_vaddr;
if (minp > pos)
minp = pos;
- pos += phdr.p_filesz;
+ pos += phdr[i].p_filesz;
if (maxp < pos)
maxp = pos;
}
/* Zero out bss. */
- if (IS_BSS(phdr) && (flags & LOAD_BSS)) {
+ if (IS_BSS(phdr[i]) && (flags & LOAD_BSS)) {
PROGRESS(("+%lu",
- (u_long)(phdr.p_memsz - phdr.p_filesz)));
- BZERO((phdr.p_vaddr + phdr.p_filesz),
- phdr.p_memsz - phdr.p_filesz);
+ (u_long)(phdr[i].p_memsz - phdr[i].p_filesz)));
+ BZERO((phdr[i].p_vaddr + phdr[i].p_filesz),
+ phdr[i].p_memsz - phdr[i].p_filesz);
}
- if (IS_BSS(phdr) && (flags & (LOAD_BSS|COUNT_BSS))) {
- pos += phdr.p_memsz - phdr.p_filesz;
+ if (IS_BSS(phdr[i]) && (flags & (LOAD_BSS|COUNT_BSS))) {
+ pos += phdr[i].p_memsz - phdr[i].p_filesz;
if (maxp < pos)
maxp = pos;
}
}
+ FREE(phdr, sz);
/*
* Copy the ELF and section headers.
Home |
Main Index |
Thread Index |
Old Index