Bläddra i källkod

[relocate] Guard against systems that report empty memory regions

If the INT 15,e820 memory map reports a region [0,0), this confuses
the "truncate to even megabytes" logic, which ends up rounding the
region 'down' to [0,fff00000).

Fix by ensuring that the region's end address is at least 1, before we
subtract 1 to obtain the "last byte in region" address.
tags/v0.9.4
Michael Brown 15 år sedan
förälder
incheckning
ca0b0f0616
1 ändrade filer med 10 tillägg och 5 borttagningar
  1. 10
    5
      src/arch/i386/core/relocate.c

+ 10
- 5
src/arch/i386/core/relocate.c Visa fil

@@ -93,11 +93,16 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
93 93
 			/* If last byte that might be used (r_end-1)
94 94
 			 * is in an odd megabyte, round down r_end to
95 95
 			 * the top of the next even megabyte.
96
+			 *
97
+			 * Make sure that we don't accidentally wrap
98
+			 * r_end below 0.
96 99
 			 */
97
-			r_end = ( r_end - 1 ) & ~0xfffff;
98
-			DBG ( "...end truncated to %lx "
99
-			      "(avoid ending in odd megabyte)\n",
100
-			      r_end );
100
+			if ( r_end >= 1 ) {
101
+				r_end = ( r_end - 1 ) & ~0xfffff;
102
+				DBG ( "...end truncated to %lx "
103
+				      "(avoid ending in odd megabyte)\n",
104
+				      r_end );
105
+			}
101 106
 		} else if ( ( r_end - size ) & 0x100000 ) {
102 107
 			/* If the last byte that might be used
103 108
 			 * (r_end-1) is in an even megabyte, but the
@@ -108,7 +113,7 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
108 113
 			 * Make sure that we don't accidentally wrap
109 114
 			 * r_end below 0.
110 115
 			 */
111
-			if ( r_end > 0x100000 ) {
116
+			if ( r_end >= 0x100000 ) {
112 117
 				r_end = ( r_end - 0x100000 ) & ~0xfffff;
113 118
 				DBG ( "...end truncated to %lx "
114 119
 				      "(avoid starting in odd megabyte)\n",

Laddar…
Avbryt
Spara