summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2003-03-12 21:04:04 +0000
committermiod <miod@openbsd.org>2003-03-12 21:04:04 +0000
commite3ee3d4ea3ecbaefe980d8a567de514438dce1e5 (patch)
tree9c2daf1a55a5bd6859065713ff338f933bfe7cb7
parentactually, vput always unlocks the vnode (diff)
downloadwireguard-openbsd-e3ee3d4ea3ecbaefe980d8a567de514438dce1e5.tar.xz
wireguard-openbsd-e3ee3d4ea3ecbaefe980d8a567de514438dce1e5.zip
Make config -e work correctly on the various m68k platforms, by handling
all the various a.out MAGIC correctly, and handling the mvme68k case where kernel_text starts after the a.out header. No functional change, no regression on other a.out arches (i386 and vax). ok deraadt@ henning@
-rw-r--r--usr.sbin/config/exec_aout.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/usr.sbin/config/exec_aout.c b/usr.sbin/config/exec_aout.c
index 80b9dbf97d6..3f8c6ca46e2 100644
--- a/usr.sbin/config/exec_aout.c
+++ b/usr.sbin/config/exec_aout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_aout.c,v 1.4 2002/03/14 06:51:42 mpech Exp $ */
+/* $OpenBSD: exec_aout.c,v 1.5 2003/03/12 21:04:04 miod Exp $ */
/*
* Copyright (c) 1999 Mats O Jansson. All rights reserved.
@@ -30,7 +30,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: exec_aout.c,v 1.4 2002/03/14 06:51:42 mpech Exp $";
+static char rcsid[] = "$OpenBSD: exec_aout.c,v 1.5 2003/03/12 21:04:04 miod Exp $";
#endif
#include <err.h>
@@ -46,29 +46,65 @@ static char rcsid[] = "$OpenBSD: exec_aout.c,v 1.4 2002/03/14 06:51:42 mpech Exp
#include "ukc.h"
caddr_t aout_p, aout_r;
-int aout_psz = 0, aout_rsz = 0;
+unsigned long aout_psz = 0, aout_rsz = 0;
struct exec aout_ex;
+unsigned long aout_adjvalue = 0;
+unsigned long aout_datashift = 0;
+void
+aout_computeadj()
+{
+ aout_adjvalue = (unsigned long)aout_p +
+ N_TXTOFF(aout_ex) - nl[P_KERNEL_TEXT].n_value;
+
+ /*
+ * On m68k a.out ZMAGIC kernel, kernel_text begins _after_ the a.out
+ * header, so compensate for it.
+ */
+ if (nl[P_KERNEL_TEXT].n_value & (__LDPGSZ - 1))
+ aout_adjvalue += sizeof(aout_ex);
+
+ /*
+ * On NMAGIC kernel, we need an extra relocation for the data area
+ */
+ aout_datashift = (N_DATADDR(aout_ex) - N_TXTADDR(aout_ex)) -
+ aout_ex.a_text;
+}
+
+/* ``kernel'' vaddr -> in-memory address */
caddr_t
aout_adjust(x)
caddr_t x;
{
- unsigned long y;
- y = (unsigned long)x - nl[P_KERNEL_TEXT].n_value + (unsigned long)aout_p +
- N_TXTOFF(aout_ex);
- return((caddr_t)y);
+ if (aout_adjvalue == 0)
+ aout_computeadj();
+
+ if (aout_datashift != 0 &&
+ (unsigned long)x >= N_DATADDR(aout_ex))
+ x -= aout_datashift;
+
+ return (x + aout_adjvalue);
}
+/* in-memory address -> ``kernel'' vaddr */
caddr_t
aout_readjust(x)
caddr_t x;
{
- unsigned long y;
+ caddr_t y;
+
+#if 0 /* unnecessary, aout_adjust() is always invoked first */
+ if (aout_adjvalue == 0)
+ aout_computeadj();
+#endif
+
+ y = x - aout_adjvalue;
+ if (aout_datashift != 0 &&
+ (unsigned long)y >= N_TXTADDR(aout_ex) + aout_ex.a_text)
+ y += aout_datashift;
- y = (unsigned long)x - (unsigned long)aout_p + nl[P_KERNEL_TEXT].n_value -
- N_TXTOFF(aout_ex);
- return((caddr_t)y);
+ return (y);
}
int
@@ -106,9 +142,10 @@ aout_loadkernel(file)
if (N_BADMAG(aout_ex))
errx(1, "bad a.out magic");
- (void)lseek(fd, (off_t)0, SEEK_SET);
+ lseek(fd, (off_t)0, SEEK_SET);
- aout_psz = (int)(aout_ex.a_text+aout_ex.a_data);
+ aout_psz = (int)(aout_ex.a_text + N_TXTOFF(aout_ex) +
+ aout_ex.a_data);
aout_p = malloc(aout_psz);