From: Kevin O'Connor Date: Sat, 14 Dec 2013 18:14:02 +0000 (-0500) Subject: Remove the pmm handle argument from _malloc(). X-Git-Tag: rel-1.7.5-rc1~95 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=743c1575390188fd628ecd0333bb679e8ecc0bec;p=seabios.git Remove the pmm handle argument from _malloc(). The PMM handle argument will almost always be 0xffffffff. Use separate code for the few rare cases where it may not be the default value. Gcc produces better code if _malloc() only requires three parameters. Signed-off-by: Kevin O'Connor --- diff --git a/src/fw/csm.c b/src/fw/csm.c index dfb0d12..a44ed26 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -257,9 +257,9 @@ handle_csm_0006(struct bregs *regs) size, align, region); if (region & 2) - chunk = _malloc(&ZoneLow, MALLOC_DEFAULT_HANDLE, size, align); + chunk = _malloc(&ZoneLow, size, align); if (!chunk && (region & 1)) - chunk = _malloc(&ZoneFSeg, MALLOC_DEFAULT_HANDLE, size, align); + chunk = _malloc(&ZoneFSeg, size, align); dprintf(3, "Legacy16GetTableAddress size %x align %x region %d yields %p\n", size, align, region, chunk); diff --git a/src/fw/romfile_loader.c b/src/fw/romfile_loader.c index 325a0fa..f4b17ff 100644 --- a/src/fw/romfile_loader.c +++ b/src/fw/romfile_loader.c @@ -57,7 +57,7 @@ static void romfile_loader_allocate(struct romfile_loader_entry_s *entry, file->file = romfile_find(entry->alloc_file); if (!file->file || !file->file->size) return; - data = _malloc(zone, MALLOC_DEFAULT_HANDLE, file->file->size, alloc_align); + data = _malloc(zone, file->file->size, alloc_align); if (!data) { warn_noalloc(); return; diff --git a/src/malloc.c b/src/malloc.c index 6ef418a..c4cb171 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -225,7 +225,7 @@ zonelow_expand(u32 size, u32 align, struct allocinfo_s *fill) // Allocate memory from the given zone and track it as a PMM allocation void * __malloc -_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) +_malloc(struct zone_s *zone, u32 size, u32 align) { ASSERT32FLAT(); if (!size) @@ -240,6 +240,7 @@ _malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) if (!detail) return NULL; } + detail->handle = MALLOC_DEFAULT_HANDLE; // Find and reserve space for main allocation void *data = allocSpace(zone, size, align, &detail->datainfo); @@ -250,9 +251,8 @@ _malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) return NULL; } - dprintf(8, "_malloc zone=%p handle=%x size=%d align=%x ret=%p (detail=%p)\n" - , zone, handle, size, align, data, detail); - detail->handle = handle; + dprintf(8, "_malloc zone=%p size=%d align=%x ret=%p (detail=%p)\n" + , zone, size, align, data, detail); return data; } @@ -296,9 +296,22 @@ malloc_getspace(struct zone_s *zone) return maxspace - reserve; } +// Set a handle associated with an allocation. +void +malloc_sethandle(void *data, u32 handle) +{ + ASSERT32FLAT(); + struct allocinfo_s *info = findAlloc(data); + if (!info || data == (void*)info || data == info->dataend) + return; + struct allocdetail_s *detail = container_of( + info, struct allocdetail_s, datainfo); + detail->handle = handle; +} + // Find the data block allocated with _malloc with a given handle. void * -malloc_find(u32 handle) +malloc_findhandle(u32 handle) { int i; for (i=0; i