shithub: riscv

Download patch

ref: 2185188f8360ea1952c7339c2702a16f15b12be1
parent: eef4565003def0a1e72bf381665027ebe0420c6f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri May 23 21:27:57 EDT 2014

kernel: fix read size calculation in pio() demand load

on amd64, the text segment is aligned and padded to
2MB, but segment granularity is 4K which can give
us page faults that are beyond the highest file
offset. this is perfectly valid, but was not handled
correctly in pio().

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -211,9 +211,11 @@
 		}
 
 		c = s->image->c;
-		ask = s->flen-soff;
-		if(ask > BY2PG)
-			ask = BY2PG;
+		ask = BY2PG;
+		if(soff >= s->flen)
+			ask = 0;
+		else if((soff+ask) > s->flen)
+			ask = s->flen-soff;
 	}
 	else {			/* from a swap image */
 		daddr = swapaddr(loadrec);