shithub: riscv

Download patch

ref: 00572496ce8e2e3919586a0ce3df1fc457220ae5
parent: b32300deb06b94f76a4aec144d23bbec3049d85f
author: cinap_lenrek <[email protected]>
date: Fri Nov 6 12:27:15 EST 2015

kernel: use nicer check in okaddr(), wet floor signs in fixfault()

instead of checking addr+len >= addr, check len >= -addr so
that addr == 0 is never valid for len > 0 even if we decide
to have memory at the zero page so theres never any chance
user can pass in "nil" pointers.

put up some signs where we fall thru the switch cases in
fixfault()

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -237,10 +237,8 @@
 				return -1;
 			*pg = new;
 		}
-		goto common;
-
-	case SG_DATA:
-	common:			/* Demand load/pagein/copy on write */
+		/* wet floor */
+	case SG_DATA:			/* Demand load/pagein/copy on write */
 		if(pagedout(*pg))
 			pio(s, addr, soff, pg);
 
@@ -279,6 +277,7 @@
 			new->ref = 1;
 			*pg = new;
 		}
+		/* wet floor */
 	case SG_FIXED:			/* Never paged out */
 		if (checkaddr && addr == addr2check)
 			(*checkaddr)(addr, s, *pg);
@@ -301,7 +300,7 @@
 {
 	Segment *s;
 
-	if((long)len >= 0 && addr+len >= addr) {
+	if((long)len >= 0 && len <= -addr) {
 		for(;;) {
 			s = seg(up, addr, 0);
 			if(s == nil || (write && (s->type&SG_RONLY)))