In-progress work: refactoring PAL not to be instanced.
This removes a lot of useless passing around of the PAL object.
This commit is contained in:
@@ -15,18 +15,12 @@ using namespace xe::kernel;
|
||||
using namespace xe::kernel::fs;
|
||||
|
||||
|
||||
Device::Device(xe_pal_ref pal, const char* path) {
|
||||
pal_ = xe_pal_retain(pal);
|
||||
Device::Device(const char* path) {
|
||||
path_ = xestrdupa(path);
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
xe_free(path_);
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
xe_pal_ref Device::pal() {
|
||||
return xe_pal_retain(pal_);
|
||||
}
|
||||
|
||||
const char* Device::path() {
|
||||
|
||||
@@ -23,16 +23,14 @@ namespace fs {
|
||||
|
||||
class Device {
|
||||
public:
|
||||
Device(xe_pal_ref pal, const char* path);
|
||||
Device(const char* path);
|
||||
virtual ~Device();
|
||||
|
||||
xe_pal_ref pal();
|
||||
const char* path();
|
||||
|
||||
virtual Entry* ResolvePath(const char* path) = 0;
|
||||
|
||||
protected:
|
||||
xe_pal_ref pal_;
|
||||
char* path_;
|
||||
};
|
||||
|
||||
|
||||
@@ -74,9 +74,8 @@ private:
|
||||
}
|
||||
|
||||
|
||||
DiscImageDevice::DiscImageDevice(xe_pal_ref pal, const char* path,
|
||||
const xechar_t* local_path) :
|
||||
Device(pal, path) {
|
||||
DiscImageDevice::DiscImageDevice(const char* path, const xechar_t* local_path) :
|
||||
Device(path) {
|
||||
local_path_ = xestrdup(local_path);
|
||||
mmap_ = NULL;
|
||||
gdfx_ = NULL;
|
||||
@@ -89,7 +88,7 @@ DiscImageDevice::~DiscImageDevice() {
|
||||
}
|
||||
|
||||
int DiscImageDevice::Init() {
|
||||
mmap_ = xe_mmap_open(pal_, kXEFileModeRead, local_path_, 0, 0);
|
||||
mmap_ = xe_mmap_open(kXEFileModeRead, local_path_, 0, 0);
|
||||
if (!mmap_) {
|
||||
XELOGE("Disc image could not be mapped");
|
||||
return 1;
|
||||
|
||||
@@ -26,7 +26,7 @@ class GDFX;
|
||||
|
||||
class DiscImageDevice : public Device {
|
||||
public:
|
||||
DiscImageDevice(xe_pal_ref pal, const char* path, const xechar_t* local_path);
|
||||
DiscImageDevice(const char* path, const xechar_t* local_path);
|
||||
virtual ~DiscImageDevice();
|
||||
|
||||
int Init();
|
||||
|
||||
@@ -46,10 +46,7 @@ public:
|
||||
|
||||
virtual MemoryMapping* CreateMemoryMapping(
|
||||
xe_file_mode file_mode, const size_t offset, const size_t length) {
|
||||
xe_pal_ref pal = device()->pal();
|
||||
xe_mmap_ref mmap = xe_mmap_open(pal, file_mode, local_path_,
|
||||
offset, length);
|
||||
xe_pal_release(pal);
|
||||
xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length);
|
||||
if (!mmap) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -70,9 +67,9 @@ private:
|
||||
}
|
||||
|
||||
|
||||
LocalDirectoryDevice::LocalDirectoryDevice(xe_pal_ref pal, const char* path,
|
||||
LocalDirectoryDevice::LocalDirectoryDevice(const char* path,
|
||||
const xechar_t* local_path) :
|
||||
Device(pal, path) {
|
||||
Device(path) {
|
||||
local_path_ = xestrdup(local_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace fs {
|
||||
|
||||
class LocalDirectoryDevice : public Device {
|
||||
public:
|
||||
LocalDirectoryDevice(xe_pal_ref pal, const char* path,
|
||||
const xechar_t* local_path);
|
||||
LocalDirectoryDevice(const char* path, const xechar_t* local_path);
|
||||
virtual ~LocalDirectoryDevice();
|
||||
|
||||
virtual Entry* ResolvePath(const char* path);
|
||||
|
||||
@@ -18,8 +18,7 @@ using namespace xe::kernel;
|
||||
using namespace xe::kernel::fs;
|
||||
|
||||
|
||||
FileSystem::FileSystem(xe_pal_ref pal) {
|
||||
pal_ = xe_pal_retain(pal);
|
||||
FileSystem::FileSystem() {
|
||||
}
|
||||
|
||||
FileSystem::~FileSystem() {
|
||||
@@ -31,8 +30,6 @@ FileSystem::~FileSystem() {
|
||||
}
|
||||
devices_.clear();
|
||||
symlinks_.clear();
|
||||
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
int FileSystem::RegisterDevice(const char* path, Device* device) {
|
||||
@@ -42,13 +39,13 @@ int FileSystem::RegisterDevice(const char* path, Device* device) {
|
||||
|
||||
int FileSystem::RegisterLocalDirectoryDevice(
|
||||
const char* path, const xechar_t* local_path) {
|
||||
Device* device = new LocalDirectoryDevice(pal_, path, local_path);
|
||||
Device* device = new LocalDirectoryDevice(path, local_path);
|
||||
return RegisterDevice(path, device);
|
||||
}
|
||||
|
||||
int FileSystem::RegisterDiscImageDevice(
|
||||
const char* path, const xechar_t* local_path) {
|
||||
DiscImageDevice* device = new DiscImageDevice(pal_, path, local_path);
|
||||
DiscImageDevice* device = new DiscImageDevice(path, local_path);
|
||||
if (device->Init()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Device;
|
||||
|
||||
class FileSystem {
|
||||
public:
|
||||
FileSystem(xe_pal_ref pal);
|
||||
FileSystem();
|
||||
~FileSystem();
|
||||
|
||||
int RegisterDevice(const char* path, Device* device);
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
Entry* ResolvePath(const char* path);
|
||||
|
||||
private:
|
||||
xe_pal_ref pal_;
|
||||
std::vector<Device*> devices_;
|
||||
std::tr1::unordered_map<std::string, std::string> symlinks_;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@ class KernelModule {
|
||||
public:
|
||||
KernelModule(Runtime* runtime) {
|
||||
runtime_ = runtime;
|
||||
pal_ = runtime->pal();
|
||||
memory_ = runtime->memory();
|
||||
export_resolver_ = runtime->export_resolver();
|
||||
}
|
||||
@@ -36,12 +35,10 @@ public:
|
||||
virtual ~KernelModule() {
|
||||
export_resolver_.reset();
|
||||
xe_memory_release(memory_);
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
protected:
|
||||
Runtime* runtime_;
|
||||
xe_pal_ref pal_;
|
||||
xe_memory_ref memory_;
|
||||
shared_ptr<ExportResolver> export_resolver_;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ XamModule::XamModule(Runtime* runtime) :
|
||||
"xam.xex", xam_export_table, XECOUNT(xam_export_table));
|
||||
|
||||
// Setup the xam state instance.
|
||||
xam_state = auto_ptr<XamState>(new XamState(pal_, memory_, export_resolver_));
|
||||
xam_state = auto_ptr<XamState>(new XamState(memory_, export_resolver_));
|
||||
|
||||
// Register all exported functions.
|
||||
RegisterInfoExports(export_resolver_.get(), xam_state.get());
|
||||
|
||||
@@ -20,14 +20,12 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
XamState::XamState(xe_pal_ref pal, xe_memory_ref memory,
|
||||
XamState::XamState(xe_memory_ref memory,
|
||||
shared_ptr<ExportResolver> export_resolver) {
|
||||
this->pal = xe_pal_retain(pal);
|
||||
this->memory = xe_memory_retain(memory);
|
||||
export_resolver_ = export_resolver;
|
||||
}
|
||||
|
||||
XamState::~XamState() {
|
||||
xe_memory_release(memory);
|
||||
xe_pal_release(pal);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,9 @@ namespace xam {
|
||||
|
||||
class XamState {
|
||||
public:
|
||||
XamState(xe_pal_ref pal, xe_memory_ref memory,
|
||||
shared_ptr<ExportResolver> export_resolver);
|
||||
XamState(xe_memory_ref memory, shared_ptr<ExportResolver> export_resolver);
|
||||
~XamState();
|
||||
|
||||
xe_pal_ref pal;
|
||||
xe_memory_ref memory;
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,7 +28,6 @@ KernelState::KernelState(Runtime* runtime) :
|
||||
runtime_(runtime),
|
||||
executable_module_(NULL),
|
||||
next_handle_(0) {
|
||||
pal_ = runtime->pal();
|
||||
memory_ = runtime->memory();
|
||||
processor_ = runtime->processor();
|
||||
filesystem_ = runtime->filesystem();
|
||||
@@ -69,17 +68,12 @@ KernelState::~KernelState() {
|
||||
filesystem_.reset();
|
||||
processor_.reset();
|
||||
xe_memory_release(memory_);
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
Runtime* KernelState::runtime() {
|
||||
return runtime_;
|
||||
}
|
||||
|
||||
xe_pal_ref KernelState::pal() {
|
||||
return pal_;
|
||||
}
|
||||
|
||||
xe_memory_ref KernelState::memory() {
|
||||
return memory_;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public:
|
||||
~KernelState();
|
||||
|
||||
Runtime* runtime();
|
||||
xe_pal_ref pal();
|
||||
xe_memory_ref memory();
|
||||
cpu::Processor* processor();
|
||||
fs::FileSystem* filesystem();
|
||||
@@ -51,7 +50,6 @@ private:
|
||||
void RemoveObject(XObject* obj);
|
||||
|
||||
Runtime* runtime_;
|
||||
xe_pal_ref pal_;
|
||||
xe_memory_ref memory_;
|
||||
shared_ptr<cpu::Processor> processor_;
|
||||
shared_ptr<fs::FileSystem> filesystem_;
|
||||
|
||||
@@ -92,8 +92,7 @@ X_STATUS XModule::LoadFromMemory(const void* addr, const size_t length) {
|
||||
XEEXPECTNOTNULL(xex_);
|
||||
|
||||
// Prepare the module for execution.
|
||||
XEEXPECTZERO(kernel_state()->processor()->PrepareModule(
|
||||
name_, path_, xex_, runtime()->export_resolver()));
|
||||
XEEXPECTZERO(kernel_state()->processor()->LoadXexModule(name_, path_, xex_));
|
||||
|
||||
return X_STATUS_SUCCESS;
|
||||
|
||||
|
||||
@@ -18,15 +18,14 @@ using namespace xe::kernel;
|
||||
using namespace xe::kernel::fs;
|
||||
|
||||
|
||||
Runtime::Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor,
|
||||
Runtime::Runtime(shared_ptr<cpu::Processor> processor,
|
||||
const xechar_t* command_line) {
|
||||
pal_ = xe_pal_retain(pal);
|
||||
memory_ = processor->memory();
|
||||
processor_ = processor;
|
||||
XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line));
|
||||
export_resolver_ = shared_ptr<ExportResolver>(new ExportResolver());
|
||||
|
||||
filesystem_ = shared_ptr<FileSystem>(new FileSystem(pal_));
|
||||
filesystem_ = shared_ptr<FileSystem>(new FileSystem());
|
||||
|
||||
xboxkrnl_ = auto_ptr<xboxkrnl::XboxkrnlModule>(
|
||||
new xboxkrnl::XboxkrnlModule(this));
|
||||
@@ -36,17 +35,12 @@ Runtime::Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor,
|
||||
|
||||
Runtime::~Runtime() {
|
||||
xe_memory_release(memory_);
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
const xechar_t* Runtime::command_line() {
|
||||
return command_line_;
|
||||
}
|
||||
|
||||
xe_pal_ref Runtime::pal() {
|
||||
return xe_pal_retain(pal_);
|
||||
}
|
||||
|
||||
xe_memory_ref Runtime::memory() {
|
||||
return xe_memory_retain(memory_);
|
||||
}
|
||||
|
||||
@@ -42,13 +42,11 @@ class KernelModule;
|
||||
|
||||
class Runtime {
|
||||
public:
|
||||
Runtime(xe_pal_ref pal, shared_ptr<cpu::Processor> processor,
|
||||
const xechar_t* command_line);
|
||||
Runtime(shared_ptr<cpu::Processor> processor, const xechar_t* command_line);
|
||||
~Runtime();
|
||||
|
||||
const xechar_t* command_line();
|
||||
|
||||
xe_pal_ref pal();
|
||||
xe_memory_ref memory();
|
||||
shared_ptr<cpu::Processor> processor();
|
||||
shared_ptr<ExportResolver> export_resolver();
|
||||
@@ -60,7 +58,6 @@ public:
|
||||
private:
|
||||
xechar_t command_line_[XE_MAX_PATH];
|
||||
|
||||
xe_pal_ref pal_;
|
||||
xe_memory_ref memory_;
|
||||
shared_ptr<cpu::Processor> processor_;
|
||||
shared_ptr<ExportResolver> export_resolver_;
|
||||
|
||||
Reference in New Issue
Block a user