Zero memory on alloc.
This commit is contained in:
parent
d065ee43e8
commit
d9a55a5557
|
@ -293,11 +293,20 @@ uint32_t xe_memory_heap_alloc(
|
||||||
// will place wherever asked (so long as it doesn't overlap the heap).
|
// will place wherever asked (so long as it doesn't overlap the heap).
|
||||||
if (!base_address) {
|
if (!base_address) {
|
||||||
// Normal allocation from the managed heap.
|
// Normal allocation from the managed heap.
|
||||||
|
uint32_t result;
|
||||||
if (flags & XE_MEMORY_FLAG_PHYSICAL) {
|
if (flags & XE_MEMORY_FLAG_PHYSICAL) {
|
||||||
return memory->physical_heap.Alloc(base_address, size, flags, alignment);
|
result = memory->physical_heap.Alloc(
|
||||||
|
base_address, size, flags, alignment);
|
||||||
} else {
|
} else {
|
||||||
return memory->virtual_heap.Alloc(base_address, size, flags, alignment);
|
result = memory->virtual_heap.Alloc(
|
||||||
|
base_address, size, flags, alignment);
|
||||||
}
|
}
|
||||||
|
if (result) {
|
||||||
|
if (flags & XE_MEMORY_FLAG_ZERO) {
|
||||||
|
xe_zero_struct(memory->mapping_base + result, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
if (base_address >= XE_MEMORY_VIRTUAL_HEAP_LOW &&
|
if (base_address >= XE_MEMORY_VIRTUAL_HEAP_LOW &&
|
||||||
base_address < XE_MEMORY_VIRTUAL_HEAP_HIGH) {
|
base_address < XE_MEMORY_VIRTUAL_HEAP_HIGH) {
|
||||||
|
@ -322,6 +331,10 @@ uint32_t xe_memory_heap_alloc(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & XE_MEMORY_FLAG_ZERO) {
|
||||||
|
xe_zero_struct(pv, size);
|
||||||
|
}
|
||||||
|
|
||||||
return base_address;
|
return base_address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ uint32_t xe_memory_search_aligned(xe_memory_ref memory, size_t start,
|
||||||
enum {
|
enum {
|
||||||
XE_MEMORY_FLAG_64KB_PAGES = (1 << 1),
|
XE_MEMORY_FLAG_64KB_PAGES = (1 << 1),
|
||||||
XE_MEMORY_FLAG_PHYSICAL = (1 << 2),
|
XE_MEMORY_FLAG_PHYSICAL = (1 << 2),
|
||||||
|
XE_MEMORY_FLAG_ZERO = (1 << 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -110,7 +110,7 @@ int Processor::Setup() {
|
||||||
interrupt_thread_lock_ = xe_mutex_alloc(10000);
|
interrupt_thread_lock_ = xe_mutex_alloc(10000);
|
||||||
interrupt_thread_state_ = AllocThread(16 * 1024, 0, 0);
|
interrupt_thread_state_ = AllocThread(16 * 1024, 0, 0);
|
||||||
interrupt_thread_block_ = xe_memory_heap_alloc(
|
interrupt_thread_block_ = xe_memory_heap_alloc(
|
||||||
memory_, 0, 2048, 0);
|
memory_, 0, 2048, XE_MEMORY_FLAG_ZERO);
|
||||||
interrupt_thread_state_->ppc_state()->r[13] = interrupt_thread_block_;
|
interrupt_thread_state_->ppc_state()->r[13] = interrupt_thread_block_;
|
||||||
|
|
||||||
sym_table_ = new SymbolTable();
|
sym_table_ = new SymbolTable();
|
||||||
|
@ -146,7 +146,7 @@ int Processor::LoadRawBinary(const xechar_t* path, uint32_t start_address) {
|
||||||
|
|
||||||
// Place the data into memory at the desired address.
|
// Place the data into memory at the desired address.
|
||||||
XEEXPECTNOTZERO(xe_memory_heap_alloc(
|
XEEXPECTNOTZERO(xe_memory_heap_alloc(
|
||||||
memory_, start_address, (uint32_t)length, 0));
|
memory_, start_address, (uint32_t)length, XE_MEMORY_FLAG_ZERO));
|
||||||
XEEXPECTZERO(xe_copy_memory(
|
XEEXPECTZERO(xe_copy_memory(
|
||||||
xe_memory_addr(memory_, start_address), length, addr, length));
|
xe_memory_addr(memory_, start_address), length, addr, length));
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ ThreadState::ThreadState(
|
||||||
thread_id_(thread_id) {
|
thread_id_(thread_id) {
|
||||||
memory_ = processor->memory();
|
memory_ = processor->memory();
|
||||||
|
|
||||||
stack_address_ = xe_memory_heap_alloc(memory_, 0, stack_size, 0);
|
stack_address_ = xe_memory_heap_alloc(
|
||||||
|
memory_, 0, stack_size, XE_MEMORY_FLAG_ZERO);
|
||||||
|
|
||||||
// Allocate with 64b alignment.
|
// Allocate with 64b alignment.
|
||||||
ppc_state_ = (xe_ppc_state_t*)xe_malloc_aligned(sizeof(xe_ppc_state_t));
|
ppc_state_ = (xe_ppc_state_t*)xe_malloc_aligned(sizeof(xe_ppc_state_t));
|
||||||
|
|
|
@ -133,7 +133,8 @@ X_STATUS XThread::Create() {
|
||||||
// 0x160: last error
|
// 0x160: last error
|
||||||
// So, at offset 0x100 we have a 4b pointer to offset 200, then have the
|
// So, at offset 0x100 we have a 4b pointer to offset 200, then have the
|
||||||
// structure.
|
// structure.
|
||||||
thread_state_address_ = xe_memory_heap_alloc(memory(), 0, 2048, 0);
|
thread_state_address_ = xe_memory_heap_alloc(
|
||||||
|
memory(), 0, 2048, XE_MEMORY_FLAG_ZERO);
|
||||||
if (!thread_state_address_) {
|
if (!thread_state_address_) {
|
||||||
XELOGW("Unable to allocate thread state block");
|
XELOGW("Unable to allocate thread state block");
|
||||||
return X_STATUS_NO_MEMORY;
|
return X_STATUS_NO_MEMORY;
|
||||||
|
@ -147,7 +148,8 @@ X_STATUS XThread::Create() {
|
||||||
// Allocate TLS block.
|
// Allocate TLS block.
|
||||||
const xe_xex2_header_t* header = module->xex_header();
|
const xe_xex2_header_t* header = module->xex_header();
|
||||||
uint32_t tls_size = header->tls_info.slot_count * header->tls_info.data_size;
|
uint32_t tls_size = header->tls_info.slot_count * header->tls_info.data_size;
|
||||||
tls_address_ = xe_memory_heap_alloc(memory(), 0, tls_size, 0);
|
tls_address_ = xe_memory_heap_alloc(
|
||||||
|
memory(), 0, tls_size, XE_MEMORY_FLAG_ZERO);
|
||||||
if (!tls_address_) {
|
if (!tls_address_) {
|
||||||
XELOGW("Unable to allocate thread local storage block");
|
XELOGW("Unable to allocate thread local storage block");
|
||||||
module->Release();
|
module->Release();
|
||||||
|
|
|
@ -533,10 +533,9 @@ int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
|
||||||
// Allocate in-place the XEX memory.
|
// Allocate in-place the XEX memory.
|
||||||
const size_t exe_length = xex_length - header->exe_offset;
|
const size_t exe_length = xex_length - header->exe_offset;
|
||||||
size_t uncompressed_size = exe_length;
|
size_t uncompressed_size = exe_length;
|
||||||
uint32_t alloc_result =
|
uint32_t alloc_result = xe_memory_heap_alloc(
|
||||||
xe_memory_heap_alloc(memory,
|
memory, header->exe_address, (uint32_t)uncompressed_size,
|
||||||
header->exe_address, (uint32_t)uncompressed_size,
|
XE_MEMORY_FLAG_ZERO);
|
||||||
0);
|
|
||||||
if (!alloc_result) {
|
if (!alloc_result) {
|
||||||
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
||||||
header->exe_address, uncompressed_size);
|
header->exe_address, uncompressed_size);
|
||||||
|
@ -580,10 +579,9 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate in-place the XEX memory.
|
// Allocate in-place the XEX memory.
|
||||||
uint32_t alloc_result =
|
uint32_t alloc_result = xe_memory_heap_alloc(
|
||||||
xe_memory_heap_alloc(memory,
|
memory, header->exe_address, (uint32_t)uncompressed_size,
|
||||||
header->exe_address, (uint32_t)uncompressed_size,
|
XE_MEMORY_FLAG_ZERO);
|
||||||
0);
|
|
||||||
if (!alloc_result) {
|
if (!alloc_result) {
|
||||||
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
||||||
header->exe_address, uncompressed_size);
|
header->exe_address, uncompressed_size);
|
||||||
|
@ -719,10 +717,9 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate in-place the XEX memory.
|
// Allocate in-place the XEX memory.
|
||||||
uint32_t alloc_result =
|
uint32_t alloc_result = xe_memory_heap_alloc(
|
||||||
xe_memory_heap_alloc(memory,
|
memory, header->exe_address, (uint32_t)uncompressed_size,
|
||||||
header->exe_address, (uint32_t)uncompressed_size,
|
XE_MEMORY_FLAG_ZERO);
|
||||||
0);
|
|
||||||
if (!alloc_result) {
|
if (!alloc_result) {
|
||||||
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.",
|
||||||
header->exe_address, uncompressed_size);
|
header->exe_address, uncompressed_size);
|
||||||
|
|
Loading…
Reference in New Issue