shithub: riscv

Download patch

ref: 4ec93f94c92eec46433a962eb0f86b6f27909e6c
parent: 3ca9ac70c4f41ff57617d4cfcf46caa304db9a01
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Jul 10 19:56:39 EDT 2015

kernel: use HDR_MAGIC constant to handle Exec header extension, make rebootcmd() handle AOUT_MAGIC macro

--- a/sys/src/9/port/rebootcmd.c
+++ b/sys/src/9/port/rebootcmd.c
@@ -70,14 +70,17 @@
 	text = l2be(exec.text);
 	data = l2be(exec.data);
 
-	if(AOUT_MAGIC == S_MAGIC || AOUT_MAGIC == I_MAGIC){
-		if(magic != S_MAGIC && magic != I_MAGIC)
+	if(!(magic == AOUT_MAGIC)){
+		switch(magic){
+		case I_MAGIC:
+		case S_MAGIC:
+			if((I_MAGIC == AOUT_MAGIC) || (S_MAGIC == AOUT_MAGIC))
+				break;
+		default:
 			error(Ebadexec);
-	} else if(magic != AOUT_MAGIC)
-		error(Ebadexec);
-
-	/* amd64 extra header */
-	if(magic == S_MAGIC)
+		}
+	}
+	if(magic & HDR_MAGIC)
 		readn(c, &exec, 8);
 
 	/* round text out to page boundary */
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -282,15 +282,16 @@
 			error(Ebadexec);
 		magic = l2be(exec.magic);
 		if(n == sizeof(Exec) && (magic == AOUT_MAGIC)){
-			text = l2be(exec.text);
 			entry = l2be(exec.entry);
-			switch(magic){
-			case S_MAGIC:
+			text = l2be(exec.text);
+			if(magic & HDR_MAGIC)
 				text += 8;
-				align = 0x200000;	/* 2MB segment alignment for amd64 */
+			switch(magic){
+			case S_MAGIC:	/* 2MB segment alignment for amd64 */
+				align = 0x200000;
 				break;
-			case V_MAGIC:
-				align = 0x4000;		/* MIPS has 16K page alignment */
+			case V_MAGIC:	/* 16K segment alignment for mips */
+				align = 0x4000;
 				break;
 			}
 			if(text >= (USTKTOP-USTKSIZE)-(UTZERO+sizeof(Exec))