Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lldb/trunk/source/Expression/IRMemoryMap.cpp
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, | ||||
lldb_private::Log *log( | lldb_private::Log *log( | ||||
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); | lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); | ||||
error.Clear(); | error.Clear(); | ||||
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 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 | } else { | ||||
allocation_size = (size & alignment_mask) | // Round up the requested size to an aligned value. | ||||
? ((size + alignment) & (~alignment_mask)) | allocation_size = llvm::alignTo(size, alignment); | ||||
: 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 - 1` additional bytes. | |||||
allocation_size += alignment - 1; | |||||
} | |||||
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 |