Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
source/Expression/IRMemoryMap.cpp
Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, | ||||
lldb::ProcessSP process_sp; | lldb::ProcessSP process_sp; | ||||
lldb::addr_t allocation_address = LLDB_INVALID_ADDRESS; | lldb::addr_t allocation_address = LLDB_INVALID_ADDRESS; | ||||
lldb::addr_t aligned_address = LLDB_INVALID_ADDRESS; | lldb::addr_t aligned_address = LLDB_INVALID_ADDRESS; | ||||
size_t alignment_mask = alignment - 1; | size_t alignment_mask = alignment - 1; | ||||
size_t allocation_size; | size_t allocation_size; | ||||
if (size == 0) | if (size == 0) { | ||||
// FIXME: Malloc(0) should either return an invalid address or assert, in | |||||
// order to cut down on unnecessary allocations. | |||||
allocation_size = alignment; | allocation_size = alignment; | ||||
} else { | |||||
// Round up the requested size to an aligned value, if needed. | |||||
if (size & alignment_mask) | |||||
allocation_size = ((size + alignment) & (~alignment_mask)); | |||||
else | else | ||||
allocation_size = (size & alignment_mask) | allocation_size = size; | ||||
labath: `allocation_size = llvm::alignTo(size, alignment)` | |||||
? ((size + alignment) & (~alignment_mask)) | |||||
: size; | // The process page cache does not see the requested alignment. We can't | ||||
// assume its result will be any more than 1-byte aligned. To work around | |||||
// this, request `alignment` additional bytes. | |||||
// | |||||
// FIXME: Pass the requested alignment into the process page cache to | |||||
// reduce internal fragmentation. | |||||
allocation_size += alignment; | |||||
} | |||||
I think this should be just allocation_size += alignment -1. The subsequent realignment cannot eat more than alignment-1 bytes. labath: I think this should be just `allocation_size += alignment -1`. The subsequent realignment… | |||||
switch (policy) { | switch (policy) { | ||||
default: | default: | ||||
error.SetErrorToGenericError(); | error.SetErrorToGenericError(); | ||||
error.SetErrorString("Couldn't malloc: invalid allocation policy"); | error.SetErrorString("Couldn't malloc: invalid allocation policy"); | ||||
return LLDB_INVALID_ADDRESS; | return LLDB_INVALID_ADDRESS; | ||||
case eAllocationPolicyHostOnly: | case eAllocationPolicyHostOnly: | ||||
allocation_address = FindSpace(allocation_size); | allocation_address = FindSpace(allocation_size); | ||||
▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines |
allocation_size = llvm::alignTo(size, alignment)