Closing #7227:
* fix debug-heap's handling of page-guarded allocations in realloc() * let calloc() use page-guarded allocations, too, if requested git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40533 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2000,19 +2000,38 @@ realloc(void *address, size_t newSize)
|
|||||||
if (info->magic == kAreaAllocationMagic && info->area == area
|
if (info->magic == kAreaAllocationMagic && info->area == area
|
||||||
&& info->size == areaInfo.size && info->base == areaInfo.address
|
&& info->size == areaInfo.size && info->base == areaInfo.address
|
||||||
&& info->allocation_size < areaInfo.size) {
|
&& info->allocation_size < areaInfo.size) {
|
||||||
size_t available = info->size - ((addr_t)info->allocation_base
|
if (sUseGuardPage) {
|
||||||
- (addr_t)info->base);
|
size_t available = info->size - B_PAGE_SIZE
|
||||||
|
- sizeof(area_allocation_info);
|
||||||
|
|
||||||
if (available >= newSize) {
|
if (available >= newSize) {
|
||||||
// there is enough room available for the newSize
|
// there is enough room available for the newSize
|
||||||
INFO(("realloc(): new size %ld fits in old area %ld with %ld "
|
newAddress = (void*)((addr_t)info->allocation_base
|
||||||
"available\n", newSize, area, available));
|
+ info->allocation_size - newSize);
|
||||||
info->allocation_size = newSize;
|
INFO(("realloc(): new size %ld fits in old area %ld with "
|
||||||
return address;
|
"%ld available -> new address: %p\n", newSize, area,
|
||||||
|
available, newAddress));
|
||||||
|
memmove(newAddress, info->allocation_base,
|
||||||
|
min_c(newSize, info->allocation_size));
|
||||||
|
info->allocation_base = newAddress;
|
||||||
|
info->allocation_size = newSize;
|
||||||
|
return newAddress;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
size_t available = info->size - ((addr_t)info->allocation_base
|
||||||
|
- (addr_t)info->base);
|
||||||
|
|
||||||
|
if (available >= newSize) {
|
||||||
|
// there is enough room available for the newSize
|
||||||
|
INFO(("realloc(): new size %ld fits in old area %ld with "
|
||||||
|
"%ld available\n", newSize, area, available));
|
||||||
|
info->allocation_size = newSize;
|
||||||
|
return address;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// have to allocate/copy/free - TODO maybe resize the area instead?
|
// have to allocate/copy/free - TODO maybe resize the area instead?
|
||||||
newAddress = memalign(0, newSize);
|
newAddress = malloc(newSize);
|
||||||
if (newAddress == NULL) {
|
if (newAddress == NULL) {
|
||||||
panic("realloc(): failed to allocate new block of %ld"
|
panic("realloc(): failed to allocate new block of %ld"
|
||||||
" bytes\n", newSize);
|
" bytes\n", newSize);
|
||||||
@@ -2036,7 +2055,7 @@ realloc(void *address, size_t newSize)
|
|||||||
void *
|
void *
|
||||||
calloc(size_t numElements, size_t size)
|
calloc(size_t numElements, size_t size)
|
||||||
{
|
{
|
||||||
void *address = memalign(0, numElements * size);
|
void *address = malloc(numElements * size);
|
||||||
if (address != NULL)
|
if (address != NULL)
|
||||||
memset(address, 0, numElements * size);
|
memset(address, 0, numElements * size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user