Fix bug when whole region is free

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-13 17:25:49 +01:00
parent a52dadc592
commit 8b889c332a

View file

@ -199,9 +199,9 @@ malloc_in_range (struct grub_relocator *rel,
grub_mm_region_t r, rp; grub_mm_region_t r, rp;
for (rp = NULL, r = grub_mm_base; r; rp = r, r = r->next) for (rp = NULL, r = grub_mm_base; r; rp = r, r = r->next)
{ {
grub_dprintf ("relocator", "region %p. %d %d %d\n", r, grub_dprintf ("relocator", "region %p. %d %d %d %d\n", r,
(grub_addr_t) r + r->size + sizeof (*r) >= start, (grub_addr_t) r + r->size + sizeof (*r) >= start,
(grub_addr_t) r < end && r->size + sizeof (*r) >= size, (grub_addr_t) r < end, r->size + sizeof (*r) >= size,
(rb == NULL || (from_low_priv ? rb > r : rb < r))); (rb == NULL || (from_low_priv ? rb > r : rb < r)));
if ((grub_addr_t) r + r->size + sizeof (*r) >= start if ((grub_addr_t) r + r->size + sizeof (*r) >= start
&& (grub_addr_t) r < end && r->size + sizeof (*r) >= size && (grub_addr_t) r < end && r->size + sizeof (*r) >= size
@ -224,7 +224,7 @@ malloc_in_range (struct grub_relocator *rel,
hb = get_best_header (rel, start, end, align, size, rb, &hbp, &best_addr, hb = get_best_header (rel, start, end, align, size, rb, &hbp, &best_addr,
from_low_priv, collisioncheck); from_low_priv, collisioncheck);
grub_dprintf ("relocator", "best header %p/%lx\n", hb, grub_dprintf ("relocator", "best header %p/%p/%lx\n", hb, hbp,
(unsigned long) best_addr); (unsigned long) best_addr);
if (!hb) if (!hb)
@ -253,8 +253,8 @@ malloc_in_range (struct grub_relocator *rel,
- (newreg_start - (newreg_start
- (grub_addr_t) rb)) >> GRUB_MM_ALIGN_LOG2; - (grub_addr_t) rb)) >> GRUB_MM_ALIGN_LOG2;
new_header = (void *) (newreg_start + sizeof (*rb)); new_header = (void *) (newreg_start + sizeof (*rb));
if (newhnext == hb->next) if (newhnext == hb)
newhnext = newhnext; newhnext = new_header;
new_header->next = newhnext; new_header->next = newhnext;
new_header->size = newhsize; new_header->size = newhsize;
new_header->magic = GRUB_MM_FREE_MAGIC; new_header->magic = GRUB_MM_FREE_MAGIC;
@ -280,6 +280,18 @@ malloc_in_range (struct grub_relocator *rel,
rbp->next = newreg; rbp->next = newreg;
else else
grub_mm_base = newreg; grub_mm_base = newreg;
{
grub_mm_header_t h = newreg->first, hp = NULL;
do
{
if ((void *) h < (void *) (newreg + 1))
grub_fatal ("Failed to adjust memory region: %p, %p, %p, %p, %p",
newreg, newreg->first, h, hp, hb);
hp = h;
h = h->next;
}
while (h != newreg->first);
}
} }
*res = best_addr; *res = best_addr;
return 1; return 1;