Better handling of title workspace

This commit is contained in:
Gliniak 2022-02-28 14:20:13 +01:00
parent 4bfd3a6506
commit b759cb23a5
3 changed files with 17 additions and 0 deletions

View File

@ -783,8 +783,16 @@ X_STATUS Emulator::CompleteLaunch(const std::filesystem::path& path,
}
// Grab the current title ID.
xex2_opt_execution_info* info = nullptr;
uint32_t workspace_address = 0;
module->GetOptHeader(XEX_HEADER_EXECUTION_INFO, &info);
kernel_state_->memory()
->LookupHeapByType(false, 0x1000)
->Alloc(module->workspace_size(), 0x1000,
kMemoryAllocationReserve | kMemoryAllocationCommit,
kMemoryProtectRead | kMemoryProtectWrite, false,
&workspace_address);
if (!info) {
title_id_ = 0;
} else {

View File

@ -208,6 +208,13 @@ X_STATUS UserModule::LoadContinue() {
// Cache some commonly used headers...
this->xex_module()->GetOptHeader(XEX_HEADER_ENTRY_POINT, &entry_point_);
this->xex_module()->GetOptHeader(XEX_HEADER_DEFAULT_STACK_SIZE, &stack_size_);
xe::be<uint32_t>* ws_size = 0;
this->xex_module()->GetOptHeader(XEX_HEADER_TITLE_WORKSPACE_SIZE, &ws_size);
// ToDo: Find better way to handle default and mimimal values!
if (ws_size && *ws_size) {
workspace_size_ = std::max(ws_size->get(), uint32_t(256 * 1024));
}
is_dll_module_ = !!(header->module_flags & XEX_MODULE_DLL_MODULE);
// Setup the loader data entry

View File

@ -67,6 +67,7 @@ class UserModule : public XModule {
uint32_t entry_point() const { return entry_point_; }
uint32_t stack_size() const { return stack_size_; }
uint32_t workspace_size() const { return workspace_size_; }
X_STATUS LoadFromFile(const std::string_view path);
X_STATUS LoadFromMemory(const void* addr, const size_t length);
@ -113,6 +114,7 @@ class UserModule : public XModule {
bool is_dll_module_ = false;
uint32_t entry_point_ = 0;
uint32_t stack_size_ = 0;
uint32_t workspace_size_ = 384*1024;
};
} // namespace kernel