summaryrefslogtreecommitdiff
path: root/sys/lib/libsa/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/lib/libsa/exec.c')
-rw-r--r--sys/lib/libsa/exec.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/sys/lib/libsa/exec.c b/sys/lib/libsa/exec.c
index 65076e90935..e3e56a9b516 100644
--- a/sys/lib/libsa/exec.c
+++ b/sys/lib/libsa/exec.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.16 1997/06/26 19:11:37 drochner Exp $ */
+/* $NetBSD: exec.c,v 1.17 1997/06/28 07:17:56 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
@@ -47,23 +47,18 @@
#include "stand.h"
-static char *ssym, *esym;
-
-extern u_int opendev;
-
void
exec(path, loadaddr, howto)
char *path;
char *loadaddr;
int howto;
{
- register int io;
#ifndef INSECURE
struct stat sb;
#endif
struct exec x;
- int i;
- register char *addr;
+ int io, i;
+ char *addr, *ssym, *esym;
io = open(path, 0);
if (io < 0)
@@ -80,8 +75,7 @@ exec(path, loadaddr, howto)
#endif
i = read(io, (char *)&x, sizeof(x));
- if (i != sizeof(x) ||
- N_BADMAG(x)) {
+ if (i != sizeof(x) || N_BADMAG(x)) {
errno = EFTYPE;
return;
}
@@ -89,12 +83,11 @@ exec(path, loadaddr, howto)
/* Text */
printf("%ld", x.a_text);
addr = loadaddr;
-#ifdef NO_LSEEK
- if (N_GETMAGIC(x) == ZMAGIC && read(io, (char *)addr, 0x400) == -1)
-#else
- if (N_GETMAGIC(x) == ZMAGIC && lseek(io, 0x400, SEEK_SET) == -1)
-#endif
- goto shread;
+ if (N_GETMAGIC(x) == ZMAGIC) {
+ bcopy(&x, addr, sizeof(x));
+ addr += sizeof(x);
+ x.a_text -= sizeof(x);
+ }
if (read(io, (char *)addr, x.a_text) != x.a_text)
goto shread;
addr += x.a_text;
@@ -117,12 +110,15 @@ exec(path, loadaddr, howto)
ssym = addr;
bcopy(&x.a_syms, addr, sizeof(x.a_syms));
addr += sizeof(x.a_syms);
- printf("+[%ld", x.a_syms);
- if (read(io, addr, x.a_syms) != x.a_syms)
- goto shread;
- addr += x.a_syms;
+ if (x.a_syms) {
+ printf("+[%ld", x.a_syms);
+ if (read(io, addr, x.a_syms) != x.a_syms)
+ goto shread;
+ addr += x.a_syms;
+ }
- if (read(io, &i, sizeof(int)) != sizeof(int))
+ i = 0;
+ if (x.a_syms && read(io, &i, sizeof(int)) != sizeof(int))
goto shread;
bcopy(&i, addr, sizeof(int));
@@ -134,8 +130,10 @@ exec(path, loadaddr, howto)
addr += i;
}
- /* and that many bytes of (debug symbols?) */
- printf("+%d]", i);
+ if (x.a_syms) {
+ /* and that many bytes of (debug symbols?) */
+ printf("+%d]", i);
+ }
close(io);
@@ -145,10 +143,15 @@ exec(path, loadaddr, howto)
#undef round_to_size
/* and note the end address of all this */
- printf(" total=0x%lx", (u_long)addr);
-
- x.a_entry += (long)loadaddr;
- printf(" start=0x%lx\n", x.a_entry);
+ printf(" total=0x%lx\n", (u_long)addr);
+
+ /*
+ * Machine-dependent code must now adjust the
+ * entry point. This used to be done here,
+ * but some systems may need to relocate the
+ * loaded file before jumping to it, and the
+ * displayed start address would be wrong.
+ */
#ifdef EXEC_DEBUG
printf("ssym=0x%x esym=0x%x\n", ssym, esym);