Removing xenia/malloc.*
Using standard memory functions now.
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user