Просмотр исходного кода

[umalloc] Avoid problems when _textdata_memsz is a multiple of 4kB

If it happens that _textdata_memsz ends up being an exact multiple of
4kB, then this will cause the .textdata section (after relocation) to
start on a page boundary.  This means that the hidden memory region
(which is rounded down to the nearest page boundary) will start
exactly at virtual address 0, i.e. UNULL.  This means that
init_eheap() will erroneously assume that it has failed to allocate a
an external heap, since it typically ends up choosing the area that
lies immediately below .textdata, which in this case will be the
region with top==UNULL.

A subsequent error is that memtop_urealloc() passes through the error
return status -ENOMEM to the caller, which (rightly) assumes that the
result represents a valid userptr_t address.

Fixed by using alternative tests for heap non-existence, and by
returning UNULL in case of an error from init_eheap().
tags/v0.9.7
Michael Brown 16 лет назад
Родитель
Сommit
46da51703a
1 измененных файлов: 3 добавлений и 3 удалений
  1. 3
    3
      src/arch/i386/interface/pcbios/memtop_umalloc.c

+ 3
- 3
src/arch/i386/interface/pcbios/memtop_umalloc.c Просмотреть файл

@@ -92,7 +92,7 @@ static int init_eheap ( void ) {
92 92
 		}
93 93
 	}
94 94
 
95
-	if ( ! top ) {
95
+	if ( ! heap_size ) {
96 96
 		DBG ( "No external heap available\n" );
97 97
 		return -ENOMEM;
98 98
 	}
@@ -139,9 +139,9 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
139 139
 	int rc;
140 140
 
141 141
 	/* Initialise external memory allocator if necessary */
142
-	if ( ! top  ) {
142
+	if ( bottom == top ) {
143 143
 		if ( ( rc = init_eheap() ) != 0 )
144
-			return rc;
144
+			return UNULL;
145 145
 	}
146 146
 
147 147
 	/* Get block properties into extmem */

Загрузка…
Отмена
Сохранить