* kern/mm.c (grub_mm_init_region): Check for region size after aligning

pointers.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-05-03 13:07:31 +02:00
parent 2589383147
commit 9b058d5291
2 changed files with 10 additions and 6 deletions

View file

@ -1,3 +1,8 @@
2010-05-01 Vladimir Serbinenko <phcoder@gmail.com>
* kern/mm.c (grub_mm_init_region): Check for region size after aligning
pointers.
2010-05-01 Vladimir Serbinenko <phcoder@gmail.com> 2010-05-01 Vladimir Serbinenko <phcoder@gmail.com>
* kern/mm.c (grub_real_malloc): Fix size calculation when extra == 0. * kern/mm.c (grub_real_malloc): Fix size calculation when extra == 0.

View file

@ -148,15 +148,14 @@ grub_mm_init_region (void *addr, grub_size_t size)
grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size); grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size);
#endif #endif
/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN * 2)
return;
/* Allocate a region from the head. */ /* Allocate a region from the head. */
r = (grub_mm_region_t) (((grub_addr_t) addr + GRUB_MM_ALIGN - 1) r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN);
& (~(GRUB_MM_ALIGN - 1)));
size -= (char *) r - (char *) addr + sizeof (*r); size -= (char *) r - (char *) addr + sizeof (*r);
/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN)
return;
h = (grub_mm_header_t) ((char *) r + GRUB_MM_ALIGN); h = (grub_mm_header_t) ((char *) r + GRUB_MM_ALIGN);
h->next = h; h->next = h;
h->magic = GRUB_MM_FREE_MAGIC; h->magic = GRUB_MM_FREE_MAGIC;