Removing xenia/malloc.*
Using standard memory functions now.
This commit is contained in:
parent
609d7c755f
commit
cecf83b7b7
|
@ -73,11 +73,11 @@ void* Arena::CloneContents() {
|
||||||
}
|
}
|
||||||
chunk = chunk->next;
|
chunk = chunk->next;
|
||||||
}
|
}
|
||||||
void* result = xe_malloc(total_length);
|
void* result = malloc(total_length);
|
||||||
uint8_t* p = (uint8_t*)result;
|
uint8_t* p = (uint8_t*)result;
|
||||||
chunk = head_chunk_;
|
chunk = head_chunk_;
|
||||||
while (chunk) {
|
while (chunk) {
|
||||||
xe_copy_struct(p, chunk->buffer, chunk->offset);
|
memcpy(p, chunk->buffer, chunk->offset);
|
||||||
p += chunk->offset;
|
p += chunk->offset;
|
||||||
if (chunk == active_chunk_) {
|
if (chunk == active_chunk_) {
|
||||||
break;
|
break;
|
||||||
|
@ -89,12 +89,12 @@ void* Arena::CloneContents() {
|
||||||
|
|
||||||
Arena::Chunk::Chunk(size_t chunk_size)
|
Arena::Chunk::Chunk(size_t chunk_size)
|
||||||
: next(nullptr), capacity(chunk_size), buffer(0), offset(0) {
|
: next(nullptr), capacity(chunk_size), buffer(0), offset(0) {
|
||||||
buffer = (uint8_t*)xe_malloc(capacity);
|
buffer = reinterpret_cast<uint8_t*>(malloc(capacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
Arena::Chunk::~Chunk() {
|
Arena::Chunk::~Chunk() {
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
xe_free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,13 @@ IVMFunction::IVMFunction(FunctionInfo* symbol_info)
|
||||||
: Function(symbol_info),
|
: Function(symbol_info),
|
||||||
register_count_(0),
|
register_count_(0),
|
||||||
intcode_count_(0),
|
intcode_count_(0),
|
||||||
intcodes_(0),
|
intcodes_(nullptr),
|
||||||
source_map_count_(0),
|
source_map_count_(0),
|
||||||
source_map_(0) {}
|
source_map_(nullptr) {}
|
||||||
|
|
||||||
IVMFunction::~IVMFunction() {
|
IVMFunction::~IVMFunction() {
|
||||||
xe_free(intcodes_);
|
free(intcodes_);
|
||||||
xe_free(source_map_);
|
free(source_map_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IVMFunction::Setup(TranslationContext& ctx) {
|
void IVMFunction::Setup(TranslationContext& ctx) {
|
||||||
|
|
|
@ -65,12 +65,12 @@ void IVMStack::Free(size_t register_count) {
|
||||||
|
|
||||||
IVMStack::Chunk::Chunk(size_t chunk_size)
|
IVMStack::Chunk::Chunk(size_t chunk_size)
|
||||||
: prev(NULL), next(NULL), capacity(chunk_size), buffer(0), offset(0) {
|
: prev(NULL), next(NULL), capacity(chunk_size), buffer(0), offset(0) {
|
||||||
buffer = (uint8_t*)xe_malloc(capacity);
|
buffer = reinterpret_cast<uint8_t*>(malloc(capacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
IVMStack::Chunk::~Chunk() {
|
IVMStack::Chunk::~Chunk() {
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
xe_free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,7 @@ int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||||
|
|
||||||
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
|
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
|
||||||
size_t code_size, StringBuffer* str) {
|
size_t code_size, StringBuffer* str) {
|
||||||
BE::DISASM disasm;
|
BE::DISASM disasm = {0};
|
||||||
xe_zero_struct(&disasm, sizeof(disasm));
|
|
||||||
disasm.Archi = 64;
|
disasm.Archi = 64;
|
||||||
disasm.Options = BE::Tabulation + BE::MasmSyntax + BE::PrefixedNumeral;
|
disasm.Options = BE::Tabulation + BE::MasmSyntax + BE::PrefixedNumeral;
|
||||||
disasm.EIP = (BE::UIntPtr)machine_code;
|
disasm.EIP = (BE::UIntPtr)machine_code;
|
||||||
|
|
|
@ -76,7 +76,7 @@ void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
|
||||||
lock_.unlock();
|
lock_.unlock();
|
||||||
|
|
||||||
// Copy code.
|
// Copy code.
|
||||||
xe_copy_struct(final_address, machine_code, code_size);
|
memcpy(final_address, machine_code, code_size);
|
||||||
|
|
||||||
return final_address;
|
return final_address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ RegisterAllocationPass::RegisterAllocationPass(const MachineInfo* machine_info)
|
||||||
// Initialize register sets.
|
// Initialize register sets.
|
||||||
// TODO(benvanik): rewrite in a way that makes sense - this is terrible.
|
// TODO(benvanik): rewrite in a way that makes sense - this is terrible.
|
||||||
auto mi_sets = machine_info->register_sets;
|
auto mi_sets = machine_info->register_sets;
|
||||||
xe_zero_struct(&usage_sets_, sizeof(usage_sets_));
|
memset(&usage_sets_, 0, sizeof(usage_sets_));
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
while (mi_sets[n].count) {
|
while (mi_sets[n].count) {
|
||||||
auto& mi_set = mi_sets[n];
|
auto& mi_set = mi_sets[n];
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
// TODO(benvanik): move the common stuff into here?
|
// TODO(benvanik): move the common stuff into here?
|
||||||
#include <xenia/logging.h>
|
#include <xenia/logging.h>
|
||||||
#include <xenia/malloc.h>
|
|
||||||
#include <xenia/profiling.h>
|
#include <xenia/profiling.h>
|
||||||
|
|
||||||
#endif // ALLOY_CORE_H_
|
#endif // ALLOY_CORE_H_
|
||||||
|
|
|
@ -69,8 +69,8 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
|
||||||
size_t list_size = instr_count_ * sizeof(void*);
|
size_t list_size = instr_count_ * sizeof(void*);
|
||||||
instr_offset_list_ = (Instr**)arena_->Alloc(list_size);
|
instr_offset_list_ = (Instr**)arena_->Alloc(list_size);
|
||||||
label_list_ = (Label**)arena_->Alloc(list_size);
|
label_list_ = (Label**)arena_->Alloc(list_size);
|
||||||
xe_zero_struct(instr_offset_list_, list_size);
|
memset(instr_offset_list_, 0, list_size);
|
||||||
xe_zero_struct(label_list_, list_size);
|
memset(label_list_, 0, list_size);
|
||||||
|
|
||||||
// Always mark entry with label.
|
// Always mark entry with label.
|
||||||
label_list_[0] = NewLabel();
|
label_list_[0] = NewLabel();
|
||||||
|
@ -171,7 +171,7 @@ void PPCHIRBuilder::AnnotateLabel(uint64_t address, Label* label) {
|
||||||
snprintf(name_buffer, poly::countof(name_buffer), "loc_%.8X",
|
snprintf(name_buffer, poly::countof(name_buffer), "loc_%.8X",
|
||||||
(uint32_t)address);
|
(uint32_t)address);
|
||||||
label->name = (char*)arena_->Alloc(sizeof(name_buffer));
|
label->name = (char*)arena_->Alloc(sizeof(name_buffer));
|
||||||
xe_copy_struct(label->name, name_buffer, sizeof(name_buffer));
|
memcpy(label->name, name_buffer, sizeof(name_buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionInfo* PPCHIRBuilder::LookupFunction(uint64_t address) {
|
FunctionInfo* PPCHIRBuilder::LookupFunction(uint64_t address) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace tables {
|
||||||
static InstrType** instr_table_prep(InstrType* unprep, size_t unprep_count,
|
static InstrType** instr_table_prep(InstrType* unprep, size_t unprep_count,
|
||||||
int a, int b) {
|
int a, int b) {
|
||||||
int prep_count = (int)pow(2.0, b - a + 1);
|
int prep_count = (int)pow(2.0, b - a + 1);
|
||||||
InstrType** prep = (InstrType**)xe_calloc(prep_count * sizeof(void*));
|
InstrType** prep = (InstrType**)calloc(prep_count, sizeof(void*));
|
||||||
for (int n = 0; n < unprep_count; n++) {
|
for (int n = 0; n < unprep_count; n++) {
|
||||||
int ordinal = select_bits(unprep[n].opcode, a, b);
|
int ordinal = select_bits(unprep[n].opcode, a, b);
|
||||||
prep[ordinal] = &unprep[n];
|
prep[ordinal] = &unprep[n];
|
||||||
|
@ -107,7 +107,7 @@ static InstrType** instr_table_prep_63(InstrType* unprep, size_t unprep_count,
|
||||||
int a, int b) {
|
int a, int b) {
|
||||||
// Special handling for A format instructions.
|
// Special handling for A format instructions.
|
||||||
int prep_count = (int)pow(2.0, b - a + 1);
|
int prep_count = (int)pow(2.0, b - a + 1);
|
||||||
InstrType** prep = (InstrType**)xe_calloc(prep_count * sizeof(void*));
|
InstrType** prep = (InstrType**)calloc(prep_count, sizeof(void*));
|
||||||
for (int n = 0; n < unprep_count; n++) {
|
for (int n = 0; n < unprep_count; n++) {
|
||||||
int ordinal = select_bits(unprep[n].opcode, a, b);
|
int ordinal = select_bits(unprep[n].opcode, a, b);
|
||||||
if (unprep[n].format == kXEPPCInstrFormatA) {
|
if (unprep[n].format == kXEPPCInstrFormatA) {
|
||||||
|
|
|
@ -632,7 +632,7 @@ void HIRBuilder::Comment(const char* format, ...) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void* p = arena_->Alloc(len + 1);
|
void* p = arena_->Alloc(len + 1);
|
||||||
xe_copy_struct(p, buffer, len + 1);
|
memcpy(p, buffer, len + 1);
|
||||||
Instr* i = AppendInstr(OPCODE_COMMENT_info, 0);
|
Instr* i = AppendInstr(OPCODE_COMMENT_info, 0);
|
||||||
i->src1.offset = (uint64_t)p;
|
i->src1.offset = (uint64_t)p;
|
||||||
i->src2.value = i->src3.value = NULL;
|
i->src2.value = i->src3.value = NULL;
|
||||||
|
|
|
@ -21,11 +21,11 @@ DebugInfo::DebugInfo()
|
||||||
source_map_(nullptr) {}
|
source_map_(nullptr) {}
|
||||||
|
|
||||||
DebugInfo::~DebugInfo() {
|
DebugInfo::~DebugInfo() {
|
||||||
xe_free(source_map_);
|
free(source_map_);
|
||||||
xe_free(source_disasm_);
|
free(source_disasm_);
|
||||||
xe_free(raw_hir_disasm_);
|
free(raw_hir_disasm_);
|
||||||
xe_free(hir_disasm_);
|
free(hir_disasm_);
|
||||||
xe_free(machine_code_disasm_);
|
free(machine_code_disasm_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugInfo::InitializeSourceMap(size_t source_map_count,
|
void DebugInfo::InitializeSourceMap(size_t source_map_count,
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <poly/string.h>
|
#include <poly/string.h>
|
||||||
|
|
||||||
#include <xenia/logging.h>
|
#include <xenia/logging.h>
|
||||||
#include <xenia/malloc.h>
|
|
||||||
#include <xenia/profiling.h>
|
#include <xenia/profiling.h>
|
||||||
#include <xenia/types.h>
|
#include <xenia/types.h>
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,9 @@
|
||||||
|
|
||||||
#include <xenia/core/ref.h>
|
#include <xenia/core/ref.h>
|
||||||
|
|
||||||
|
void xe_ref_init(xe_ref_t* ref) { ref->count = 1; }
|
||||||
|
|
||||||
void xe_ref_init(xe_ref_t* ref) {
|
void xe_ref_retain(xe_ref_t* ref) { poly::atomic_inc(&ref->count); }
|
||||||
ref->count = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void xe_ref_retain(xe_ref_t* ref) {
|
|
||||||
poly::atomic_inc(&ref->count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void xe_ref_release(xe_ref_t* ref, xe_ref_dealloc_t dealloc) {
|
void xe_ref_release(xe_ref_t* ref, xe_ref_dealloc_t dealloc) {
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
|
@ -26,6 +21,6 @@ void xe_ref_release(xe_ref_t* ref, xe_ref_dealloc_t dealloc) {
|
||||||
if (dealloc) {
|
if (dealloc) {
|
||||||
dealloc(ref);
|
dealloc(ref);
|
||||||
}
|
}
|
||||||
xe_free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
|
||||||
void xe_socket_init() {
|
void xe_socket_init() {
|
||||||
// No-op.
|
// No-op.
|
||||||
}
|
}
|
||||||
|
@ -35,31 +34,30 @@ void xe_socket_close(socket_t socket) {
|
||||||
|
|
||||||
void xe_socket_set_keepalive(socket_t socket, bool value) {
|
void xe_socket_set_keepalive(socket_t socket, bool value) {
|
||||||
int opt_value = value ? 1 : 0;
|
int opt_value = value ? 1 : 0;
|
||||||
setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE,
|
setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &opt_value, sizeof(opt_value));
|
||||||
&opt_value, sizeof(opt_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void xe_socket_set_reuseaddr(socket_t socket, bool value) {
|
void xe_socket_set_reuseaddr(socket_t socket, bool value) {
|
||||||
int opt_value = value ? 1 : 0;
|
int opt_value = value ? 1 : 0;
|
||||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
|
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &opt_value, sizeof(opt_value));
|
||||||
&opt_value, sizeof(opt_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void xe_socket_set_nodelay(socket_t socket, bool value) {
|
void xe_socket_set_nodelay(socket_t socket, bool value) {
|
||||||
int opt_value = value ? 1 : 0;
|
int opt_value = value ? 1 : 0;
|
||||||
setsockopt(socket, IPPROTO_TCP, TCP_NODELAY,
|
setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &opt_value, sizeof(opt_value));
|
||||||
&opt_value, sizeof(opt_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void xe_socket_set_nonblock(socket_t socket, bool value) {
|
void xe_socket_set_nonblock(socket_t socket, bool value) {
|
||||||
int flags;
|
int flags;
|
||||||
while ((flags = fcntl(socket, F_GETFL, 0)) == -1 && errno == EINTR);
|
while ((flags = fcntl(socket, F_GETFL, 0)) == -1 && errno == EINTR)
|
||||||
|
;
|
||||||
if (flags == -1) {
|
if (flags == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int r;
|
int r;
|
||||||
while ((r = fcntl(socket, F_SETFL, flags | O_NONBLOCK)) == -1 &&
|
while ((r = fcntl(socket, F_SETFL, flags | O_NONBLOCK)) == -1 &&
|
||||||
errno == EINTR);
|
errno == EINTR)
|
||||||
|
;
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,8 +98,8 @@ int xe_socket_listen(socket_t socket) {
|
||||||
int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) {
|
int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) {
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
socklen_t client_count = sizeof(client_addr);
|
socklen_t client_count = sizeof(client_addr);
|
||||||
socket_t client_socket_id = accept(
|
socket_t client_socket_id =
|
||||||
socket, (struct sockaddr*)&client_addr, &client_count);
|
accept(socket, (struct sockaddr*)&client_addr, &client_count);
|
||||||
if (client_socket_id < 0) {
|
if (client_socket_id < 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -109,8 +107,8 @@ int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) {
|
||||||
out_client_info->socket = client_socket_id;
|
out_client_info->socket = client_socket_id;
|
||||||
|
|
||||||
int client_ip = client_addr.sin_addr.s_addr;
|
int client_ip = client_addr.sin_addr.s_addr;
|
||||||
inet_ntop(AF_INET, &client_ip,
|
inet_ntop(AF_INET, &client_ip, out_client_info->addr,
|
||||||
out_client_info->addr, XECOUNT(out_client_info->addr));
|
XECOUNT(out_client_info->addr));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -143,8 +141,8 @@ struct xe_socket_loop {
|
||||||
};
|
};
|
||||||
|
|
||||||
xe_socket_loop_t* xe_socket_loop_create(socket_t socket) {
|
xe_socket_loop_t* xe_socket_loop_create(socket_t socket) {
|
||||||
xe_socket_loop_t* loop = (xe_socket_loop_t*)xe_calloc(
|
xe_socket_loop_t* loop =
|
||||||
sizeof(xe_socket_loop_t));
|
(xe_socket_loop_t*)calloc(1, sizeof(xe_socket_loop_t));
|
||||||
|
|
||||||
loop->socket = socket;
|
loop->socket = socket;
|
||||||
|
|
||||||
|
@ -164,11 +162,11 @@ xe_socket_loop_t* xe_socket_loop_create(socket_t socket) {
|
||||||
void xe_socket_loop_destroy(xe_socket_loop_t* loop) {
|
void xe_socket_loop_destroy(xe_socket_loop_t* loop) {
|
||||||
close(loop->notify_rd_id);
|
close(loop->notify_rd_id);
|
||||||
close(loop->notify_wr_id);
|
close(loop->notify_wr_id);
|
||||||
xe_free(loop);
|
free(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
int xe_socket_loop_poll(xe_socket_loop_t* loop,
|
int xe_socket_loop_poll(xe_socket_loop_t* loop, bool check_read,
|
||||||
bool check_read, bool check_write) {
|
bool check_write) {
|
||||||
// Prep events object.
|
// Prep events object.
|
||||||
if (check_read) {
|
if (check_read) {
|
||||||
loop->events[0].events |= POLLIN;
|
loop->events[0].events |= POLLIN;
|
||||||
|
@ -180,7 +178,8 @@ int xe_socket_loop_poll(xe_socket_loop_t* loop,
|
||||||
// Poll.
|
// Poll.
|
||||||
int r;
|
int r;
|
||||||
while ((r = poll(loop->events, XECOUNT(loop->events), -1)) == -1 &&
|
while ((r = poll(loop->events, XECOUNT(loop->events), -1)) == -1 &&
|
||||||
errno == EINTR);
|
errno == EINTR)
|
||||||
|
;
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,8 @@ XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id,
|
||||||
assert_not_zero(stack_address_);
|
assert_not_zero(stack_address_);
|
||||||
|
|
||||||
// Allocate with 64b alignment.
|
// Allocate with 64b alignment.
|
||||||
context_ = (PPCContext*)xe_malloc_aligned(sizeof(PPCContext));
|
context_ = (PPCContext*)calloc(1, sizeof(PPCContext));
|
||||||
assert_true(((uint64_t)context_ & 0xF) == 0);
|
assert_true(((uint64_t)context_ & 0xF) == 0);
|
||||||
xe_zero_struct(context_, sizeof(PPCContext));
|
|
||||||
|
|
||||||
// Stash pointers to common structures that callbacks may need.
|
// Stash pointers to common structures that callbacks may need.
|
||||||
context_->reserve_address = memory_->reserve_address();
|
context_->reserve_address = memory_->reserve_address();
|
||||||
|
@ -55,7 +54,7 @@ XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id,
|
||||||
XenonThreadState::~XenonThreadState() {
|
XenonThreadState::~XenonThreadState() {
|
||||||
runtime_->debugger()->OnThreadDestroyed(this);
|
runtime_->debugger()->OnThreadDestroyed(this);
|
||||||
|
|
||||||
xe_free_aligned(context_);
|
free(context_);
|
||||||
xenon_memory()->HeapFree(stack_address_, stack_size_);
|
xenon_memory()->HeapFree(stack_address_, stack_size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,19 +9,16 @@
|
||||||
|
|
||||||
#include <xenia/gpu/register_file.h>
|
#include <xenia/gpu/register_file.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace xe;
|
using namespace xe;
|
||||||
using namespace xe::gpu;
|
using namespace xe::gpu;
|
||||||
|
|
||||||
|
RegisterFile::RegisterFile() { memset(values, 0, sizeof(values)); }
|
||||||
RegisterFile::RegisterFile() {
|
|
||||||
xe_zero_struct(values, sizeof(values));
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* RegisterFile::GetRegisterName(uint32_t index) {
|
const char* RegisterFile::GetRegisterName(uint32_t index) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
#define XE_GPU_REGISTER(index, type, name) \
|
#define XE_GPU_REGISTER(index, type, name) \
|
||||||
case index: return #name;
|
case index: \
|
||||||
|
return #name;
|
||||||
#include <xenia/gpu/xenos/register_table.inc>
|
#include <xenia/gpu/xenos/register_table.inc>
|
||||||
#undef XE_GPU_REGISTER
|
#undef XE_GPU_REGISTER
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -12,21 +12,21 @@
|
||||||
#include <poly/math.h>
|
#include <poly/math.h>
|
||||||
#include <xenia/gpu/xenos/ucode_disassembler.h>
|
#include <xenia/gpu/xenos/ucode_disassembler.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace xe;
|
using namespace xe;
|
||||||
using namespace xe::gpu;
|
using namespace xe::gpu;
|
||||||
using namespace xe::gpu::xenos;
|
using namespace xe::gpu::xenos;
|
||||||
|
|
||||||
|
|
||||||
ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
||||||
const Info& info,
|
const Info& info, xenos::XE_GPU_SHADER_TYPE type)
|
||||||
xenos::XE_GPU_SHADER_TYPE type)
|
|
||||||
: HashedResource(memory_range),
|
: HashedResource(memory_range),
|
||||||
info_(info), type_(type), is_prepared_(false), disasm_src_(nullptr) {
|
info_(info),
|
||||||
xe_zero_struct(&alloc_counts_, sizeof(alloc_counts_));
|
type_(type),
|
||||||
xe_zero_struct(&buffer_inputs_, sizeof(buffer_inputs_));
|
is_prepared_(false),
|
||||||
xe_zero_struct(&sampler_inputs_, sizeof(sampler_inputs_));
|
disasm_src_(nullptr) {
|
||||||
|
memset(&alloc_counts_, 0, sizeof(alloc_counts_));
|
||||||
|
memset(&buffer_inputs_, 0, sizeof(buffer_inputs_));
|
||||||
|
memset(&sampler_inputs_, 0, sizeof(sampler_inputs_));
|
||||||
|
|
||||||
// Verify.
|
// Verify.
|
||||||
dword_count_ = memory_range.length / 4;
|
dword_count_ = memory_range.length / 4;
|
||||||
|
@ -34,7 +34,7 @@ ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
||||||
|
|
||||||
// Copy bytes and swap.
|
// Copy bytes and swap.
|
||||||
size_t byte_size = dword_count_ * sizeof(uint32_t);
|
size_t byte_size = dword_count_ * sizeof(uint32_t);
|
||||||
dwords_ = (uint32_t*)xe_malloc(byte_size);
|
dwords_ = (uint32_t*)malloc(byte_size);
|
||||||
for (uint32_t n = 0; n < dword_count_; n++) {
|
for (uint32_t n = 0; n < dword_count_; n++) {
|
||||||
dwords_[n] = poly::load_and_swap<uint32_t>(memory_range.host_base + n * 4);
|
dwords_[n] = poly::load_and_swap<uint32_t>(memory_range.host_base + n * 4);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderResource::~ShaderResource() {
|
ShaderResource::~ShaderResource() {
|
||||||
xe_free(disasm_src_);
|
free(disasm_src_);
|
||||||
xe_free(dwords_);
|
free(dwords_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderResource::GatherIO() {
|
void ShaderResource::GatherIO() {
|
||||||
|
@ -128,8 +128,7 @@ void ShaderResource::GatherExec(const instr_cf_exec_t* cf) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO(benvanik): gather registers used, predicate bits used, etc.
|
// TODO(benvanik): gather registers used, predicate bits used, etc.
|
||||||
const instr_alu_t* alu =
|
const instr_alu_t* alu = (const instr_alu_t*)(dwords_ + alu_off * 3);
|
||||||
(const instr_alu_t*)(dwords_ + alu_off * 3);
|
|
||||||
if (alu->vector_write_mask) {
|
if (alu->vector_write_mask) {
|
||||||
if (alu->export_data && alu->vector_dest == 63) {
|
if (alu->export_data && alu->vector_dest == 63) {
|
||||||
alloc_counts_.point_size = true;
|
alloc_counts_.point_size = true;
|
||||||
|
@ -261,16 +260,14 @@ void ShaderResource::GatherTextureFetch(const xenos::instr_fetch_tex_t* tex) {
|
||||||
// Format mangling, size estimation, etc.
|
// Format mangling, size estimation, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexShaderResource::VertexShaderResource(
|
VertexShaderResource::VertexShaderResource(const MemoryRange& memory_range,
|
||||||
const MemoryRange& memory_range, const Info& info)
|
const Info& info)
|
||||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_VERTEX) {
|
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_VERTEX) {}
|
||||||
}
|
|
||||||
|
|
||||||
VertexShaderResource::~VertexShaderResource() = default;
|
VertexShaderResource::~VertexShaderResource() = default;
|
||||||
|
|
||||||
PixelShaderResource::PixelShaderResource(
|
PixelShaderResource::PixelShaderResource(const MemoryRange& memory_range,
|
||||||
const MemoryRange& memory_range, const Info& info)
|
const Info& info)
|
||||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_PIXEL) {
|
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_PIXEL) {}
|
||||||
}
|
|
||||||
|
|
||||||
PixelShaderResource::~PixelShaderResource() = default;
|
PixelShaderResource::~PixelShaderResource() = default;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace fs {
|
||||||
|
|
||||||
DiscImageFile::DiscImageFile(KernelState* kernel_state, Mode mode,
|
DiscImageFile::DiscImageFile(KernelState* kernel_state, Mode mode,
|
||||||
DiscImageEntry* entry)
|
DiscImageEntry* entry)
|
||||||
: entry_(entry), XFile(kernel_state, mode) {}
|
: XFile(kernel_state, mode), entry_(entry) {}
|
||||||
|
|
||||||
DiscImageFile::~DiscImageFile() {}
|
DiscImageFile::~DiscImageFile() {}
|
||||||
|
|
||||||
|
@ -59,8 +59,7 @@ X_STATUS DiscImageFile::ReadSync(void* buffer, size_t buffer_length,
|
||||||
}
|
}
|
||||||
size_t real_offset = gdfx_entry->offset + byte_offset;
|
size_t real_offset = gdfx_entry->offset + byte_offset;
|
||||||
size_t real_length = std::min(buffer_length, gdfx_entry->size - byte_offset);
|
size_t real_length = std::min(buffer_length, gdfx_entry->size - byte_offset);
|
||||||
xe_copy_memory(buffer, buffer_length, entry_->mmap()->data() + real_offset,
|
memcpy(buffer, entry_->mmap()->data() + real_offset, real_length);
|
||||||
real_length);
|
|
||||||
*out_bytes_read = real_length;
|
*out_bytes_read = real_length;
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ X_STATUS STFSContainerFile::ReadSync(void* buffer, size_t buffer_length,
|
||||||
offset += byte_offset % 4096;
|
offset += byte_offset % 4096;
|
||||||
read_length = std::min(read_length, record.length - (byte_offset % 4096));
|
read_length = std::min(read_length, record.length - (byte_offset % 4096));
|
||||||
}
|
}
|
||||||
xe_copy_struct(dest_ptr, entry_->mmap()->data() + offset, read_length);
|
memcpy(dest_ptr, entry_->mmap()->data() + offset, read_length);
|
||||||
dest_ptr += read_length;
|
dest_ptr += read_length;
|
||||||
remaining_length -= read_length;
|
remaining_length -= read_length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,19 +50,14 @@ void GDFXEntry::Dump(int indent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GDFX::GDFX(poly::MappedMemory* mmap) : mmap_(mmap) {
|
GDFX::GDFX(poly::MappedMemory* mmap) : mmap_(mmap) { root_entry_ = nullptr; }
|
||||||
root_entry_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
GDFX::~GDFX() {
|
GDFX::~GDFX() { delete root_entry_; }
|
||||||
delete root_entry_;
|
|
||||||
}
|
|
||||||
|
|
||||||
GDFXEntry* GDFX::root_entry() { return root_entry_; }
|
GDFXEntry* GDFX::root_entry() { return root_entry_; }
|
||||||
|
|
||||||
GDFX::Error GDFX::Load() {
|
GDFX::Error GDFX::Load() {
|
||||||
ParseState state;
|
ParseState state = {0};
|
||||||
xe_zero_struct(&state, sizeof(state));
|
|
||||||
|
|
||||||
state.ptr = mmap_->data();
|
state.ptr = mmap_->data();
|
||||||
state.size = mmap_->size();
|
state.size = mmap_->size();
|
||||||
|
|
|
@ -37,15 +37,15 @@ bool STFSVolumeDescriptor::Read(const uint8_t* p) {
|
||||||
block_separation = poly::load_and_swap<uint8_t>(p + 0x02);
|
block_separation = poly::load_and_swap<uint8_t>(p + 0x02);
|
||||||
file_table_block_count = poly::load_and_swap<uint16_t>(p + 0x03);
|
file_table_block_count = poly::load_and_swap<uint16_t>(p + 0x03);
|
||||||
file_table_block_number = XEGETUINT24BE(p + 0x05);
|
file_table_block_number = XEGETUINT24BE(p + 0x05);
|
||||||
xe_copy_struct(top_hash_table_hash, p + 0x08, 0x14);
|
memcpy(top_hash_table_hash, p + 0x08, 0x14);
|
||||||
total_allocated_block_count = poly::load_and_swap<uint32_t>(p + 0x1C);
|
total_allocated_block_count = poly::load_and_swap<uint32_t>(p + 0x1C);
|
||||||
total_unallocated_block_count = poly::load_and_swap<uint32_t>(p + 0x20);
|
total_unallocated_block_count = poly::load_and_swap<uint32_t>(p + 0x20);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool STFSHeader::Read(const uint8_t* p) {
|
bool STFSHeader::Read(const uint8_t* p) {
|
||||||
xe_copy_struct(license_entries, p + 0x22C, 0x100);
|
memcpy(license_entries, p + 0x22C, 0x100);
|
||||||
xe_copy_struct(header_hash, p + 0x32C, 0x14);
|
memcpy(header_hash, p + 0x32C, 0x14);
|
||||||
header_size = poly::load_and_swap<uint32_t>(p + 0x340);
|
header_size = poly::load_and_swap<uint32_t>(p + 0x340);
|
||||||
content_type = (STFSContentType)poly::load_and_swap<uint32_t>(p + 0x344);
|
content_type = (STFSContentType)poly::load_and_swap<uint32_t>(p + 0x344);
|
||||||
metadata_version = poly::load_and_swap<uint32_t>(p + 0x348);
|
metadata_version = poly::load_and_swap<uint32_t>(p + 0x348);
|
||||||
|
@ -64,8 +64,8 @@ bool STFSHeader::Read(const uint8_t* p) {
|
||||||
disc_number = poly::load_and_swap<uint8_t>(p + 0x366);
|
disc_number = poly::load_and_swap<uint8_t>(p + 0x366);
|
||||||
disc_in_set = poly::load_and_swap<uint8_t>(p + 0x367);
|
disc_in_set = poly::load_and_swap<uint8_t>(p + 0x367);
|
||||||
save_game_id = poly::load_and_swap<uint32_t>(p + 0x368);
|
save_game_id = poly::load_and_swap<uint32_t>(p + 0x368);
|
||||||
xe_copy_struct(console_id, p + 0x36C, 0x5);
|
memcpy(console_id, p + 0x36C, 0x5);
|
||||||
xe_copy_struct(profile_id, p + 0x371, 0x8);
|
memcpy(profile_id, p + 0x371, 0x8);
|
||||||
data_file_count = poly::load_and_swap<uint32_t>(p + 0x39D);
|
data_file_count = poly::load_and_swap<uint32_t>(p + 0x39D);
|
||||||
data_file_combined_size = poly::load_and_swap<uint64_t>(p + 0x3A1);
|
data_file_combined_size = poly::load_and_swap<uint64_t>(p + 0x3A1);
|
||||||
descriptor_type = (STFSDescriptorType)poly::load_and_swap<uint8_t>(p + 0x3A9);
|
descriptor_type = (STFSDescriptorType)poly::load_and_swap<uint8_t>(p + 0x3A9);
|
||||||
|
@ -76,7 +76,7 @@ bool STFSHeader::Read(const uint8_t* p) {
|
||||||
if (!volume_descriptor.Read(p + 0x379)) {
|
if (!volume_descriptor.Read(p + 0x379)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
xe_copy_struct(device_id, p + 0x3FD, 0x14);
|
memcpy(device_id, p + 0x3FD, 0x14);
|
||||||
for (size_t n = 0; n < 0x900 / 2; n++) {
|
for (size_t n = 0; n < 0x900 / 2; n++) {
|
||||||
display_names[n] = poly::load_and_swap<uint16_t>(p + 0x411 + n * 2);
|
display_names[n] = poly::load_and_swap<uint16_t>(p + 0x411 + n * 2);
|
||||||
display_descs[n] = poly::load_and_swap<uint16_t>(p + 0xD11 + n * 2);
|
display_descs[n] = poly::load_and_swap<uint16_t>(p + 0xD11 + n * 2);
|
||||||
|
@ -88,8 +88,8 @@ bool STFSHeader::Read(const uint8_t* p) {
|
||||||
transfer_flags = poly::load_and_swap<uint8_t>(p + 0x1711);
|
transfer_flags = poly::load_and_swap<uint8_t>(p + 0x1711);
|
||||||
thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1712);
|
thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1712);
|
||||||
title_thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1716);
|
title_thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1716);
|
||||||
xe_copy_struct(thumbnail_image, p + 0x171A, 0x4000);
|
memcpy(thumbnail_image, p + 0x171A, 0x4000);
|
||||||
xe_copy_struct(title_thumbnail_image, p + 0x571A, 0x4000);
|
memcpy(title_thumbnail_image, p + 0x571A, 0x4000);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace xe {
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
|
|
||||||
ObjectTable::ObjectTable()
|
ObjectTable::ObjectTable()
|
||||||
: table_capacity_(0), table_(NULL), last_free_entry_(0) {}
|
: table_capacity_(0), table_(nullptr), last_free_entry_(0) {}
|
||||||
|
|
||||||
ObjectTable::~ObjectTable() {
|
ObjectTable::~ObjectTable() {
|
||||||
std::lock_guard<std::mutex> lock(table_mutex_);
|
std::lock_guard<std::mutex> lock(table_mutex_);
|
||||||
|
@ -34,7 +34,7 @@ ObjectTable::~ObjectTable() {
|
||||||
|
|
||||||
table_capacity_ = 0;
|
table_capacity_ = 0;
|
||||||
last_free_entry_ = 0;
|
last_free_entry_ = 0;
|
||||||
xe_free(table_);
|
free(table_);
|
||||||
table_ = NULL;
|
table_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,18 @@ X_STATUS ObjectTable::FindFreeSlot(uint32_t* out_slot) {
|
||||||
|
|
||||||
// Table out of slots, expand.
|
// Table out of slots, expand.
|
||||||
uint32_t new_table_capacity = std::max(16 * 1024u, table_capacity_ * 2);
|
uint32_t new_table_capacity = std::max(16 * 1024u, table_capacity_ * 2);
|
||||||
ObjectTableEntry* new_table = (ObjectTableEntry*)xe_recalloc(
|
size_t new_table_size = new_table_capacity * sizeof(ObjectTableEntry);
|
||||||
table_, table_capacity_ * sizeof(ObjectTableEntry),
|
size_t old_table_size = table_capacity_ * sizeof(ObjectTableEntry);
|
||||||
new_table_capacity * sizeof(ObjectTableEntry));
|
ObjectTableEntry* new_table =
|
||||||
|
(ObjectTableEntry*)realloc(table_, new_table_size);
|
||||||
if (!new_table) {
|
if (!new_table) {
|
||||||
return X_STATUS_NO_MEMORY;
|
return X_STATUS_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
// Zero out new memory.
|
||||||
|
if (new_table_size > old_table_size) {
|
||||||
|
memset(reinterpret_cast<uint8_t*>(new_table) + old_table_size, 0,
|
||||||
|
new_table_size - old_table_size);
|
||||||
|
}
|
||||||
last_free_entry_ = table_capacity_;
|
last_free_entry_ = table_capacity_;
|
||||||
table_capacity_ = new_table_capacity;
|
table_capacity_ = new_table_capacity;
|
||||||
table_ = new_table;
|
table_ = new_table;
|
||||||
|
|
|
@ -74,8 +74,7 @@ class XDirectoryInfo {
|
||||||
poly::store_and_swap<uint64_t>(dst + 48, info->allocation_size);
|
poly::store_and_swap<uint64_t>(dst + 48, info->allocation_size);
|
||||||
poly::store_and_swap<uint32_t>(dst + 56, info->attributes);
|
poly::store_and_swap<uint32_t>(dst + 56, info->attributes);
|
||||||
poly::store_and_swap<uint32_t>(dst + 60, info->file_name_length);
|
poly::store_and_swap<uint32_t>(dst + 60, info->file_name_length);
|
||||||
xe_copy_memory(dst + 64, info->file_name_length, info->file_name,
|
memcpy(dst + 64, info->file_name, info->file_name_length);
|
||||||
info->file_name_length);
|
|
||||||
dst += info->next_entry_offset;
|
dst += info->next_entry_offset;
|
||||||
src += info->next_entry_offset;
|
src += info->next_entry_offset;
|
||||||
} while (info->next_entry_offset != 0);
|
} while (info->next_entry_offset != 0);
|
||||||
|
@ -99,8 +98,7 @@ class XVolumeInfo {
|
||||||
poly::store_and_swap<uint32_t>(dst + 8, this->serial_number);
|
poly::store_and_swap<uint32_t>(dst + 8, this->serial_number);
|
||||||
poly::store_and_swap<uint32_t>(dst + 12, this->label_length);
|
poly::store_and_swap<uint32_t>(dst + 12, this->label_length);
|
||||||
poly::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
|
poly::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
|
||||||
xe_copy_memory(dst + 20, this->label_length, this->label,
|
memcpy(dst + 20, this->label, this->label_length);
|
||||||
this->label_length);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static_assert_size(XVolumeInfo, 24);
|
static_assert_size(XVolumeInfo, 24);
|
||||||
|
@ -120,8 +118,7 @@ class XFileSystemAttributeInfo {
|
||||||
poly::store_and_swap<uint32_t>(dst + 4,
|
poly::store_and_swap<uint32_t>(dst + 4,
|
||||||
this->maximum_component_name_length);
|
this->maximum_component_name_length);
|
||||||
poly::store_and_swap<uint32_t>(dst + 8, this->fs_name_length);
|
poly::store_and_swap<uint32_t>(dst + 8, this->fs_name_length);
|
||||||
xe_copy_memory(dst + 12, this->fs_name_length, this->fs_name,
|
memcpy(dst + 12, this->fs_name, this->fs_name_length);
|
||||||
this->fs_name_length);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static_assert_size(XFileSystemAttributeInfo, 16);
|
static_assert_size(XFileSystemAttributeInfo, 16);
|
||||||
|
|
|
@ -67,7 +67,7 @@ X_STATUS XUserModule::LoadFromFile(const char* path) {
|
||||||
XEEXPECTZERO(result);
|
XEEXPECTZERO(result);
|
||||||
|
|
||||||
size_t buffer_length = file_info.file_length;
|
size_t buffer_length = file_info.file_length;
|
||||||
buffer = (uint8_t*)xe_malloc(buffer_length);
|
buffer = (uint8_t*)malloc(buffer_length);
|
||||||
|
|
||||||
// Open file for reading.
|
// Open file for reading.
|
||||||
result = fs_entry->Open(kernel_state(), fs::Mode::READ, false, &file);
|
result = fs_entry->Open(kernel_state(), fs::Mode::READ, false, &file);
|
||||||
|
@ -85,7 +85,7 @@ X_STATUS XUserModule::LoadFromFile(const char* path) {
|
||||||
|
|
||||||
XECLEANUP:
|
XECLEANUP:
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
xe_free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
if (file) {
|
if (file) {
|
||||||
file->Release();
|
file->Release();
|
||||||
|
@ -99,8 +99,7 @@ X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) {
|
||||||
XenonRuntime* runtime = processor->runtime();
|
XenonRuntime* runtime = processor->runtime();
|
||||||
|
|
||||||
// Load the XEX into memory and decrypt.
|
// Load the XEX into memory and decrypt.
|
||||||
xe_xex2_options_t xex_options;
|
xe_xex2_options_t xex_options = {0};
|
||||||
xe_zero_struct(&xex_options, sizeof(xex_options));
|
|
||||||
xex_ = xe_xex2_load(kernel_state()->memory(), addr, length, xex_options);
|
xex_ = xe_xex2_load(kernel_state()->memory(), addr, length, xex_options);
|
||||||
if (!xex_) {
|
if (!xex_) {
|
||||||
return X_STATUS_UNSUCCESSFUL;
|
return X_STATUS_UNSUCCESSFUL;
|
||||||
|
|
|
@ -51,7 +51,7 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
|
||||||
|
|
||||||
xe_xex2_ref xe_xex2_load(xe::Memory *memory, const void *addr,
|
xe_xex2_ref xe_xex2_load(xe::Memory *memory, const void *addr,
|
||||||
const size_t length, xe_xex2_options_t options) {
|
const size_t length, xe_xex2_options_t options) {
|
||||||
xe_xex2_ref xex = (xe_xex2_ref)xe_calloc(sizeof(xe_xex2));
|
xe_xex2_ref xex = (xe_xex2_ref)calloc(1, sizeof(xe_xex2));
|
||||||
xe_ref_init((xe_ref)xex);
|
xe_ref_init((xe_ref)xex);
|
||||||
|
|
||||||
xex->memory = memory;
|
xex->memory = memory;
|
||||||
|
@ -85,14 +85,14 @@ void xe_xex2_dealloc(xe_xex2_ref xex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xe_xex2_header_t *header = &xex->header;
|
xe_xex2_header_t *header = &xex->header;
|
||||||
xe_free(header->sections);
|
free(header->sections);
|
||||||
xe_free(header->resource_infos);
|
free(header->resource_infos);
|
||||||
if (header->file_format_info.compression_type == XEX_COMPRESSION_BASIC) {
|
if (header->file_format_info.compression_type == XEX_COMPRESSION_BASIC) {
|
||||||
xe_free(header->file_format_info.compression_info.basic.blocks);
|
free(header->file_format_info.compression_info.basic.blocks);
|
||||||
}
|
}
|
||||||
for (size_t n = 0; n < header->import_library_count; n++) {
|
for (size_t n = 0; n < header->import_library_count; n++) {
|
||||||
xe_xex2_import_library_t *library = &header->import_libraries[n];
|
xe_xex2_import_library_t *library = &header->import_libraries[n];
|
||||||
xe_free(library->records);
|
free(library->records);
|
||||||
}
|
}
|
||||||
|
|
||||||
xex->memory = NULL;
|
xex->memory = NULL;
|
||||||
|
@ -162,13 +162,12 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
break;
|
break;
|
||||||
case XEX_HEADER_RESOURCE_INFO: {
|
case XEX_HEADER_RESOURCE_INFO: {
|
||||||
header->resource_info_count = (opt_header->length - 4) / 16;
|
header->resource_info_count = (opt_header->length - 4) / 16;
|
||||||
header->resource_infos = (xe_xex2_resource_info_t *)xe_calloc(
|
header->resource_infos = (xe_xex2_resource_info_t *)calloc(
|
||||||
sizeof(xe_xex2_resource_info_t) * header->resource_info_count);
|
header->resource_info_count, sizeof(xe_xex2_resource_info_t));
|
||||||
const uint8_t *ph = pp + 0x04;
|
const uint8_t *ph = pp + 0x04;
|
||||||
for (size_t n = 0; n < header->resource_info_count; n++) {
|
for (size_t n = 0; n < header->resource_info_count; n++) {
|
||||||
auto &res = header->resource_infos[n];
|
auto &res = header->resource_infos[n];
|
||||||
XEEXPECTZERO(
|
memcpy(res.name, ph + 0x00, 8);
|
||||||
xe_copy_memory(res.name, sizeof(res.name), ph + 0x00, 8));
|
|
||||||
res.address = poly::load_and_swap<uint32_t>(ph + 0x08);
|
res.address = poly::load_and_swap<uint32_t>(ph + 0x08);
|
||||||
res.size = poly::load_and_swap<uint32_t>(ph + 0x0C);
|
res.size = poly::load_and_swap<uint32_t>(ph + 0x0C);
|
||||||
ph += 16;
|
ph += 16;
|
||||||
|
@ -254,8 +253,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
pp += 12 + string_table_size;
|
pp += 12 + string_table_size;
|
||||||
for (size_t m = 0; m < count; m++) {
|
for (size_t m = 0; m < count; m++) {
|
||||||
xe_xex2_import_library_t *library = &header->import_libraries[m];
|
xe_xex2_import_library_t *library = &header->import_libraries[m];
|
||||||
XEEXPECTZERO(xe_copy_memory(library->digest, sizeof(library->digest),
|
memcpy(library->digest, pp + 0x04, 20);
|
||||||
pp + 0x04, 20));
|
|
||||||
library->import_id = poly::load_and_swap<uint32_t>(pp + 0x18);
|
library->import_id = poly::load_and_swap<uint32_t>(pp + 0x18);
|
||||||
library->version.value = poly::load_and_swap<uint32_t>(pp + 0x1C);
|
library->version.value = poly::load_and_swap<uint32_t>(pp + 0x1C);
|
||||||
library->min_version.value = poly::load_and_swap<uint32_t>(pp + 0x20);
|
library->min_version.value = poly::load_and_swap<uint32_t>(pp + 0x20);
|
||||||
|
@ -282,7 +280,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
|
|
||||||
library->record_count = poly::load_and_swap<uint16_t>(pp + 0x26);
|
library->record_count = poly::load_and_swap<uint16_t>(pp + 0x26);
|
||||||
library->records =
|
library->records =
|
||||||
(uint32_t *)xe_calloc(library->record_count * sizeof(uint32_t));
|
(uint32_t *)calloc(library->record_count, sizeof(uint32_t));
|
||||||
XEEXPECTNOTNULL(library->records);
|
XEEXPECTNOTNULL(library->records);
|
||||||
pp += 0x28;
|
pp += 0x28;
|
||||||
for (size_t i = 0; i < library->record_count; i++) {
|
for (size_t i = 0; i < library->record_count; i++) {
|
||||||
|
@ -304,8 +302,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
pp += 4;
|
pp += 4;
|
||||||
for (size_t m = 0; m < count; m++) {
|
for (size_t m = 0; m < count; m++) {
|
||||||
xe_xex2_static_library_t *library = &header->static_libraries[m];
|
xe_xex2_static_library_t *library = &header->static_libraries[m];
|
||||||
XEEXPECTZERO(xe_copy_memory(library->name, sizeof(library->name),
|
memcpy(library->name, pp + 0x00, 8);
|
||||||
pp + 0x00, 8));
|
|
||||||
library->name[8] = 0;
|
library->name[8] = 0;
|
||||||
library->major = poly::load_and_swap<uint16_t>(pp + 0x08);
|
library->major = poly::load_and_swap<uint16_t>(pp + 0x08);
|
||||||
library->minor = poly::load_and_swap<uint16_t>(pp + 0x0A);
|
library->minor = poly::load_and_swap<uint16_t>(pp + 0x0A);
|
||||||
|
@ -333,8 +330,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
uint32_t info_size = poly::load_and_swap<uint32_t>(pp + 0x00);
|
uint32_t info_size = poly::load_and_swap<uint32_t>(pp + 0x00);
|
||||||
comp_info->block_count = (info_size - 8) / 8;
|
comp_info->block_count = (info_size - 8) / 8;
|
||||||
comp_info->blocks =
|
comp_info->blocks =
|
||||||
(xe_xex2_file_basic_compression_block_t *)xe_calloc(
|
(xe_xex2_file_basic_compression_block_t *)calloc(
|
||||||
comp_info->block_count *
|
comp_info->block_count,
|
||||||
sizeof(xe_xex2_file_basic_compression_block_t));
|
sizeof(xe_xex2_file_basic_compression_block_t));
|
||||||
XEEXPECTNOTNULL(comp_info->blocks);
|
XEEXPECTNOTNULL(comp_info->blocks);
|
||||||
for (size_t m = 0; m < comp_info->block_count; m++) {
|
for (size_t m = 0; m < comp_info->block_count; m++) {
|
||||||
|
@ -360,9 +357,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
comp_info->window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
|
comp_info->window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
|
||||||
comp_info->window_bits = window_bits;
|
comp_info->window_bits = window_bits;
|
||||||
comp_info->block_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
|
comp_info->block_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
|
||||||
XEEXPECTZERO(xe_copy_memory(comp_info->block_hash,
|
memcpy(comp_info->block_hash, pp + 0x10, 20);
|
||||||
sizeof(comp_info->block_hash),
|
|
||||||
pp + 0x10, 20));
|
|
||||||
} break;
|
} break;
|
||||||
case XEX_COMPRESSION_DELTA:
|
case XEX_COMPRESSION_DELTA:
|
||||||
// TODO: XEX_COMPRESSION_DELTA
|
// TODO: XEX_COMPRESSION_DELTA
|
||||||
|
@ -378,25 +373,18 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
ldr = &header->loader_info;
|
ldr = &header->loader_info;
|
||||||
ldr->header_size = poly::load_and_swap<uint32_t>(pc + 0x000);
|
ldr->header_size = poly::load_and_swap<uint32_t>(pc + 0x000);
|
||||||
ldr->image_size = poly::load_and_swap<uint32_t>(pc + 0x004);
|
ldr->image_size = poly::load_and_swap<uint32_t>(pc + 0x004);
|
||||||
XEEXPECTZERO(xe_copy_memory(ldr->rsa_signature, sizeof(ldr->rsa_signature),
|
memcpy(ldr->rsa_signature, pc + 0x008, 256);
|
||||||
pc + 0x008, 256));
|
|
||||||
ldr->unklength = poly::load_and_swap<uint32_t>(pc + 0x108);
|
ldr->unklength = poly::load_and_swap<uint32_t>(pc + 0x108);
|
||||||
ldr->image_flags =
|
ldr->image_flags =
|
||||||
(xe_xex2_image_flags)poly::load_and_swap<uint32_t>(pc + 0x10C);
|
(xe_xex2_image_flags)poly::load_and_swap<uint32_t>(pc + 0x10C);
|
||||||
ldr->load_address = poly::load_and_swap<uint32_t>(pc + 0x110);
|
ldr->load_address = poly::load_and_swap<uint32_t>(pc + 0x110);
|
||||||
XEEXPECTZERO(xe_copy_memory(ldr->section_digest, sizeof(ldr->section_digest),
|
memcpy(ldr->section_digest, pc + 0x114, 20);
|
||||||
pc + 0x114, 20));
|
|
||||||
ldr->import_table_count = poly::load_and_swap<uint32_t>(pc + 0x128);
|
ldr->import_table_count = poly::load_and_swap<uint32_t>(pc + 0x128);
|
||||||
XEEXPECTZERO(xe_copy_memory(ldr->import_table_digest,
|
memcpy(ldr->import_table_digest, pc + 0x12C, 20);
|
||||||
sizeof(ldr->import_table_digest), pc + 0x12C,
|
memcpy(ldr->media_id, pc + 0x140, 16);
|
||||||
20));
|
memcpy(ldr->file_key, pc + 0x150, 16);
|
||||||
XEEXPECTZERO(
|
|
||||||
xe_copy_memory(ldr->media_id, sizeof(ldr->media_id), pc + 0x140, 16));
|
|
||||||
XEEXPECTZERO(
|
|
||||||
xe_copy_memory(ldr->file_key, sizeof(ldr->file_key), pc + 0x150, 16));
|
|
||||||
ldr->export_table = poly::load_and_swap<uint32_t>(pc + 0x160);
|
ldr->export_table = poly::load_and_swap<uint32_t>(pc + 0x160);
|
||||||
XEEXPECTZERO(xe_copy_memory(ldr->header_digest, sizeof(ldr->header_digest),
|
memcpy(ldr->header_digest, pc + 0x164, 20);
|
||||||
pc + 0x164, 20));
|
|
||||||
ldr->game_regions =
|
ldr->game_regions =
|
||||||
(xe_xex2_region_flags)poly::load_and_swap<uint32_t>(pc + 0x178);
|
(xe_xex2_region_flags)poly::load_and_swap<uint32_t>(pc + 0x178);
|
||||||
ldr->media_flags =
|
ldr->media_flags =
|
||||||
|
@ -406,15 +394,14 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
||||||
ps = p + header->certificate_offset + 0x180;
|
ps = p + header->certificate_offset + 0x180;
|
||||||
header->section_count = poly::load_and_swap<uint32_t>(ps + 0x000);
|
header->section_count = poly::load_and_swap<uint32_t>(ps + 0x000);
|
||||||
ps += 4;
|
ps += 4;
|
||||||
header->sections = (xe_xex2_section_t *)xe_calloc(header->section_count *
|
header->sections = (xe_xex2_section_t *)calloc(header->section_count,
|
||||||
sizeof(xe_xex2_section_t));
|
sizeof(xe_xex2_section_t));
|
||||||
XEEXPECTNOTNULL(header->sections);
|
XEEXPECTNOTNULL(header->sections);
|
||||||
for (size_t n = 0; n < header->section_count; n++) {
|
for (size_t n = 0; n < header->section_count; n++) {
|
||||||
xe_xex2_section_t *section = &header->sections[n];
|
xe_xex2_section_t *section = &header->sections[n];
|
||||||
section->info.value = poly::load_and_swap<uint32_t>(ps);
|
section->info.value = poly::load_and_swap<uint32_t>(ps);
|
||||||
ps += 4;
|
ps += 4;
|
||||||
XEEXPECTZERO(xe_copy_memory(section->digest, sizeof(section->digest), ps,
|
memcpy(section->digest, ps, sizeof(section->digest));
|
||||||
sizeof(section->digest)));
|
|
||||||
ps += sizeof(section->digest);
|
ps += sizeof(section->digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +449,7 @@ mspack_memory_file *mspack_memory_open(struct mspack_system *sys, void *buffer,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mspack_memory_file *memfile =
|
mspack_memory_file *memfile =
|
||||||
(mspack_memory_file *)xe_calloc(sizeof(mspack_memory_file));
|
(mspack_memory_file *)calloc(1, sizeof(mspack_memory_file));
|
||||||
if (!memfile) {
|
if (!memfile) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -473,16 +460,13 @@ mspack_memory_file *mspack_memory_open(struct mspack_system *sys, void *buffer,
|
||||||
}
|
}
|
||||||
void mspack_memory_close(mspack_memory_file *file) {
|
void mspack_memory_close(mspack_memory_file *file) {
|
||||||
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
||||||
xe_free(memfile);
|
free(memfile);
|
||||||
}
|
}
|
||||||
int mspack_memory_read(struct mspack_file *file, void *buffer, int chars) {
|
int mspack_memory_read(struct mspack_file *file, void *buffer, int chars) {
|
||||||
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
||||||
const off_t remaining = memfile->buffer_size - memfile->offset;
|
const off_t remaining = memfile->buffer_size - memfile->offset;
|
||||||
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
||||||
if (xe_copy_memory(buffer, total,
|
memcpy(buffer, (uint8_t *)memfile->buffer + memfile->offset, total);
|
||||||
(uint8_t *)memfile->buffer + memfile->offset, total)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memfile->offset += total;
|
memfile->offset += total;
|
||||||
return (int)total;
|
return (int)total;
|
||||||
}
|
}
|
||||||
|
@ -490,23 +474,20 @@ int mspack_memory_write(struct mspack_file *file, void *buffer, int chars) {
|
||||||
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
||||||
const off_t remaining = memfile->buffer_size - memfile->offset;
|
const off_t remaining = memfile->buffer_size - memfile->offset;
|
||||||
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
||||||
if (xe_copy_memory((uint8_t *)memfile->buffer + memfile->offset,
|
memcpy((uint8_t *)memfile->buffer + memfile->offset, buffer, total);
|
||||||
memfile->buffer_size - memfile->offset, buffer, total)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memfile->offset += total;
|
memfile->offset += total;
|
||||||
return (int)total;
|
return (int)total;
|
||||||
}
|
}
|
||||||
void *mspack_memory_alloc(struct mspack_system *sys, size_t chars) {
|
void *mspack_memory_alloc(struct mspack_system *sys, size_t chars) {
|
||||||
return xe_calloc(chars);
|
return calloc(chars, 1);
|
||||||
}
|
}
|
||||||
void mspack_memory_free(void *ptr) { xe_free(ptr); }
|
void mspack_memory_free(void *ptr) { free(ptr); }
|
||||||
void mspack_memory_copy(void *src, void *dest, size_t chars) {
|
void mspack_memory_copy(void *src, void *dest, size_t chars) {
|
||||||
xe_copy_memory(dest, chars, src, chars);
|
memcpy(dest, src, chars);
|
||||||
}
|
}
|
||||||
struct mspack_system *mspack_memory_sys_create() {
|
struct mspack_system *mspack_memory_sys_create() {
|
||||||
struct mspack_system *sys =
|
struct mspack_system *sys =
|
||||||
(struct mspack_system *)xe_calloc(sizeof(struct mspack_system));
|
(struct mspack_system *)calloc(1, sizeof(struct mspack_system));
|
||||||
if (!sys) {
|
if (!sys) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -517,7 +498,7 @@ struct mspack_system *mspack_memory_sys_create() {
|
||||||
sys->copy = mspack_memory_copy;
|
sys->copy = mspack_memory_copy;
|
||||||
return sys;
|
return sys;
|
||||||
}
|
}
|
||||||
void mspack_memory_sys_destroy(struct mspack_system *sys) { xe_free(sys); }
|
void mspack_memory_sys_destroy(struct mspack_system *sys) { free(sys); }
|
||||||
|
|
||||||
void xe_xex2_decrypt_buffer(const uint8_t *session_key,
|
void xe_xex2_decrypt_buffer(const uint8_t *session_key,
|
||||||
const uint8_t *input_buffer,
|
const uint8_t *input_buffer,
|
||||||
|
@ -560,7 +541,11 @@ int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
|
||||||
|
|
||||||
switch (header->file_format_info.encryption_type) {
|
switch (header->file_format_info.encryption_type) {
|
||||||
case XEX_ENCRYPTION_NONE:
|
case XEX_ENCRYPTION_NONE:
|
||||||
return xe_copy_memory(buffer, uncompressed_size, p, exe_length);
|
if (exe_length > uncompressed_size) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memcpy(buffer, p, exe_length);
|
||||||
|
return 0;
|
||||||
case XEX_ENCRYPTION_NORMAL:
|
case XEX_ENCRYPTION_NORMAL:
|
||||||
xe_xex2_decrypt_buffer(header->session_key, p, exe_length, buffer,
|
xe_xex2_decrypt_buffer(header->session_key, p, exe_length, buffer,
|
||||||
uncompressed_size);
|
uncompressed_size);
|
||||||
|
@ -597,7 +582,7 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
||||||
if (!alloc_result) {
|
if (!alloc_result) {
|
||||||
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
|
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
|
||||||
uncompressed_size);
|
uncompressed_size);
|
||||||
XEFAIL();
|
return 1;
|
||||||
}
|
}
|
||||||
uint8_t *buffer = memory->Translate(header->exe_address);
|
uint8_t *buffer = memory->Translate(header->exe_address);
|
||||||
uint8_t *d = buffer;
|
uint8_t *d = buffer;
|
||||||
|
@ -612,8 +597,12 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
||||||
|
|
||||||
switch (header->file_format_info.encryption_type) {
|
switch (header->file_format_info.encryption_type) {
|
||||||
case XEX_ENCRYPTION_NONE:
|
case XEX_ENCRYPTION_NONE:
|
||||||
XEEXPECTZERO(xe_copy_memory(d, uncompressed_size - (d - buffer), p,
|
if (exe_length - (p - source_buffer) >
|
||||||
exe_length - (p - source_buffer)));
|
uncompressed_size - (d - buffer)) {
|
||||||
|
// Overflow.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memcpy(d, p, exe_length - (p - source_buffer));
|
||||||
break;
|
break;
|
||||||
case XEX_ENCRYPTION_NORMAL: {
|
case XEX_ENCRYPTION_NORMAL: {
|
||||||
const uint8_t *ct = p;
|
const uint8_t *ct = p;
|
||||||
|
@ -639,9 +628,6 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
XECLEANUP:
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
||||||
|
@ -682,7 +668,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
||||||
case XEX_ENCRYPTION_NORMAL:
|
case XEX_ENCRYPTION_NORMAL:
|
||||||
// TODO: a way to do without a copy/alloc?
|
// TODO: a way to do without a copy/alloc?
|
||||||
free_input = true;
|
free_input = true;
|
||||||
input_buffer = (const uint8_t *)xe_calloc(input_size);
|
input_buffer = (const uint8_t *)calloc(1, input_size);
|
||||||
XEEXPECTNOTNULL(input_buffer);
|
XEEXPECTNOTNULL(input_buffer);
|
||||||
xe_xex2_decrypt_buffer(header->session_key, exe_buffer, exe_length,
|
xe_xex2_decrypt_buffer(header->session_key, exe_buffer, exe_length,
|
||||||
(uint8_t *)input_buffer, input_size);
|
(uint8_t *)input_buffer, input_size);
|
||||||
|
@ -692,14 +678,14 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
compress_buffer = (uint8_t *)xe_calloc(exe_length);
|
compress_buffer = (uint8_t *)calloc(1, exe_length);
|
||||||
XEEXPECTNOTNULL(compress_buffer);
|
XEEXPECTNOTNULL(compress_buffer);
|
||||||
|
|
||||||
p = input_buffer;
|
p = input_buffer;
|
||||||
d = compress_buffer;
|
d = compress_buffer;
|
||||||
|
|
||||||
// De-block.
|
// De-block.
|
||||||
deblock_buffer = (uint8_t *)xe_calloc(input_size);
|
deblock_buffer = (uint8_t *)calloc(1, input_size);
|
||||||
XEEXPECTNOTNULL(deblock_buffer);
|
XEEXPECTNOTNULL(deblock_buffer);
|
||||||
block_size = header->file_format_info.compression_info.normal.block_size;
|
block_size = header->file_format_info.compression_info.normal.block_size;
|
||||||
while (block_size) {
|
while (block_size) {
|
||||||
|
@ -714,7 +700,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
||||||
if (!chunk_size) {
|
if (!chunk_size) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xe_copy_memory(d, exe_length - (d - compress_buffer), p, chunk_size);
|
memcpy(d, p, chunk_size);
|
||||||
p += chunk_size;
|
p += chunk_size;
|
||||||
d += chunk_size;
|
d += chunk_size;
|
||||||
|
|
||||||
|
@ -770,10 +756,10 @@ XECLEANUP:
|
||||||
mspack_memory_sys_destroy(sys);
|
mspack_memory_sys_destroy(sys);
|
||||||
sys = NULL;
|
sys = NULL;
|
||||||
}
|
}
|
||||||
xe_free(compress_buffer);
|
free(compress_buffer);
|
||||||
xe_free(deblock_buffer);
|
free(deblock_buffer);
|
||||||
if (free_input) {
|
if (free_input) {
|
||||||
xe_free((void *)input_buffer);
|
free((void *)input_buffer);
|
||||||
}
|
}
|
||||||
return result_code;
|
return result_code;
|
||||||
}
|
}
|
||||||
|
@ -865,9 +851,8 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
|
||||||
// Setup/load sections.
|
// Setup/load sections.
|
||||||
sechdr = IMAGE_FIRST_SECTION(nthdr);
|
sechdr = IMAGE_FIRST_SECTION(nthdr);
|
||||||
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
|
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
|
||||||
PESection *section = (PESection *)xe_calloc(sizeof(PESection));
|
PESection *section = (PESection *)calloc(1, sizeof(PESection));
|
||||||
xe_copy_memory(section->name, sizeof(section->name), sechdr->Name,
|
memcpy(section->name, sechdr->Name, sizeof(sechdr->Name));
|
||||||
sizeof(sechdr->Name));
|
|
||||||
section->name[8] = 0;
|
section->name[8] = 0;
|
||||||
section->raw_address = sechdr->PointerToRawData;
|
section->raw_address = sechdr->PointerToRawData;
|
||||||
section->raw_size = sechdr->SizeOfRawData;
|
section->raw_size = sechdr->SizeOfRawData;
|
||||||
|
@ -928,8 +913,8 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate storage.
|
// Allocate storage.
|
||||||
xe_xex2_import_info_t *infos = (xe_xex2_import_info_t *)xe_calloc(
|
xe_xex2_import_info_t *infos = (xe_xex2_import_info_t *)calloc(
|
||||||
info_count * sizeof(xe_xex2_import_info_t));
|
info_count, sizeof(xe_xex2_import_info_t));
|
||||||
assert_not_null(infos);
|
assert_not_null(infos);
|
||||||
|
|
||||||
assert_not_zero(info_count);
|
assert_not_zero(info_count);
|
||||||
|
|
|
@ -30,12 +30,8 @@ public:
|
||||||
X_ANSI_STRING object_name;
|
X_ANSI_STRING object_name;
|
||||||
uint32_t attributes;
|
uint32_t attributes;
|
||||||
|
|
||||||
X_OBJECT_ATTRIBUTES() {
|
X_OBJECT_ATTRIBUTES() { Zero(); }
|
||||||
Zero();
|
X_OBJECT_ATTRIBUTES(const uint8_t* base, uint32_t p) { Read(base, p); }
|
||||||
}
|
|
||||||
X_OBJECT_ATTRIBUTES(const uint8_t* base, uint32_t p) {
|
|
||||||
Read(base, p);
|
|
||||||
}
|
|
||||||
void Read(const uint8_t* base, uint32_t p) {
|
void Read(const uint8_t* base, uint32_t p) {
|
||||||
root_directory = poly::load_and_swap<uint32_t>(base + p);
|
root_directory = poly::load_and_swap<uint32_t>(base + p);
|
||||||
object_name_ptr = poly::load_and_swap<uint32_t>(base + p + 4);
|
object_name_ptr = poly::load_and_swap<uint32_t>(base + p + 4);
|
||||||
|
@ -135,7 +131,7 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xe_free(object_name);
|
free(object_name);
|
||||||
SHIM_SET_RETURN_32(result);
|
SHIM_SET_RETURN_32(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +199,7 @@ SHIM_CALL NtOpenFile_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xe_free(object_name);
|
free(object_name);
|
||||||
SHIM_SET_RETURN_32(result);
|
SHIM_SET_RETURN_32(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +490,7 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xe_free(object_name);
|
free(object_name);
|
||||||
SHIM_SET_RETURN_32(result);
|
SHIM_SET_RETURN_32(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,23 +516,23 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state,
|
||||||
result = X_STATUS_SUCCESS;
|
result = X_STATUS_SUCCESS;
|
||||||
switch (fs_info_class) {
|
switch (fs_info_class) {
|
||||||
case 1: { // FileFsVolumeInformation
|
case 1: { // FileFsVolumeInformation
|
||||||
auto volume_info = (XVolumeInfo*)xe_calloc(length);
|
auto volume_info = (XVolumeInfo*)calloc(length, 1);
|
||||||
result = file->QueryVolume(volume_info, length);
|
result = file->QueryVolume(volume_info, length);
|
||||||
if (XSUCCEEDED(result)) {
|
if (XSUCCEEDED(result)) {
|
||||||
volume_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
volume_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
||||||
info = length;
|
info = length;
|
||||||
}
|
}
|
||||||
xe_free(volume_info);
|
free(volume_info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: { // FileFsAttributeInformation
|
case 5: { // FileFsAttributeInformation
|
||||||
auto fs_attribute_info = (XFileSystemAttributeInfo*)xe_calloc(length);
|
auto fs_attribute_info = (XFileSystemAttributeInfo*)calloc(length, 1);
|
||||||
result = file->QueryFileSystemAttributes(fs_attribute_info, length);
|
result = file->QueryFileSystemAttributes(fs_attribute_info, length);
|
||||||
if (XSUCCEEDED(result)) {
|
if (XSUCCEEDED(result)) {
|
||||||
fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
||||||
info = length;
|
info = length;
|
||||||
}
|
}
|
||||||
xe_free(fs_attribute_info);
|
free(fs_attribute_info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -589,7 +585,7 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
|
|
||||||
if (length < 72) {
|
if (length < 72) {
|
||||||
SHIM_SET_RETURN_32(X_STATUS_INFO_LENGTH_MISMATCH);
|
SHIM_SET_RETURN_32(X_STATUS_INFO_LENGTH_MISMATCH);
|
||||||
xe_free(file_name);
|
free(file_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,14 +595,14 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
XFile* file = NULL;
|
XFile* file = NULL;
|
||||||
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
|
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
|
||||||
if (XSUCCEEDED(result)) {
|
if (XSUCCEEDED(result)) {
|
||||||
XDirectoryInfo* dir_info = (XDirectoryInfo*)xe_calloc(length);
|
XDirectoryInfo* dir_info = (XDirectoryInfo*)calloc(length, 1);
|
||||||
result =
|
result =
|
||||||
file->QueryDirectory(dir_info, length, file_name, restart_scan != 0);
|
file->QueryDirectory(dir_info, length, file_name, restart_scan != 0);
|
||||||
if (XSUCCEEDED(result)) {
|
if (XSUCCEEDED(result)) {
|
||||||
dir_info->Write(SHIM_MEM_BASE, file_info_ptr);
|
dir_info->Write(SHIM_MEM_BASE, file_info_ptr);
|
||||||
info = length;
|
info = length;
|
||||||
}
|
}
|
||||||
xe_free(dir_info);
|
free(dir_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (XFAILED(result)) {
|
if (XFAILED(result)) {
|
||||||
|
@ -621,7 +617,7 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
file->Release();
|
file->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
xe_free(file_name);
|
free(file_name);
|
||||||
SHIM_SET_RETURN_32(result);
|
SHIM_SET_RETURN_32(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ SHIM_CALL MmQueryStatistics_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
X_STATUS result = X_STATUS_SUCCESS;
|
X_STATUS result = X_STATUS_SUCCESS;
|
||||||
|
|
||||||
// Zero out the struct.
|
// Zero out the struct.
|
||||||
xe_zero_struct(SHIM_MEM_ADDR(stats_ptr), 104);
|
memset(SHIM_MEM_ADDR(stats_ptr), 0, 104);
|
||||||
SHIM_SET_MEM_32(stats_ptr + 0, 104);
|
SHIM_SET_MEM_32(stats_ptr + 0, 104);
|
||||||
|
|
||||||
// Set the constants the game is likely asking for.
|
// Set the constants the game is likely asking for.
|
||||||
|
|
|
@ -108,7 +108,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state)
|
||||||
export_resolver_->SetVariableMapping(
|
export_resolver_->SetVariableMapping(
|
||||||
"xboxkrnl.exe", ordinals::ExLoadedCommandLine, pExLoadedCommandLine);
|
"xboxkrnl.exe", ordinals::ExLoadedCommandLine, pExLoadedCommandLine);
|
||||||
char command_line[] = "\"default.xex\"";
|
char command_line[] = "\"default.xex\"";
|
||||||
xe_copy_memory(mem + pExLoadedCommandLine, 1024, command_line,
|
memcpy(mem + pExLoadedCommandLine, command_line,
|
||||||
poly::countof(command_line) + 1);
|
poly::countof(command_line) + 1);
|
||||||
|
|
||||||
// XboxKrnlVersion (8b)
|
// XboxKrnlVersion (8b)
|
||||||
|
|
|
@ -408,7 +408,7 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
|
|
||||||
// swap the format buffer
|
// swap the format buffer
|
||||||
wchar_t* swapped_format =
|
wchar_t* swapped_format =
|
||||||
(wchar_t*)xe_malloc((format_length + 1) * sizeof(wchar_t));
|
(wchar_t*)malloc((format_length + 1) * sizeof(wchar_t));
|
||||||
for (size_t i = 0; i < format_length; ++i) {
|
for (size_t i = 0; i < format_length; ++i) {
|
||||||
swapped_format[i] = poly::byte_swap(format[i]);
|
swapped_format[i] = poly::byte_swap(format[i]);
|
||||||
}
|
}
|
||||||
|
@ -587,13 +587,13 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
const wchar_t* data = (const wchar_t*)SHIM_MEM_ADDR(value);
|
const wchar_t* data = (const wchar_t*)SHIM_MEM_ADDR(value);
|
||||||
size_t data_length = wcslen(data);
|
size_t data_length = wcslen(data);
|
||||||
wchar_t* swapped_data =
|
wchar_t* swapped_data =
|
||||||
(wchar_t*)xe_malloc((data_length + 1) * sizeof(wchar_t));
|
(wchar_t*)malloc((data_length + 1) * sizeof(wchar_t));
|
||||||
for (size_t i = 0; i < data_length; ++i) {
|
for (size_t i = 0; i < data_length; ++i) {
|
||||||
swapped_data[i] = poly::byte_swap(data[i]);
|
swapped_data[i] = poly::byte_swap(data[i]);
|
||||||
}
|
}
|
||||||
swapped_data[data_length] = '\0';
|
swapped_data[data_length] = '\0';
|
||||||
int result = wsprintf(b, local, swapped_data);
|
int result = wsprintf(b, local, swapped_data);
|
||||||
xe_free(swapped_data);
|
free(swapped_data);
|
||||||
b += result;
|
b += result;
|
||||||
arg_index++;
|
arg_index++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -607,7 +607,7 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
}
|
}
|
||||||
*b = '\0';
|
*b = '\0';
|
||||||
|
|
||||||
xe_free(swapped_format);
|
free(swapped_format);
|
||||||
|
|
||||||
// swap the result buffer
|
// swap the result buffer
|
||||||
for (wchar_t* swap = buffer; swap != b; ++swap) {
|
for (wchar_t* swap = buffer; swap != b; ++swap) {
|
||||||
|
|
|
@ -300,7 +300,7 @@ SHIM_CALL VdSwap_shim(PPCContext* ppc_state, KernelState* state) {
|
||||||
// token value. It'd be nice to figure out what this is really doing so
|
// token value. It'd be nice to figure out what this is really doing so
|
||||||
// that we could simulate it, though due to TCR I bet all games need to
|
// that we could simulate it, though due to TCR I bet all games need to
|
||||||
// use this method.
|
// use this method.
|
||||||
xe_zero_struct(SHIM_MEM_ADDR(unk0), 64 * 4);
|
memset(SHIM_MEM_ADDR(unk0), 0, 64 * 4);
|
||||||
auto dwords = reinterpret_cast<uint32_t*>(SHIM_MEM_ADDR(unk0));
|
auto dwords = reinterpret_cast<uint32_t*>(SHIM_MEM_ADDR(unk0));
|
||||||
dwords[0] = poly::byte_swap((0x03 << 30) | ((1 - 1) << 16) |
|
dwords[0] = poly::byte_swap((0x03 << 30) | ((1 - 1) << 16) |
|
||||||
(xe::gpu::xenos::PM4_XE_SWAP << 8));
|
(xe::gpu::xenos::PM4_XE_SWAP << 8));
|
||||||
|
|
|
@ -1,137 +0,0 @@
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* Xenia : Xbox 360 Emulator Research Project *
|
|
||||||
******************************************************************************
|
|
||||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
||||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <xenia/malloc.h>
|
|
||||||
|
|
||||||
#include <xenia/common.h>
|
|
||||||
|
|
||||||
|
|
||||||
void *xe_malloc(const size_t size) {
|
|
||||||
// Some platforms return NULL from malloc with size zero.
|
|
||||||
if (!size) {
|
|
||||||
return malloc(1);
|
|
||||||
}
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xe_calloc(const size_t size) {
|
|
||||||
// Some platforms return NULL from malloc with size zero.
|
|
||||||
if (!size) {
|
|
||||||
return calloc(1, 1);
|
|
||||||
}
|
|
||||||
return calloc(1, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* xe_realloc(void *ptr, const size_t old_size, const size_t new_size) {
|
|
||||||
if (!ptr) {
|
|
||||||
// Support realloc as malloc.
|
|
||||||
return malloc(new_size);
|
|
||||||
}
|
|
||||||
if (old_size == new_size) {
|
|
||||||
// No-op.
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
if (!new_size) {
|
|
||||||
// Zero-size realloc, return a dummy buffer for platforms that don't support
|
|
||||||
// zero-size allocs.
|
|
||||||
void *dummy = malloc(1);
|
|
||||||
if (!dummy) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
xe_free(ptr);
|
|
||||||
return dummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
return realloc(ptr, new_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* xe_recalloc(void *ptr, const size_t old_size, const size_t new_size) {
|
|
||||||
if (!ptr) {
|
|
||||||
// Support realloc as malloc.
|
|
||||||
return calloc(1, new_size);
|
|
||||||
}
|
|
||||||
if (old_size == new_size) {
|
|
||||||
// No-op.
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
if (!new_size) {
|
|
||||||
// Zero-size realloc, return a dummy buffer for platforms that don't support
|
|
||||||
// zero-size allocs.
|
|
||||||
void *dummy = calloc(1, 1);
|
|
||||||
if (!dummy) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
xe_free(ptr);
|
|
||||||
return dummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *result = realloc(ptr, new_size);
|
|
||||||
if (!result) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zero out new memory.
|
|
||||||
if (new_size > old_size) {
|
|
||||||
xe_zero_memory(result, new_size, old_size, new_size - old_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void xe_free(void *ptr) {
|
|
||||||
if (ptr) {
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xe_aligned_void_t *xe_malloc_aligned(const size_t size) {
|
|
||||||
// TODO(benvanik): validate every platform is aligned to XE_ALIGNMENT.
|
|
||||||
return xe_malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void xe_free_aligned(xe_aligned_void_t *ptr) {
|
|
||||||
xe_free((void*)ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int xe_zero_struct(void *ptr, const size_t size) {
|
|
||||||
return xe_zero_memory(ptr, size, 0, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int xe_zero_memory(void *ptr, const size_t size, const size_t offset,
|
|
||||||
const size_t length) {
|
|
||||||
// TODO(benvanik): validate sizing/clamp.
|
|
||||||
if (!ptr || !length) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (offset + length > size) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
memset((uint8_t*)ptr + offset, 0, length);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int xe_copy_struct(void *dest, const void *source, const size_t size) {
|
|
||||||
return xe_copy_memory(dest, size, source, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int xe_copy_memory(void *dest, const size_t dest_size, const void *source,
|
|
||||||
const size_t source_size) {
|
|
||||||
// TODO(benvanik): validate sizing.
|
|
||||||
if (!source_size) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!dest || !source) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (dest_size < source_size) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
memcpy(dest, source, source_size);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* Xenia : Xbox 360 Emulator Research Project *
|
|
||||||
******************************************************************************
|
|
||||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
||||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef XENIA_MALLOC_H_
|
|
||||||
#define XENIA_MALLOC_H_
|
|
||||||
|
|
||||||
#include <xenia/types.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define xe_alloca(size) alloca(size)
|
|
||||||
|
|
||||||
void *xe_malloc(const size_t size);
|
|
||||||
void *xe_calloc(const size_t size);
|
|
||||||
void *xe_realloc(void *ptr, const size_t old_size, const size_t new_size);
|
|
||||||
void *xe_recalloc(void *ptr, const size_t old_size, const size_t new_size);
|
|
||||||
void xe_free(void *ptr);
|
|
||||||
|
|
||||||
typedef __declspec(align(16)) volatile void xe_aligned_void_t;
|
|
||||||
xe_aligned_void_t *xe_malloc_aligned(const size_t size);
|
|
||||||
void xe_free_aligned(xe_aligned_void_t *ptr);
|
|
||||||
|
|
||||||
int xe_zero_struct(void *ptr, const size_t size);
|
|
||||||
int xe_zero_memory(void *ptr, const size_t size, const size_t offset,
|
|
||||||
const size_t length);
|
|
||||||
int xe_copy_struct(void *dest, const void *source, const size_t size);
|
|
||||||
int xe_copy_memory(void *dest, const size_t dest_size, const void *source,
|
|
||||||
const size_t source_size);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // XENIA_MALLOC_H_
|
|
|
@ -348,7 +348,7 @@ uint64_t Memory::HeapAlloc(uint64_t base_address, size_t size, uint32_t flags,
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
if (flags & MEMORY_FLAG_ZERO) {
|
if (flags & MEMORY_FLAG_ZERO) {
|
||||||
xe_zero_struct(Translate(result), size);
|
memset(Translate(result), 0, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -377,7 +377,7 @@ uint64_t Memory::HeapAlloc(uint64_t base_address, size_t size, uint32_t flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & MEMORY_FLAG_ZERO) {
|
if (flags & MEMORY_FLAG_ZERO) {
|
||||||
xe_zero_struct(pv, size);
|
memset(pv, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base_address;
|
return base_address;
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
'export_resolver.h',
|
'export_resolver.h',
|
||||||
'logging.cc',
|
'logging.cc',
|
||||||
'logging.h',
|
'logging.h',
|
||||||
'malloc.cc',
|
|
||||||
'malloc.h',
|
|
||||||
'memory.cc',
|
'memory.cc',
|
||||||
'memory.h',
|
'memory.h',
|
||||||
'profiling.cc',
|
'profiling.cc',
|
||||||
|
|
|
@ -266,7 +266,7 @@ public:
|
||||||
if (buffer == NULL || length == 0) {
|
if (buffer == NULL || length == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
auto copy = (char*)xe_calloc(length + 1);
|
auto copy = (char*)calloc(length + 1, sizeof(char));
|
||||||
std::strncpy(copy, buffer, length);
|
std::strncpy(copy, buffer, length);
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,8 @@ class ThreadState : public alloy::runtime::ThreadState {
|
||||||
memset(memory_->Translate(stack_address_), 0, stack_size_);
|
memset(memory_->Translate(stack_address_), 0, stack_size_);
|
||||||
|
|
||||||
// Allocate with 64b alignment.
|
// Allocate with 64b alignment.
|
||||||
context_ = (PPCContext*)xe_malloc_aligned(sizeof(PPCContext));
|
context_ = (PPCContext*)calloc(1, sizeof(PPCContext));
|
||||||
assert_true((reinterpret_cast<uint64_t>(context_) & 0xF) == 0);
|
assert_true((reinterpret_cast<uint64_t>(context_) & 0xF) == 0);
|
||||||
memset(&context_, 0, sizeof(PPCContext));
|
|
||||||
|
|
||||||
// Stash pointers to common structures that callbacks may need.
|
// Stash pointers to common structures that callbacks may need.
|
||||||
context_->reserve_address = memory_->reserve_address();
|
context_->reserve_address = memory_->reserve_address();
|
||||||
|
@ -59,7 +58,7 @@ class ThreadState : public alloy::runtime::ThreadState {
|
||||||
}
|
}
|
||||||
~ThreadState() override {
|
~ThreadState() override {
|
||||||
runtime_->debugger()->OnThreadDestroyed(this);
|
runtime_->debugger()->OnThreadDestroyed(this);
|
||||||
xe_free_aligned(context_);
|
free(context_);
|
||||||
}
|
}
|
||||||
|
|
||||||
PPCContext* context() const { return context_; }
|
PPCContext* context() const { return context_; }
|
||||||
|
|
Loading…
Reference in New Issue