Browse Source

[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 16 years ago
parent
commit
ca0b0f0616
1 changed files with 10 additions and 5 deletions
  1. 10
    5
      src/arch/i386/core/relocate.c

+ 10
- 5
src/arch/i386/core/relocate.c View File

93
 			/* If last byte that might be used (r_end-1)
93
 			/* If last byte that might be used (r_end-1)
94
 			 * is in an odd megabyte, round down r_end to
94
 			 * is in an odd megabyte, round down r_end to
95
 			 * the top of the next even megabyte.
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
 		} else if ( ( r_end - size ) & 0x100000 ) {
106
 		} else if ( ( r_end - size ) & 0x100000 ) {
102
 			/* If the last byte that might be used
107
 			/* If the last byte that might be used
103
 			 * (r_end-1) is in an even megabyte, but the
108
 			 * (r_end-1) is in an even megabyte, but the
108
 			 * Make sure that we don't accidentally wrap
113
 			 * Make sure that we don't accidentally wrap
109
 			 * r_end below 0.
114
 			 * r_end below 0.
110
 			 */
115
 			 */
111
-			if ( r_end > 0x100000 ) {
116
+			if ( r_end >= 0x100000 ) {
112
 				r_end = ( r_end - 0x100000 ) & ~0xfffff;
117
 				r_end = ( r_end - 0x100000 ) & ~0xfffff;
113
 				DBG ( "...end truncated to %lx "
118
 				DBG ( "...end truncated to %lx "
114
 				      "(avoid starting in odd megabyte)\n",
119
 				      "(avoid starting in odd megabyte)\n",

Loading…
Cancel
Save