Subject: bin/8575: MI loadfile() cannot load NMAGIC a.out kernel
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tsutsui@ceres.dti.ne.jp>
List: netbsd-bugs
Date: 10/07/1999 05:36:08
>Number:         8575
>Category:       bin
>Synopsis:       MI loadfile() cannot load NMAGIC a.out kernel
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct  7 05:35:00 1999
>Last-Modified:
>Originator:     Izumi Tsutsui
>Organization:
Izumi Tsutsui	Himeji City, Japan
>Release:        NetBSD-current 1.4K 19990918
>Environment:
System: NetBSD 1.4K a.out

>Description:
MI loadfile() does not handle NMAGIC a.out files correctly
so it cannot load them.

>How-To-Repeat:
Use MI loadfile() to load a NMAGIC a.out kernel.
Currently sparc /boot uses MI loadfile()
and also supports a.out kernel.

>Fix:
* Don't count a.out header size on loading a NMAGIC file
* Fix text segment alignment code (from itohy@netbsd.org)

--- /sys/lib/libsa/loadfile.c.orig	1999/09/11 15:58:02
+++ /sys/lib/libsa/loadfile.c	1999/10/07 12:01:30
@@ -450,8 +450,8 @@
 	u_long magic = N_GETMAGIC(*x);
 	int sub;
 
-	/* In OMAGIC, exec header isn't part of text segment */
-	if (magic == OMAGIC)
+	/* In OMAGIC and NMAGIC, exec header isn't part of text segment */
+	if (magic == OMAGIC || magic == NMAGIC)
 		sub = 0;
 	else
 		sub = sizeof(*x);
@@ -468,7 +468,7 @@
 	 * The kernel may use this to verify that the
 	 * symbols were loaded by this boot program.
 	 */
-	if (magic == OMAGIC) {
+	if (magic == OMAGIC || magic == NMAGIC) {
 		if (flags & LOAD_HDR)
 			BCOPY(x, maxp - sizeof(*x), sizeof(*x));
 	}
@@ -502,7 +502,7 @@
 	 * Provide alignment if required
 	 */
 	if (magic == ZMAGIC || magic == NMAGIC) {
-		int size = (int)maxp & __LDPGSZ;
+		int size = -(unsigned int)maxp & (__LDPGSZ - 1);
 
 		if (flags & LOAD_TEXTA) {
 			PROGRESS(("/%d", size));
>Audit-Trail:
>Unformatted: