From 84e884a07f795e30e6c84416480c05c4bbe206cf Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 28 Jun 2015 14:01:53 -0700 Subject: [PATCH] Moving get_opt_header out of xex2. --- src/xenia/kernel/objects/xuser_module.cc | 41 ++++++++++++++++++++---- src/xenia/kernel/objects/xuser_module.h | 4 +++ src/xenia/kernel/util/xex2.cc | 25 --------------- src/xenia/kernel/util/xex2.h | 2 -- src/xenia/kernel/xboxkrnl_rtl.cc | 5 +-- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/xenia/kernel/objects/xuser_module.cc b/src/xenia/kernel/objects/xuser_module.cc index 4517a4caf..779502524 100644 --- a/src/xenia/kernel/objects/xuser_module.cc +++ b/src/xenia/kernel/objects/xuser_module.cc @@ -146,20 +146,47 @@ X_STATUS XUserModule::GetSection(const char* name, uint32_t* out_section_data, 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(xex_header_); if (!header) { return X_STATUS_UNSUCCESSFUL; } + return GetOptHeader(memory()->virtual_membase(), header, key, + out_header_guest_ptr); +} - uint32_t field_value = - xex2_get_opt_header(memory()->virtual_membase(), header, key); - if (!field_value) { +X_STATUS XUserModule::GetOptHeader(uint8_t* membase, const xex2_header* header, + xe_xex2_header_keys key, + uint32_t* out_header_guest_ptr) { + assert_not_null(out_header_guest_ptr); + uint32_t field_value = 0; + bool field_found = false; + for (uint32_t i = 0; i < header->header_count; i++) { + auto& opt_header = header->headers[i]; + if (opt_header.key != key) { + continue; + } + field_found = true; + switch (opt_header.key & 0xFF) { + case 0x00: + // Return data stored in header value. + field_value = opt_header.value; + break; + case 0x01: + // Return pointer to data stored in header value. + field_value = uint32_t((uint8_t*)&opt_header.value - membase); + break; + default: + // Data stored at offset to header. + field_value = uint32_t((uint8_t*)&header->headers[0] - membase) + + opt_header.offset; + break; + } + break; + } + *out_header_guest_ptr = field_value; + if (!field_found) { return X_STATUS_NOT_FOUND; } - - *out_header_guest_ptr = field_value; return X_STATUS_SUCCESS; } diff --git a/src/xenia/kernel/objects/xuser_module.h b/src/xenia/kernel/objects/xuser_module.h index 74dc1c47b..18e2156ea 100644 --- a/src/xenia/kernel/objects/xuser_module.h +++ b/src/xenia/kernel/objects/xuser_module.h @@ -35,8 +35,12 @@ class XUserModule : public XModule { uint32_t GetProcAddressByName(const char* name) override; X_STATUS GetSection(const char* name, uint32_t* out_section_data, uint32_t* out_section_size) override; + X_STATUS GetOptHeader(xe_xex2_header_keys key, uint32_t* out_header_guest_ptr); + static X_STATUS GetOptHeader(uint8_t* membase, const xex2_header* header, + xe_xex2_header_keys key, + uint32_t* out_header_guest_ptr); X_STATUS Launch(uint32_t flags); diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index 8b4c4fba1..b7c8c13ce 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -29,31 +29,6 @@ namespace xe { namespace kernel { -uint32_t xex2_get_opt_header(uint8_t *membase, const xex2_header *header, - uint32_t key) { - for (uint32_t i = 0; i < header->header_count; i++) { - const xex2_opt_header &opt_header = header->headers[i]; - if (opt_header.key != key) { - continue; - } - - switch (opt_header.key & 0xFF) { - case 0x00: - // Return data stored in header value. - return opt_header.value; - case 0x01: - // Return pointer to data stored in header value. - return uint32_t((uint8_t *)&opt_header.value - membase); - default: - // Data stored at offset to header. - return uint32_t((uint8_t *)&header->headers[0] - membase) + - opt_header.offset; - } - } - - return 0; -} - uint32_t xex2_get_header_size(const xex2_header *header) { return header->exe_offset; } diff --git a/src/xenia/kernel/util/xex2.h b/src/xenia/kernel/util/xex2.h index b91524798..85a674b95 100644 --- a/src/xenia/kernel/util/xex2.h +++ b/src/xenia/kernel/util/xex2.h @@ -15,8 +15,6 @@ namespace xe { namespace kernel { -uint32_t xex2_get_opt_header(uint8_t* membase, const xex2_header* header, - uint32_t key); uint32_t xex2_get_header_size(const xex2_header* header); } // namespace kernel } // namespace xe diff --git a/src/xenia/kernel/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl_rtl.cc index 7184090de..d11d973eb 100644 --- a/src/xenia/kernel/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl_rtl.cc @@ -394,8 +394,9 @@ SHIM_CALL RtlImageXexHeaderField_shim(PPCContext* ppc_context, return; } - uint32_t field_value = - xex2_get_opt_header(SHIM_MEM_BASE, header, image_field); + uint32_t field_value = 0; + XUserModule::GetOptHeader(SHIM_MEM_BASE, header, + xe_xex2_header_keys(image_field), &field_value); SHIM_SET_RETURN_32(field_value); }