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;
|
||||
}
|
||||
void* result = xe_malloc(total_length);
|
||||
void* result = malloc(total_length);
|
||||
uint8_t* p = (uint8_t*)result;
|
||||
chunk = head_chunk_;
|
||||
while (chunk) {
|
||||
xe_copy_struct(p, chunk->buffer, chunk->offset);
|
||||
memcpy(p, chunk->buffer, chunk->offset);
|
||||
p += chunk->offset;
|
||||
if (chunk == active_chunk_) {
|
||||
break;
|
||||
|
@ -89,12 +89,12 @@ void* Arena::CloneContents() {
|
|||
|
||||
Arena::Chunk::Chunk(size_t chunk_size)
|
||||
: 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() {
|
||||
if (buffer) {
|
||||
xe_free(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,13 @@ IVMFunction::IVMFunction(FunctionInfo* symbol_info)
|
|||
: Function(symbol_info),
|
||||
register_count_(0),
|
||||
intcode_count_(0),
|
||||
intcodes_(0),
|
||||
intcodes_(nullptr),
|
||||
source_map_count_(0),
|
||||
source_map_(0) {}
|
||||
source_map_(nullptr) {}
|
||||
|
||||
IVMFunction::~IVMFunction() {
|
||||
xe_free(intcodes_);
|
||||
xe_free(source_map_);
|
||||
free(intcodes_);
|
||||
free(source_map_);
|
||||
}
|
||||
|
||||
void IVMFunction::Setup(TranslationContext& ctx) {
|
||||
|
|
|
@ -65,12 +65,12 @@ void IVMStack::Free(size_t register_count) {
|
|||
|
||||
IVMStack::Chunk::Chunk(size_t chunk_size)
|
||||
: 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() {
|
||||
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,
|
||||
size_t code_size, StringBuffer* str) {
|
||||
BE::DISASM disasm;
|
||||
xe_zero_struct(&disasm, sizeof(disasm));
|
||||
BE::DISASM disasm = {0};
|
||||
disasm.Archi = 64;
|
||||
disasm.Options = BE::Tabulation + BE::MasmSyntax + BE::PrefixedNumeral;
|
||||
disasm.EIP = (BE::UIntPtr)machine_code;
|
||||
|
|
|
@ -76,7 +76,7 @@ void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
|
|||
lock_.unlock();
|
||||
|
||||
// Copy code.
|
||||
xe_copy_struct(final_address, machine_code, code_size);
|
||||
memcpy(final_address, machine_code, code_size);
|
||||
|
||||
return final_address;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ RegisterAllocationPass::RegisterAllocationPass(const MachineInfo* machine_info)
|
|||
// Initialize register sets.
|
||||
// TODO(benvanik): rewrite in a way that makes sense - this is terrible.
|
||||
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;
|
||||
while (mi_sets[n].count) {
|
||||
auto& mi_set = mi_sets[n];
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
// TODO(benvanik): move the common stuff into here?
|
||||
#include <xenia/logging.h>
|
||||
#include <xenia/malloc.h>
|
||||
#include <xenia/profiling.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*);
|
||||
instr_offset_list_ = (Instr**)arena_->Alloc(list_size);
|
||||
label_list_ = (Label**)arena_->Alloc(list_size);
|
||||
xe_zero_struct(instr_offset_list_, list_size);
|
||||
xe_zero_struct(label_list_, list_size);
|
||||
memset(instr_offset_list_, 0, list_size);
|
||||
memset(label_list_, 0, list_size);
|
||||
|
||||
// Always mark entry with label.
|
||||
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",
|
||||
(uint32_t)address);
|
||||
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) {
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace tables {
|
|||
static InstrType** instr_table_prep(InstrType* unprep, size_t unprep_count,
|
||||
int a, int b) {
|
||||
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++) {
|
||||
int ordinal = select_bits(unprep[n].opcode, a, b);
|
||||
prep[ordinal] = &unprep[n];
|
||||
|
@ -107,7 +107,7 @@ static InstrType** instr_table_prep_63(InstrType* unprep, size_t unprep_count,
|
|||
int a, int b) {
|
||||
// Special handling for A format instructions.
|
||||
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++) {
|
||||
int ordinal = select_bits(unprep[n].opcode, a, b);
|
||||
if (unprep[n].format == kXEPPCInstrFormatA) {
|
||||
|
|
|
@ -632,7 +632,7 @@ void HIRBuilder::Comment(const char* format, ...) {
|
|||
return;
|
||||
}
|
||||
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);
|
||||
i->src1.offset = (uint64_t)p;
|
||||
i->src2.value = i->src3.value = NULL;
|
||||
|
|
|
@ -21,11 +21,11 @@ DebugInfo::DebugInfo()
|
|||
source_map_(nullptr) {}
|
||||
|
||||
DebugInfo::~DebugInfo() {
|
||||
xe_free(source_map_);
|
||||
xe_free(source_disasm_);
|
||||
xe_free(raw_hir_disasm_);
|
||||
xe_free(hir_disasm_);
|
||||
xe_free(machine_code_disasm_);
|
||||
free(source_map_);
|
||||
free(source_disasm_);
|
||||
free(raw_hir_disasm_);
|
||||
free(hir_disasm_);
|
||||
free(machine_code_disasm_);
|
||||
}
|
||||
|
||||
void DebugInfo::InitializeSourceMap(size_t source_map_count,
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <poly/string.h>
|
||||
|
||||
#include <xenia/logging.h>
|
||||
#include <xenia/malloc.h>
|
||||
#include <xenia/profiling.h>
|
||||
#include <xenia/types.h>
|
||||
|
||||
|
|
|
@ -9,14 +9,9 @@
|
|||
|
||||
#include <xenia/core/ref.h>
|
||||
|
||||
void xe_ref_init(xe_ref_t* ref) { ref->count = 1; }
|
||||
|
||||
void xe_ref_init(xe_ref_t* ref) {
|
||||
ref->count = 1;
|
||||
}
|
||||
|
||||
void xe_ref_retain(xe_ref_t* ref) {
|
||||
poly::atomic_inc(&ref->count);
|
||||
}
|
||||
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) {
|
||||
if (!ref) {
|
||||
|
@ -26,6 +21,6 @@ void xe_ref_release(xe_ref_t* ref, xe_ref_dealloc_t dealloc) {
|
|||
if (dealloc) {
|
||||
dealloc(ref);
|
||||
}
|
||||
xe_free(ref);
|
||||
free(ref);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <netinet/tcp.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
void xe_socket_init() {
|
||||
// No-op.
|
||||
}
|
||||
|
@ -35,31 +34,30 @@ void xe_socket_close(socket_t socket) {
|
|||
|
||||
void xe_socket_set_keepalive(socket_t socket, bool value) {
|
||||
int opt_value = value ? 1 : 0;
|
||||
setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&opt_value, sizeof(opt_value));
|
||||
setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &opt_value, sizeof(opt_value));
|
||||
}
|
||||
|
||||
void xe_socket_set_reuseaddr(socket_t socket, bool value) {
|
||||
int opt_value = value ? 1 : 0;
|
||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
|
||||
&opt_value, sizeof(opt_value));
|
||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &opt_value, sizeof(opt_value));
|
||||
}
|
||||
|
||||
void xe_socket_set_nodelay(socket_t socket, bool value) {
|
||||
int opt_value = value ? 1 : 0;
|
||||
setsockopt(socket, IPPROTO_TCP, TCP_NODELAY,
|
||||
&opt_value, sizeof(opt_value));
|
||||
setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &opt_value, sizeof(opt_value));
|
||||
}
|
||||
|
||||
void xe_socket_set_nonblock(socket_t socket, bool value) {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
int r;
|
||||
while ((r = fcntl(socket, F_SETFL, flags | O_NONBLOCK)) == -1 &&
|
||||
errno == EINTR);
|
||||
errno == EINTR)
|
||||
;
|
||||
if (r == -1) {
|
||||
return;
|
||||
}
|
||||
|
@ -67,9 +65,9 @@ void xe_socket_set_nonblock(socket_t socket, bool value) {
|
|||
|
||||
int xe_socket_bind(socket_t socket, uint32_t port) {
|
||||
struct sockaddr_in socket_addr;
|
||||
socket_addr.sin_family = AF_INET;
|
||||
socket_addr.sin_family = AF_INET;
|
||||
socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
socket_addr.sin_port = htons(port);
|
||||
socket_addr.sin_port = htons(port);
|
||||
int r = bind(socket, (struct sockaddr*)&socket_addr, sizeof(socket_addr));
|
||||
if (r < 0) {
|
||||
return 1;
|
||||
|
@ -79,9 +77,9 @@ int xe_socket_bind(socket_t socket, uint32_t port) {
|
|||
|
||||
int xe_socket_bind_loopback(socket_t socket) {
|
||||
struct sockaddr_in socket_addr;
|
||||
socket_addr.sin_family = AF_INET;
|
||||
socket_addr.sin_family = AF_INET;
|
||||
socket_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
socket_addr.sin_port = htons(0);
|
||||
socket_addr.sin_port = htons(0);
|
||||
int r = bind(socket, (struct sockaddr*)&socket_addr, sizeof(socket_addr));
|
||||
if (r == SOCKET_ERROR) {
|
||||
return 1;
|
||||
|
@ -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) {
|
||||
struct sockaddr_in client_addr;
|
||||
socklen_t client_count = sizeof(client_addr);
|
||||
socket_t client_socket_id = accept(
|
||||
socket, (struct sockaddr*)&client_addr, &client_count);
|
||||
socket_t client_socket_id =
|
||||
accept(socket, (struct sockaddr*)&client_addr, &client_count);
|
||||
if (client_socket_id < 0) {
|
||||
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;
|
||||
|
||||
int client_ip = client_addr.sin_addr.s_addr;
|
||||
inet_ntop(AF_INET, &client_ip,
|
||||
out_client_info->addr, XECOUNT(out_client_info->addr));
|
||||
inet_ntop(AF_INET, &client_ip, out_client_info->addr,
|
||||
XECOUNT(out_client_info->addr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -130,21 +128,21 @@ int64_t xe_socket_recv(socket_t socket, uint8_t* data, size_t length, int flags,
|
|||
}
|
||||
|
||||
struct xe_socket_loop {
|
||||
socket_t socket;
|
||||
socket_t socket;
|
||||
|
||||
int notify_rd_id;
|
||||
int notify_wr_id;
|
||||
int notify_rd_id;
|
||||
int notify_wr_id;
|
||||
|
||||
struct pollfd events[2];
|
||||
|
||||
bool pending_queued_write;
|
||||
bool pending_recv;
|
||||
bool pending_send;
|
||||
bool pending_queued_write;
|
||||
bool pending_recv;
|
||||
bool pending_send;
|
||||
};
|
||||
|
||||
xe_socket_loop_t* xe_socket_loop_create(socket_t socket) {
|
||||
xe_socket_loop_t* loop = (xe_socket_loop_t*)xe_calloc(
|
||||
sizeof(xe_socket_loop_t));
|
||||
xe_socket_loop_t* loop =
|
||||
(xe_socket_loop_t*)calloc(1, sizeof(xe_socket_loop_t));
|
||||
|
||||
loop->socket = socket;
|
||||
|
||||
|
@ -153,10 +151,10 @@ xe_socket_loop_t* xe_socket_loop_create(socket_t socket) {
|
|||
loop->notify_rd_id = notify_ids[0];
|
||||
loop->notify_wr_id = notify_ids[1];
|
||||
|
||||
loop->events[0].fd = socket;
|
||||
loop->events[0].events = POLLIN;
|
||||
loop->events[1].fd = loop->notify_rd_id;
|
||||
loop->events[1].events = POLLIN;
|
||||
loop->events[0].fd = socket;
|
||||
loop->events[0].events = POLLIN;
|
||||
loop->events[1].fd = loop->notify_rd_id;
|
||||
loop->events[1].events = POLLIN;
|
||||
|
||||
return loop;
|
||||
}
|
||||
|
@ -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) {
|
||||
close(loop->notify_rd_id);
|
||||
close(loop->notify_wr_id);
|
||||
xe_free(loop);
|
||||
free(loop);
|
||||
}
|
||||
|
||||
int xe_socket_loop_poll(xe_socket_loop_t* loop,
|
||||
bool check_read, bool check_write) {
|
||||
int xe_socket_loop_poll(xe_socket_loop_t* loop, bool check_read,
|
||||
bool check_write) {
|
||||
// Prep events object.
|
||||
if (check_read) {
|
||||
loop->events[0].events |= POLLIN;
|
||||
|
@ -180,7 +178,8 @@ int xe_socket_loop_poll(xe_socket_loop_t* loop,
|
|||
// Poll.
|
||||
int r;
|
||||
while ((r = poll(loop->events, XECOUNT(loop->events), -1)) == -1 &&
|
||||
errno == EINTR);
|
||||
errno == EINTR)
|
||||
;
|
||||
if (r == -1) {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,8 @@ XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id,
|
|||
assert_not_zero(stack_address_);
|
||||
|
||||
// Allocate with 64b alignment.
|
||||
context_ = (PPCContext*)xe_malloc_aligned(sizeof(PPCContext));
|
||||
context_ = (PPCContext*)calloc(1, sizeof(PPCContext));
|
||||
assert_true(((uint64_t)context_ & 0xF) == 0);
|
||||
xe_zero_struct(context_, sizeof(PPCContext));
|
||||
|
||||
// Stash pointers to common structures that callbacks may need.
|
||||
context_->reserve_address = memory_->reserve_address();
|
||||
|
@ -55,7 +54,7 @@ XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id,
|
|||
XenonThreadState::~XenonThreadState() {
|
||||
runtime_->debugger()->OnThreadDestroyed(this);
|
||||
|
||||
xe_free_aligned(context_);
|
||||
free(context_);
|
||||
xenon_memory()->HeapFree(stack_address_, stack_size_);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,19 +9,16 @@
|
|||
|
||||
#include <xenia/gpu/register_file.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
|
||||
|
||||
RegisterFile::RegisterFile() {
|
||||
xe_zero_struct(values, sizeof(values));
|
||||
}
|
||||
RegisterFile::RegisterFile() { memset(values, 0, sizeof(values)); }
|
||||
|
||||
const char* RegisterFile::GetRegisterName(uint32_t index) {
|
||||
switch (index) {
|
||||
#define XE_GPU_REGISTER(index, type, name) \
|
||||
case index: return #name;
|
||||
case index: \
|
||||
return #name;
|
||||
#include <xenia/gpu/xenos/register_table.inc>
|
||||
#undef XE_GPU_REGISTER
|
||||
default:
|
||||
|
|
|
@ -12,21 +12,21 @@
|
|||
#include <poly/math.h>
|
||||
#include <xenia/gpu/xenos/ucode_disassembler.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
using namespace xe::gpu::xenos;
|
||||
|
||||
|
||||
ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
||||
const Info& info,
|
||||
xenos::XE_GPU_SHADER_TYPE type)
|
||||
const Info& info, xenos::XE_GPU_SHADER_TYPE type)
|
||||
: HashedResource(memory_range),
|
||||
info_(info), type_(type), is_prepared_(false), disasm_src_(nullptr) {
|
||||
xe_zero_struct(&alloc_counts_, sizeof(alloc_counts_));
|
||||
xe_zero_struct(&buffer_inputs_, sizeof(buffer_inputs_));
|
||||
xe_zero_struct(&sampler_inputs_, sizeof(sampler_inputs_));
|
||||
info_(info),
|
||||
type_(type),
|
||||
is_prepared_(false),
|
||||
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.
|
||||
dword_count_ = memory_range.length / 4;
|
||||
|
@ -34,7 +34,7 @@ ShaderResource::ShaderResource(const MemoryRange& memory_range,
|
|||
|
||||
// Copy bytes and swap.
|
||||
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++) {
|
||||
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() {
|
||||
xe_free(disasm_src_);
|
||||
xe_free(dwords_);
|
||||
free(disasm_src_);
|
||||
free(dwords_);
|
||||
}
|
||||
|
||||
void ShaderResource::GatherIO() {
|
||||
|
@ -83,18 +83,18 @@ void ShaderResource::GatherAlloc(const instr_cf_alloc_t* cf) {
|
|||
allocs_.push_back(*cf);
|
||||
|
||||
switch (cf->buffer_select) {
|
||||
case SQ_POSITION:
|
||||
// Position (SV_POSITION).
|
||||
alloc_counts_.positions += cf->size + 1;
|
||||
break;
|
||||
case SQ_PARAMETER_PIXEL:
|
||||
// Output to PS (if VS), or frag output (if PS).
|
||||
alloc_counts_.params += cf->size + 1;
|
||||
break;
|
||||
case SQ_MEMORY:
|
||||
// MEMEXPORT?
|
||||
alloc_counts_.memories += cf->size + 1;
|
||||
break;
|
||||
case SQ_POSITION:
|
||||
// Position (SV_POSITION).
|
||||
alloc_counts_.positions += cf->size + 1;
|
||||
break;
|
||||
case SQ_PARAMETER_PIXEL:
|
||||
// Output to PS (if VS), or frag output (if PS).
|
||||
alloc_counts_.params += cf->size + 1;
|
||||
break;
|
||||
case SQ_MEMORY:
|
||||
// MEMEXPORT?
|
||||
alloc_counts_.memories += cf->size + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,27 +109,26 @@ void ShaderResource::GatherExec(const instr_cf_exec_t* cf) {
|
|||
const instr_fetch_t* fetch =
|
||||
(const instr_fetch_t*)(dwords_ + alu_off * 3);
|
||||
switch (fetch->opc) {
|
||||
case VTX_FETCH:
|
||||
GatherVertexFetch(&fetch->vtx);
|
||||
break;
|
||||
case TEX_FETCH:
|
||||
GatherTextureFetch(&fetch->tex);
|
||||
break;
|
||||
case TEX_GET_BORDER_COLOR_FRAC:
|
||||
case TEX_GET_COMP_TEX_LOD:
|
||||
case TEX_GET_GRADIENTS:
|
||||
case TEX_GET_WEIGHTS:
|
||||
case TEX_SET_TEX_LOD:
|
||||
case TEX_SET_GRADIENTS_H:
|
||||
case TEX_SET_GRADIENTS_V:
|
||||
default:
|
||||
assert_always();
|
||||
break;
|
||||
case VTX_FETCH:
|
||||
GatherVertexFetch(&fetch->vtx);
|
||||
break;
|
||||
case TEX_FETCH:
|
||||
GatherTextureFetch(&fetch->tex);
|
||||
break;
|
||||
case TEX_GET_BORDER_COLOR_FRAC:
|
||||
case TEX_GET_COMP_TEX_LOD:
|
||||
case TEX_GET_GRADIENTS:
|
||||
case TEX_GET_WEIGHTS:
|
||||
case TEX_SET_TEX_LOD:
|
||||
case TEX_SET_GRADIENTS_H:
|
||||
case TEX_SET_GRADIENTS_V:
|
||||
default:
|
||||
assert_always();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// TODO(benvanik): gather registers used, predicate bits used, etc.
|
||||
const instr_alu_t* alu =
|
||||
(const instr_alu_t*)(dwords_ + alu_off * 3);
|
||||
const instr_alu_t* alu = (const instr_alu_t*)(dwords_ + alu_off * 3);
|
||||
if (alu->vector_write_mask) {
|
||||
if (alu->export_data && alu->vector_dest == 63) {
|
||||
alloc_counts_.point_size = true;
|
||||
|
@ -213,39 +212,39 @@ void ShaderResource::GatherVertexFetch(const instr_fetch_vtx_t* vtx) {
|
|||
el->offset_words = vtx->offset;
|
||||
el->size_words = 0;
|
||||
switch (el->format) {
|
||||
case FMT_8_8_8_8:
|
||||
case FMT_2_10_10_10:
|
||||
case FMT_10_11_11:
|
||||
case FMT_11_11_10:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_16_16:
|
||||
case FMT_16_16_FLOAT:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_16_16_16_16:
|
||||
case FMT_16_16_16_16_FLOAT:
|
||||
el->size_words = 2;
|
||||
break;
|
||||
case FMT_32:
|
||||
case FMT_32_FLOAT:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_32_32:
|
||||
case FMT_32_32_FLOAT:
|
||||
el->size_words = 2;
|
||||
break;
|
||||
case FMT_32_32_32_FLOAT:
|
||||
el->size_words = 3;
|
||||
break;
|
||||
case FMT_32_32_32_32:
|
||||
case FMT_32_32_32_32_FLOAT:
|
||||
el->size_words = 4;
|
||||
break;
|
||||
default:
|
||||
XELOGE("Unknown vertex format: %d", el->format);
|
||||
assert_always();
|
||||
break;
|
||||
case FMT_8_8_8_8:
|
||||
case FMT_2_10_10_10:
|
||||
case FMT_10_11_11:
|
||||
case FMT_11_11_10:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_16_16:
|
||||
case FMT_16_16_FLOAT:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_16_16_16_16:
|
||||
case FMT_16_16_16_16_FLOAT:
|
||||
el->size_words = 2;
|
||||
break;
|
||||
case FMT_32:
|
||||
case FMT_32_FLOAT:
|
||||
el->size_words = 1;
|
||||
break;
|
||||
case FMT_32_32:
|
||||
case FMT_32_32_FLOAT:
|
||||
el->size_words = 2;
|
||||
break;
|
||||
case FMT_32_32_32_FLOAT:
|
||||
el->size_words = 3;
|
||||
break;
|
||||
case FMT_32_32_32_32:
|
||||
case FMT_32_32_32_32_FLOAT:
|
||||
el->size_words = 4;
|
||||
break;
|
||||
default:
|
||||
XELOGE("Unknown vertex format: %d", el->format);
|
||||
assert_always();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,22 +254,20 @@ void ShaderResource::GatherTextureFetch(const xenos::instr_fetch_tex_t* tex) {
|
|||
assert_true(sampler_inputs_.count + 1 < poly::countof(sampler_inputs_.descs));
|
||||
auto& input = sampler_inputs_.descs[sampler_inputs_.count++];
|
||||
input.input_index = sampler_inputs_.count - 1;
|
||||
input.fetch_slot = tex->const_idx & 0xF; // ?
|
||||
input.fetch_slot = tex->const_idx & 0xF; // ?
|
||||
input.tex_fetch = *tex;
|
||||
|
||||
// Format mangling, size estimation, etc.
|
||||
}
|
||||
|
||||
VertexShaderResource::VertexShaderResource(
|
||||
const MemoryRange& memory_range, const Info& info)
|
||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_VERTEX) {
|
||||
}
|
||||
VertexShaderResource::VertexShaderResource(const MemoryRange& memory_range,
|
||||
const Info& info)
|
||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_VERTEX) {}
|
||||
|
||||
VertexShaderResource::~VertexShaderResource() = default;
|
||||
|
||||
PixelShaderResource::PixelShaderResource(
|
||||
const MemoryRange& memory_range, const Info& info)
|
||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_PIXEL) {
|
||||
}
|
||||
PixelShaderResource::PixelShaderResource(const MemoryRange& memory_range,
|
||||
const Info& info)
|
||||
: ShaderResource(memory_range, info, XE_GPU_SHADER_TYPE_PIXEL) {}
|
||||
|
||||
PixelShaderResource::~PixelShaderResource() = default;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace fs {
|
|||
|
||||
DiscImageFile::DiscImageFile(KernelState* kernel_state, Mode mode,
|
||||
DiscImageEntry* entry)
|
||||
: entry_(entry), XFile(kernel_state, mode) {}
|
||||
: XFile(kernel_state, mode), entry_(entry) {}
|
||||
|
||||
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_length = std::min(buffer_length, gdfx_entry->size - byte_offset);
|
||||
xe_copy_memory(buffer, buffer_length, entry_->mmap()->data() + real_offset,
|
||||
real_length);
|
||||
memcpy(buffer, entry_->mmap()->data() + real_offset, real_length);
|
||||
*out_bytes_read = real_length;
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ X_STATUS STFSContainerFile::ReadSync(void* buffer, size_t buffer_length,
|
|||
offset += 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;
|
||||
remaining_length -= read_length;
|
||||
}
|
||||
|
|
|
@ -50,19 +50,14 @@ void GDFXEntry::Dump(int indent) {
|
|||
}
|
||||
}
|
||||
|
||||
GDFX::GDFX(poly::MappedMemory* mmap) : mmap_(mmap) {
|
||||
root_entry_ = nullptr;
|
||||
}
|
||||
GDFX::GDFX(poly::MappedMemory* mmap) : mmap_(mmap) { root_entry_ = nullptr; }
|
||||
|
||||
GDFX::~GDFX() {
|
||||
delete root_entry_;
|
||||
}
|
||||
GDFX::~GDFX() { delete root_entry_; }
|
||||
|
||||
GDFXEntry* GDFX::root_entry() { return root_entry_; }
|
||||
|
||||
GDFX::Error GDFX::Load() {
|
||||
ParseState state;
|
||||
xe_zero_struct(&state, sizeof(state));
|
||||
ParseState state = {0};
|
||||
|
||||
state.ptr = mmap_->data();
|
||||
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);
|
||||
file_table_block_count = poly::load_and_swap<uint16_t>(p + 0x03);
|
||||
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_unallocated_block_count = poly::load_and_swap<uint32_t>(p + 0x20);
|
||||
return true;
|
||||
};
|
||||
|
||||
bool STFSHeader::Read(const uint8_t* p) {
|
||||
xe_copy_struct(license_entries, p + 0x22C, 0x100);
|
||||
xe_copy_struct(header_hash, p + 0x32C, 0x14);
|
||||
memcpy(license_entries, p + 0x22C, 0x100);
|
||||
memcpy(header_hash, p + 0x32C, 0x14);
|
||||
header_size = poly::load_and_swap<uint32_t>(p + 0x340);
|
||||
content_type = (STFSContentType)poly::load_and_swap<uint32_t>(p + 0x344);
|
||||
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_in_set = poly::load_and_swap<uint8_t>(p + 0x367);
|
||||
save_game_id = poly::load_and_swap<uint32_t>(p + 0x368);
|
||||
xe_copy_struct(console_id, p + 0x36C, 0x5);
|
||||
xe_copy_struct(profile_id, p + 0x371, 0x8);
|
||||
memcpy(console_id, p + 0x36C, 0x5);
|
||||
memcpy(profile_id, p + 0x371, 0x8);
|
||||
data_file_count = poly::load_and_swap<uint32_t>(p + 0x39D);
|
||||
data_file_combined_size = poly::load_and_swap<uint64_t>(p + 0x3A1);
|
||||
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)) {
|
||||
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++) {
|
||||
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);
|
||||
|
@ -88,8 +88,8 @@ bool STFSHeader::Read(const uint8_t* p) {
|
|||
transfer_flags = poly::load_and_swap<uint8_t>(p + 0x1711);
|
||||
thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1712);
|
||||
title_thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1716);
|
||||
xe_copy_struct(thumbnail_image, p + 0x171A, 0x4000);
|
||||
xe_copy_struct(title_thumbnail_image, p + 0x571A, 0x4000);
|
||||
memcpy(thumbnail_image, p + 0x171A, 0x4000);
|
||||
memcpy(title_thumbnail_image, p + 0x571A, 0x4000);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace xe {
|
|||
namespace kernel {
|
||||
|
||||
ObjectTable::ObjectTable()
|
||||
: table_capacity_(0), table_(NULL), last_free_entry_(0) {}
|
||||
: table_capacity_(0), table_(nullptr), last_free_entry_(0) {}
|
||||
|
||||
ObjectTable::~ObjectTable() {
|
||||
std::lock_guard<std::mutex> lock(table_mutex_);
|
||||
|
@ -34,7 +34,7 @@ ObjectTable::~ObjectTable() {
|
|||
|
||||
table_capacity_ = 0;
|
||||
last_free_entry_ = 0;
|
||||
xe_free(table_);
|
||||
free(table_);
|
||||
table_ = NULL;
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,18 @@ X_STATUS ObjectTable::FindFreeSlot(uint32_t* out_slot) {
|
|||
|
||||
// Table out of slots, expand.
|
||||
uint32_t new_table_capacity = std::max(16 * 1024u, table_capacity_ * 2);
|
||||
ObjectTableEntry* new_table = (ObjectTableEntry*)xe_recalloc(
|
||||
table_, table_capacity_ * sizeof(ObjectTableEntry),
|
||||
new_table_capacity * sizeof(ObjectTableEntry));
|
||||
size_t new_table_size = new_table_capacity * sizeof(ObjectTableEntry);
|
||||
size_t old_table_size = table_capacity_ * sizeof(ObjectTableEntry);
|
||||
ObjectTableEntry* new_table =
|
||||
(ObjectTableEntry*)realloc(table_, new_table_size);
|
||||
if (!new_table) {
|
||||
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_;
|
||||
table_capacity_ = new_table_capacity;
|
||||
table_ = new_table;
|
||||
|
|
|
@ -74,8 +74,7 @@ class XDirectoryInfo {
|
|||
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 + 60, info->file_name_length);
|
||||
xe_copy_memory(dst + 64, info->file_name_length, info->file_name,
|
||||
info->file_name_length);
|
||||
memcpy(dst + 64, info->file_name, info->file_name_length);
|
||||
dst += info->next_entry_offset;
|
||||
src += info->next_entry_offset;
|
||||
} 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 + 12, this->label_length);
|
||||
poly::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
|
||||
xe_copy_memory(dst + 20, this->label_length, this->label,
|
||||
this->label_length);
|
||||
memcpy(dst + 20, this->label, this->label_length);
|
||||
}
|
||||
};
|
||||
static_assert_size(XVolumeInfo, 24);
|
||||
|
@ -120,8 +118,7 @@ class XFileSystemAttributeInfo {
|
|||
poly::store_and_swap<uint32_t>(dst + 4,
|
||||
this->maximum_component_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,
|
||||
this->fs_name_length);
|
||||
memcpy(dst + 12, this->fs_name, this->fs_name_length);
|
||||
}
|
||||
};
|
||||
static_assert_size(XFileSystemAttributeInfo, 16);
|
||||
|
|
|
@ -67,7 +67,7 @@ X_STATUS XUserModule::LoadFromFile(const char* path) {
|
|||
XEEXPECTZERO(result);
|
||||
|
||||
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.
|
||||
result = fs_entry->Open(kernel_state(), fs::Mode::READ, false, &file);
|
||||
|
@ -85,7 +85,7 @@ X_STATUS XUserModule::LoadFromFile(const char* path) {
|
|||
|
||||
XECLEANUP:
|
||||
if (buffer) {
|
||||
xe_free(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
if (file) {
|
||||
file->Release();
|
||||
|
@ -99,8 +99,7 @@ X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) {
|
|||
XenonRuntime* runtime = processor->runtime();
|
||||
|
||||
// Load the XEX into memory and decrypt.
|
||||
xe_xex2_options_t xex_options;
|
||||
xe_zero_struct(&xex_options, sizeof(xex_options));
|
||||
xe_xex2_options_t xex_options = {0};
|
||||
xex_ = xe_xex2_load(kernel_state()->memory(), addr, length, xex_options);
|
||||
if (!xex_) {
|
||||
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,
|
||||
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);
|
||||
|
||||
xex->memory = memory;
|
||||
|
@ -85,14 +85,14 @@ void xe_xex2_dealloc(xe_xex2_ref xex) {
|
|||
}
|
||||
|
||||
xe_xex2_header_t *header = &xex->header;
|
||||
xe_free(header->sections);
|
||||
xe_free(header->resource_infos);
|
||||
free(header->sections);
|
||||
free(header->resource_infos);
|
||||
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++) {
|
||||
xe_xex2_import_library_t *library = &header->import_libraries[n];
|
||||
xe_free(library->records);
|
||||
free(library->records);
|
||||
}
|
||||
|
||||
xex->memory = NULL;
|
||||
|
@ -162,13 +162,12 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
|||
break;
|
||||
case XEX_HEADER_RESOURCE_INFO: {
|
||||
header->resource_info_count = (opt_header->length - 4) / 16;
|
||||
header->resource_infos = (xe_xex2_resource_info_t *)xe_calloc(
|
||||
sizeof(xe_xex2_resource_info_t) * header->resource_info_count);
|
||||
header->resource_infos = (xe_xex2_resource_info_t *)calloc(
|
||||
header->resource_info_count, sizeof(xe_xex2_resource_info_t));
|
||||
const uint8_t *ph = pp + 0x04;
|
||||
for (size_t n = 0; n < header->resource_info_count; n++) {
|
||||
auto &res = header->resource_infos[n];
|
||||
XEEXPECTZERO(
|
||||
xe_copy_memory(res.name, sizeof(res.name), ph + 0x00, 8));
|
||||
memcpy(res.name, ph + 0x00, 8);
|
||||
res.address = poly::load_and_swap<uint32_t>(ph + 0x08);
|
||||
res.size = poly::load_and_swap<uint32_t>(ph + 0x0C);
|
||||
ph += 16;
|
||||
|
@ -254,8 +253,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
|
|||
pp += 12 + string_table_size;
|
||||
for (size_t m = 0; m < count; m++) {
|
||||
xe_xex2_import_library_t *library = &header->import_libraries[m];
|
||||
XEEXPECTZERO(xe_copy_memory(library->digest, sizeof(library->digest),
|
||||
pp + 0x04, 20));
|
||||
memcpy(library->digest, pp + 0x04, 20);
|
||||
library->import_id = poly::load_and_swap<uint32_t>(pp + 0x18);
|
||||
library->version.value = poly::load_and_swap<uint32_t>(pp + 0x1C);
|
||||
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->records =
|
||||
(uint32_t *)xe_calloc(library->record_count * sizeof(uint32_t));
|
||||
(uint32_t *)calloc(library->record_count, sizeof(uint32_t));
|
||||
XEEXPECTNOTNULL(library->records);
|
||||
pp += 0x28;
|
||||
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;
|
||||
for (size_t m = 0; m < count; m++) {
|
||||
xe_xex2_static_library_t *library = &header->static_libraries[m];
|
||||
XEEXPECTZERO(xe_copy_memory(library->name, sizeof(library->name),
|
||||
pp + 0x00, 8));
|
||||
memcpy(library->name, pp + 0x00, 8);
|
||||
library->name[8] = 0;
|
||||
library->major = poly::load_and_swap<uint16_t>(pp + 0x08);
|
||||
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);
|
||||
comp_info->block_count = (info_size - 8) / 8;
|
||||
comp_info->blocks =
|
||||
(xe_xex2_file_basic_compression_block_t *)xe_calloc(
|
||||
comp_info->block_count *
|
||||
(xe_xex2_file_basic_compression_block_t *)calloc(
|
||||
comp_info->block_count,
|
||||
sizeof(xe_xex2_file_basic_compression_block_t));
|
||||
XEEXPECTNOTNULL(comp_info->blocks);
|
||||
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_bits = window_bits;
|
||||
comp_info->block_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
|
||||
XEEXPECTZERO(xe_copy_memory(comp_info->block_hash,
|
||||
sizeof(comp_info->block_hash),
|
||||
pp + 0x10, 20));
|
||||
memcpy(comp_info->block_hash, pp + 0x10, 20);
|
||||
} break;
|
||||
case 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_size = poly::load_and_swap<uint32_t>(pc + 0x000);
|
||||
ldr->image_size = poly::load_and_swap<uint32_t>(pc + 0x004);
|
||||
XEEXPECTZERO(xe_copy_memory(ldr->rsa_signature, sizeof(ldr->rsa_signature),
|
||||
pc + 0x008, 256));
|
||||
memcpy(ldr->rsa_signature, pc + 0x008, 256);
|
||||
ldr->unklength = poly::load_and_swap<uint32_t>(pc + 0x108);
|
||||
ldr->image_flags =
|
||||
(xe_xex2_image_flags)poly::load_and_swap<uint32_t>(pc + 0x10C);
|
||||
ldr->load_address = poly::load_and_swap<uint32_t>(pc + 0x110);
|
||||
XEEXPECTZERO(xe_copy_memory(ldr->section_digest, sizeof(ldr->section_digest),
|
||||
pc + 0x114, 20));
|
||||
memcpy(ldr->section_digest, pc + 0x114, 20);
|
||||
ldr->import_table_count = poly::load_and_swap<uint32_t>(pc + 0x128);
|
||||
XEEXPECTZERO(xe_copy_memory(ldr->import_table_digest,
|
||||
sizeof(ldr->import_table_digest), pc + 0x12C,
|
||||
20));
|
||||
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));
|
||||
memcpy(ldr->import_table_digest, pc + 0x12C, 20);
|
||||
memcpy(ldr->media_id, pc + 0x140, 16);
|
||||
memcpy(ldr->file_key, pc + 0x150, 16);
|
||||
ldr->export_table = poly::load_and_swap<uint32_t>(pc + 0x160);
|
||||
XEEXPECTZERO(xe_copy_memory(ldr->header_digest, sizeof(ldr->header_digest),
|
||||
pc + 0x164, 20));
|
||||
memcpy(ldr->header_digest, pc + 0x164, 20);
|
||||
ldr->game_regions =
|
||||
(xe_xex2_region_flags)poly::load_and_swap<uint32_t>(pc + 0x178);
|
||||
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;
|
||||
header->section_count = poly::load_and_swap<uint32_t>(ps + 0x000);
|
||||
ps += 4;
|
||||
header->sections = (xe_xex2_section_t *)xe_calloc(header->section_count *
|
||||
sizeof(xe_xex2_section_t));
|
||||
header->sections = (xe_xex2_section_t *)calloc(header->section_count,
|
||||
sizeof(xe_xex2_section_t));
|
||||
XEEXPECTNOTNULL(header->sections);
|
||||
for (size_t n = 0; n < header->section_count; n++) {
|
||||
xe_xex2_section_t *section = &header->sections[n];
|
||||
section->info.value = poly::load_and_swap<uint32_t>(ps);
|
||||
ps += 4;
|
||||
XEEXPECTZERO(xe_copy_memory(section->digest, sizeof(section->digest), ps,
|
||||
sizeof(section->digest)));
|
||||
memcpy(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;
|
||||
}
|
||||
mspack_memory_file *memfile =
|
||||
(mspack_memory_file *)xe_calloc(sizeof(mspack_memory_file));
|
||||
(mspack_memory_file *)calloc(1, sizeof(mspack_memory_file));
|
||||
if (!memfile) {
|
||||
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) {
|
||||
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) {
|
||||
mspack_memory_file *memfile = (mspack_memory_file *)file;
|
||||
const off_t remaining = memfile->buffer_size - memfile->offset;
|
||||
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
||||
if (xe_copy_memory(buffer, total,
|
||||
(uint8_t *)memfile->buffer + memfile->offset, total)) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(buffer, (uint8_t *)memfile->buffer + memfile->offset, total);
|
||||
memfile->offset += 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;
|
||||
const off_t remaining = memfile->buffer_size - memfile->offset;
|
||||
const off_t total = std::min(static_cast<off_t>(chars), remaining);
|
||||
if (xe_copy_memory((uint8_t *)memfile->buffer + memfile->offset,
|
||||
memfile->buffer_size - memfile->offset, buffer, total)) {
|
||||
return -1;
|
||||
}
|
||||
memcpy((uint8_t *)memfile->buffer + memfile->offset, buffer, total);
|
||||
memfile->offset += total;
|
||||
return (int)total;
|
||||
}
|
||||
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) {
|
||||
xe_copy_memory(dest, chars, src, chars);
|
||||
memcpy(dest, src, chars);
|
||||
}
|
||||
struct mspack_system *mspack_memory_sys_create() {
|
||||
struct mspack_system *sys =
|
||||
(struct mspack_system *)xe_calloc(sizeof(struct mspack_system));
|
||||
(struct mspack_system *)calloc(1, sizeof(struct mspack_system));
|
||||
if (!sys) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -517,7 +498,7 @@ struct mspack_system *mspack_memory_sys_create() {
|
|||
sys->copy = mspack_memory_copy;
|
||||
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,
|
||||
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) {
|
||||
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:
|
||||
xe_xex2_decrypt_buffer(header->session_key, p, exe_length, buffer,
|
||||
uncompressed_size);
|
||||
|
@ -597,7 +582,7 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
|||
if (!alloc_result) {
|
||||
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
|
||||
uncompressed_size);
|
||||
XEFAIL();
|
||||
return 1;
|
||||
}
|
||||
uint8_t *buffer = memory->Translate(header->exe_address);
|
||||
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) {
|
||||
case XEX_ENCRYPTION_NONE:
|
||||
XEEXPECTZERO(xe_copy_memory(d, uncompressed_size - (d - buffer), p,
|
||||
exe_length - (p - source_buffer)));
|
||||
if (exe_length - (p - source_buffer) >
|
||||
uncompressed_size - (d - buffer)) {
|
||||
// Overflow.
|
||||
return 1;
|
||||
}
|
||||
memcpy(d, p, exe_length - (p - source_buffer));
|
||||
break;
|
||||
case XEX_ENCRYPTION_NORMAL: {
|
||||
const uint8_t *ct = p;
|
||||
|
@ -639,9 +628,6 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
|
|||
}
|
||||
|
||||
return 0;
|
||||
|
||||
XECLEANUP:
|
||||
return 1;
|
||||
}
|
||||
|
||||
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:
|
||||
// TODO: a way to do without a copy/alloc?
|
||||
free_input = true;
|
||||
input_buffer = (const uint8_t *)xe_calloc(input_size);
|
||||
input_buffer = (const uint8_t *)calloc(1, input_size);
|
||||
XEEXPECTNOTNULL(input_buffer);
|
||||
xe_xex2_decrypt_buffer(header->session_key, exe_buffer, exe_length,
|
||||
(uint8_t *)input_buffer, input_size);
|
||||
|
@ -692,14 +678,14 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
|||
return false;
|
||||
}
|
||||
|
||||
compress_buffer = (uint8_t *)xe_calloc(exe_length);
|
||||
compress_buffer = (uint8_t *)calloc(1, exe_length);
|
||||
XEEXPECTNOTNULL(compress_buffer);
|
||||
|
||||
p = input_buffer;
|
||||
d = compress_buffer;
|
||||
|
||||
// De-block.
|
||||
deblock_buffer = (uint8_t *)xe_calloc(input_size);
|
||||
deblock_buffer = (uint8_t *)calloc(1, input_size);
|
||||
XEEXPECTNOTNULL(deblock_buffer);
|
||||
block_size = header->file_format_info.compression_info.normal.block_size;
|
||||
while (block_size) {
|
||||
|
@ -714,7 +700,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
|
|||
if (!chunk_size) {
|
||||
break;
|
||||
}
|
||||
xe_copy_memory(d, exe_length - (d - compress_buffer), p, chunk_size);
|
||||
memcpy(d, p, chunk_size);
|
||||
p += chunk_size;
|
||||
d += chunk_size;
|
||||
|
||||
|
@ -770,10 +756,10 @@ XECLEANUP:
|
|||
mspack_memory_sys_destroy(sys);
|
||||
sys = NULL;
|
||||
}
|
||||
xe_free(compress_buffer);
|
||||
xe_free(deblock_buffer);
|
||||
free(compress_buffer);
|
||||
free(deblock_buffer);
|
||||
if (free_input) {
|
||||
xe_free((void *)input_buffer);
|
||||
free((void *)input_buffer);
|
||||
}
|
||||
return result_code;
|
||||
}
|
||||
|
@ -865,9 +851,8 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
|
|||
// Setup/load sections.
|
||||
sechdr = IMAGE_FIRST_SECTION(nthdr);
|
||||
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
|
||||
PESection *section = (PESection *)xe_calloc(sizeof(PESection));
|
||||
xe_copy_memory(section->name, sizeof(section->name), sechdr->Name,
|
||||
sizeof(sechdr->Name));
|
||||
PESection *section = (PESection *)calloc(1, sizeof(PESection));
|
||||
memcpy(section->name, sechdr->Name, sizeof(sechdr->Name));
|
||||
section->name[8] = 0;
|
||||
section->raw_address = sechdr->PointerToRawData;
|
||||
section->raw_size = sechdr->SizeOfRawData;
|
||||
|
@ -928,8 +913,8 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
|
|||
}
|
||||
|
||||
// Allocate storage.
|
||||
xe_xex2_import_info_t *infos = (xe_xex2_import_info_t *)xe_calloc(
|
||||
info_count * sizeof(xe_xex2_import_info_t));
|
||||
xe_xex2_import_info_t *infos = (xe_xex2_import_info_t *)calloc(
|
||||
info_count, sizeof(xe_xex2_import_info_t));
|
||||
assert_not_null(infos);
|
||||
|
||||
assert_not_zero(info_count);
|
||||
|
|
|
@ -24,27 +24,23 @@ namespace kernel {
|
|||
using namespace xe::kernel::fs;
|
||||
|
||||
class X_OBJECT_ATTRIBUTES {
|
||||
public:
|
||||
uint32_t root_directory;
|
||||
uint32_t object_name_ptr;
|
||||
public:
|
||||
uint32_t root_directory;
|
||||
uint32_t object_name_ptr;
|
||||
X_ANSI_STRING object_name;
|
||||
uint32_t attributes;
|
||||
uint32_t attributes;
|
||||
|
||||
X_OBJECT_ATTRIBUTES() {
|
||||
Zero();
|
||||
}
|
||||
X_OBJECT_ATTRIBUTES(const uint8_t* base, uint32_t p) {
|
||||
Read(base, p);
|
||||
}
|
||||
X_OBJECT_ATTRIBUTES() { Zero(); }
|
||||
X_OBJECT_ATTRIBUTES(const uint8_t* base, uint32_t p) { Read(base, 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);
|
||||
if (object_name_ptr) {
|
||||
object_name.Read(base, object_name_ptr);
|
||||
} else {
|
||||
object_name.Zero();
|
||||
}
|
||||
attributes = poly::load_and_swap<uint32_t>(base + p + 8);
|
||||
attributes = poly::load_and_swap<uint32_t>(base + p + 8);
|
||||
}
|
||||
void Zero() {
|
||||
root_directory = 0;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -494,7 +490,7 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state,
|
|||
}
|
||||
}
|
||||
|
||||
xe_free(object_name);
|
||||
free(object_name);
|
||||
SHIM_SET_RETURN_32(result);
|
||||
}
|
||||
|
||||
|
@ -520,23 +516,23 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state,
|
|||
result = X_STATUS_SUCCESS;
|
||||
switch (fs_info_class) {
|
||||
case 1: { // FileFsVolumeInformation
|
||||
auto volume_info = (XVolumeInfo*)xe_calloc(length);
|
||||
auto volume_info = (XVolumeInfo*)calloc(length, 1);
|
||||
result = file->QueryVolume(volume_info, length);
|
||||
if (XSUCCEEDED(result)) {
|
||||
volume_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
||||
info = length;
|
||||
}
|
||||
xe_free(volume_info);
|
||||
free(volume_info);
|
||||
break;
|
||||
}
|
||||
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);
|
||||
if (XSUCCEEDED(result)) {
|
||||
fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr);
|
||||
info = length;
|
||||
}
|
||||
xe_free(fs_attribute_info);
|
||||
free(fs_attribute_info);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -589,7 +585,7 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
|
||||
if (length < 72) {
|
||||
SHIM_SET_RETURN_32(X_STATUS_INFO_LENGTH_MISMATCH);
|
||||
xe_free(file_name);
|
||||
free(file_name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -599,14 +595,14 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
XFile* file = NULL;
|
||||
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
|
||||
if (XSUCCEEDED(result)) {
|
||||
XDirectoryInfo* dir_info = (XDirectoryInfo*)xe_calloc(length);
|
||||
XDirectoryInfo* dir_info = (XDirectoryInfo*)calloc(length, 1);
|
||||
result =
|
||||
file->QueryDirectory(dir_info, length, file_name, restart_scan != 0);
|
||||
if (XSUCCEEDED(result)) {
|
||||
dir_info->Write(SHIM_MEM_BASE, file_info_ptr);
|
||||
info = length;
|
||||
}
|
||||
xe_free(dir_info);
|
||||
free(dir_info);
|
||||
}
|
||||
|
||||
if (XFAILED(result)) {
|
||||
|
@ -621,7 +617,7 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
file->Release();
|
||||
}
|
||||
|
||||
xe_free(file_name);
|
||||
free(file_name);
|
||||
SHIM_SET_RETURN_32(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ SHIM_CALL MmQueryStatistics_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
X_STATUS result = X_STATUS_SUCCESS;
|
||||
|
||||
// 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);
|
||||
|
||||
// Set the constants the game is likely asking for.
|
||||
|
|
|
@ -108,8 +108,8 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state)
|
|||
export_resolver_->SetVariableMapping(
|
||||
"xboxkrnl.exe", ordinals::ExLoadedCommandLine, pExLoadedCommandLine);
|
||||
char command_line[] = "\"default.xex\"";
|
||||
xe_copy_memory(mem + pExLoadedCommandLine, 1024, command_line,
|
||||
poly::countof(command_line) + 1);
|
||||
memcpy(mem + pExLoadedCommandLine, command_line,
|
||||
poly::countof(command_line) + 1);
|
||||
|
||||
// XboxKrnlVersion (8b)
|
||||
// Kernel version, looks like 2b.2b.2b.2b.
|
||||
|
|
|
@ -408,7 +408,7 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
|
||||
// swap the format buffer
|
||||
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) {
|
||||
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);
|
||||
size_t data_length = wcslen(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) {
|
||||
swapped_data[i] = poly::byte_swap(data[i]);
|
||||
}
|
||||
swapped_data[data_length] = '\0';
|
||||
int result = wsprintf(b, local, swapped_data);
|
||||
xe_free(swapped_data);
|
||||
free(swapped_data);
|
||||
b += result;
|
||||
arg_index++;
|
||||
} else {
|
||||
|
@ -607,7 +607,7 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
}
|
||||
*b = '\0';
|
||||
|
||||
xe_free(swapped_format);
|
||||
free(swapped_format);
|
||||
|
||||
// swap the result buffer
|
||||
for (wchar_t* swap = buffer; swap != b; ++swap) {
|
||||
|
|
|
@ -202,15 +202,15 @@ SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim(PPCContext* ppc_state,
|
|||
//(1:17:38 AM) Rick: .text:8201B348 lwz r11, 0x2B10(r31)
|
||||
//(1:17:38 AM) Rick: .text:8201B34C addi r11, r11, 0x3C
|
||||
//(1:17:38 AM) Rick: .text:8201B350 srwi r10, r11, 20 #
|
||||
//r10 = r11 >> 20
|
||||
// r10 = r11 >> 20
|
||||
//(1:17:38 AM) Rick: .text:8201B354 clrlwi r11, r11, 3 #
|
||||
//r11 = r11 & 0x1FFFFFFF
|
||||
// r11 = r11 & 0x1FFFFFFF
|
||||
//(1:17:38 AM) Rick: .text:8201B358 addi r10, r10, 0x200
|
||||
//(1:17:39 AM) Rick: .text:8201B35C rlwinm r10, r10,
|
||||
//0,19,19 # r10 = r10 & 0x1000
|
||||
// 0,19,19 # r10 = r10 & 0x1000
|
||||
//(1:17:39 AM) Rick: .text:8201B360 add r3, r10, r11
|
||||
//(1:17:39 AM) Rick: .text:8201B364 bl
|
||||
//VdEnableRingBufferRPtrWriteBack
|
||||
// VdEnableRingBufferRPtrWriteBack
|
||||
// TODO(benvanik): something?
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
// that we could simulate it, though due to TCR I bet all games need to
|
||||
// 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));
|
||||
dwords[0] = poly::byte_swap((0x03 << 30) | ((1 - 1) << 16) |
|
||||
(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 (flags & MEMORY_FLAG_ZERO) {
|
||||
xe_zero_struct(Translate(result), size);
|
||||
memset(Translate(result), 0, size);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
xe_zero_struct(pv, size);
|
||||
memset(pv, 0, size);
|
||||
}
|
||||
|
||||
return base_address;
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
'export_resolver.h',
|
||||
'logging.cc',
|
||||
'logging.h',
|
||||
'malloc.cc',
|
||||
'malloc.h',
|
||||
'memory.cc',
|
||||
'memory.h',
|
||||
'profiling.cc',
|
||||
|
|
|
@ -266,7 +266,7 @@ public:
|
|||
if (buffer == NULL || length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
auto copy = (char*)xe_calloc(length + 1);
|
||||
auto copy = (char*)calloc(length + 1, sizeof(char));
|
||||
std::strncpy(copy, buffer, length);
|
||||
return copy;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,8 @@ class ThreadState : public alloy::runtime::ThreadState {
|
|||
memset(memory_->Translate(stack_address_), 0, stack_size_);
|
||||
|
||||
// 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);
|
||||
memset(&context_, 0, sizeof(PPCContext));
|
||||
|
||||
// Stash pointers to common structures that callbacks may need.
|
||||
context_->reserve_address = memory_->reserve_address();
|
||||
|
@ -59,7 +58,7 @@ class ThreadState : public alloy::runtime::ThreadState {
|
|||
}
|
||||
~ThreadState() override {
|
||||
runtime_->debugger()->OnThreadDestroyed(this);
|
||||
xe_free_aligned(context_);
|
||||
free(context_);
|
||||
}
|
||||
|
||||
PPCContext* context() const { return context_; }
|
||||
|
|
Loading…
Reference in New Issue