Allow unloading of user modules

This commit is contained in:
Dr. Chat
2015-07-05 14:03:00 -05:00
parent 8210ada448
commit 7f53b1d630
4 changed files with 39 additions and 2 deletions

View File

@@ -41,11 +41,19 @@ XexModule::XexModule(Processor* processor, KernelState* kernel_state)
processor_(processor),
kernel_state_(kernel_state),
xex_(nullptr),
xex_header_(nullptr),
base_address_(0),
low_address_(0),
high_address_(0) {}
XexModule::~XexModule() { xe_xex2_dealloc(xex_); }
XexModule::~XexModule() {
xe_xex2_dealloc(xex_);
if (xex_header_) {
delete[] xex_header_;
xex_header_ = nullptr;
}
}
bool XexModule::GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
void** out_ptr) {
@@ -287,6 +295,21 @@ bool XexModule::Load(const std::string& name, const std::string& path,
return true;
}
bool XexModule::Unload() {
// Just deallocate the memory occupied by the exe
uint32_t exe_address = 0;
GetOptHeader(XEX_HEADER_IMAGE_BASE_ADDRESS, &exe_address);
assert_not_zero(exe_address);
memory()->LookupHeap(exe_address)->Release(exe_address);
assert_not_null(xex_header_); // Unloading a module that wasn't loaded?
delete[] xex_header_;
xex_header_ = nullptr;
return true;
}
bool XexModule::SetupLibraryImports(const char* name,
const xex2_import_library* library) {
ExportResolver* kernel_resolver = nullptr;