Merge pull request #300 from DrChat/hmodule_fix
Swap to using HMODULE instead of handles for xex modules.
This commit is contained in:
@@ -22,14 +22,9 @@ namespace kernel {
|
||||
using namespace xe::cpu;
|
||||
|
||||
XUserModule::XUserModule(KernelState* kernel_state, const char* path)
|
||||
: XModule(kernel_state, ModuleType::kUserModule, path),
|
||||
xex_(nullptr),
|
||||
execution_info_ptr_(0) {}
|
||||
: XModule(kernel_state, ModuleType::kUserModule, path), xex_(nullptr) {}
|
||||
|
||||
XUserModule::~XUserModule() {
|
||||
kernel_state()->memory()->SystemHeapFree(execution_info_ptr_);
|
||||
xe_xex2_dealloc(xex_);
|
||||
}
|
||||
XUserModule::~XUserModule() { xe_xex2_dealloc(xex_); }
|
||||
|
||||
xe_xex2_ref XUserModule::xex() { return xex_; }
|
||||
|
||||
@@ -94,20 +89,21 @@ X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) {
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
// Store execution info for later use.
|
||||
// TODO(benvanik): just put entire xex header in memory somewhere?
|
||||
execution_info_ptr_ = memory()->SystemHeapAlloc(24);
|
||||
auto eip = memory()->TranslateVirtual(execution_info_ptr_);
|
||||
const auto& ex = xe_xex2_get_header(xex_)->execution_info;
|
||||
xe::store_and_swap<uint32_t>(eip + 0x00, ex.media_id);
|
||||
xe::store_and_swap<uint32_t>(eip + 0x04, ex.version.value);
|
||||
xe::store_and_swap<uint32_t>(eip + 0x08, ex.base_version.value);
|
||||
xe::store_and_swap<uint32_t>(eip + 0x0C, ex.title_id);
|
||||
xe::store_and_swap<uint8_t>(eip + 0x10, ex.platform);
|
||||
xe::store_and_swap<uint8_t>(eip + 0x11, ex.executable_table);
|
||||
xe::store_and_swap<uint8_t>(eip + 0x12, ex.disc_number);
|
||||
xe::store_and_swap<uint8_t>(eip + 0x13, ex.disc_count);
|
||||
xe::store_and_swap<uint32_t>(eip + 0x14, ex.savegame_id);
|
||||
// Copy the xex2 header into guest memory
|
||||
const xex2_header* header = reinterpret_cast<const xex2_header*>(addr);
|
||||
uint32_t header_size = xex2_get_header_size(header);
|
||||
|
||||
xex_header_ = memory()->SystemHeapAlloc(header_size);
|
||||
|
||||
uint8_t* xex_header_ptr = memory()->TranslateVirtual(xex_header_);
|
||||
std::memcpy(xex_header_ptr, header, header_size);
|
||||
|
||||
// Setup the loader data entry
|
||||
auto ldr_data =
|
||||
memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(hmodule_ptr_);
|
||||
|
||||
ldr_data->dll_base = 0; // GetProcAddress will read this.
|
||||
ldr_data->xex_header_base = xex_header_;
|
||||
|
||||
// Prepare the module for execution.
|
||||
// Runtime takes ownership.
|
||||
@@ -148,6 +144,24 @@ X_STATUS XUserModule::GetSection(const char* name, uint32_t* out_section_data,
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
X_STATUS XUserModule::GetOptHeader(xe_xex2_header_keys key,
|
||||
uint32_t* out_header_guest_ptr) {
|
||||
assert_not_null(out_header_guest_ptr);
|
||||
|
||||
auto header = memory()->TranslateVirtual<xex2_header*>(xex_header_);
|
||||
if (!header) {
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
auto ptr = xex2_get_opt_header(header, key);
|
||||
if (!ptr) {
|
||||
return X_STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
*out_header_guest_ptr = (uint32_t)(ptr - memory()->virtual_membase());
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
X_STATUS XUserModule::Launch(uint32_t flags) {
|
||||
const xe_xex2_header_t* header = xex_header();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user