From 4fabd20980429976884c0080707d715e241b8e2f Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 1 Nov 2014 11:42:44 -0700 Subject: [PATCH] Better process type emulation. --- src/xenia/kernel/kernel_state.cc | 1 + src/xenia/kernel/kernel_state.h | 4 ++++ src/xenia/kernel/xboxkrnl_threading.cc | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index d423c4b7e..c6fad30db 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -34,6 +34,7 @@ KernelState::KernelState(Emulator* emulator) : emulator_(emulator), memory_(emulator->memory()), has_notified_startup_(false), + process_type_(X_PROCTYPE_USER), executable_module_(nullptr) { processor_ = emulator->processor(); file_system_ = emulator->file_system(); diff --git a/src/xenia/kernel/kernel_state.h b/src/xenia/kernel/kernel_state.h index 72899d936..c590b0da6 100644 --- a/src/xenia/kernel/kernel_state.h +++ b/src/xenia/kernel/kernel_state.h @@ -59,6 +59,9 @@ class KernelState { ObjectTable* object_table() const { return object_table_; } std::mutex& object_mutex() { return object_mutex_; } + uint32_t process_type() const { return process_type_; } + void set_process_type(uint32_t value) { process_type_ = value; } + void RegisterModule(XModule* module); void UnregisterModule(XModule* module); XModule* GetModule(const char* name); @@ -95,6 +98,7 @@ class KernelState { std::vector notify_listeners_; bool has_notified_startup_; + uint32_t process_type_; XUserModule* executable_module_; friend class XObject; diff --git a/src/xenia/kernel/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl_threading.cc index 167996dc6..4a7805f13 100644 --- a/src/xenia/kernel/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl_threading.cc @@ -242,8 +242,19 @@ SHIM_CALL KeGetCurrentProcessType_shim(PPCContext* ppc_state, // DWORD - int result = X_PROCTYPE_USER; - SHIM_SET_RETURN_64(result); + SHIM_SET_RETURN_64(state->process_type()); +} + +SHIM_CALL KeSetCurrentProcessType_shim(PPCContext* ppc_state, + KernelState* state) { + uint32_t type = SHIM_GET_ARG_32(0); + // One of X_PROCTYPE_? + + XELOGD("KeSetCurrentProcessType(%d)", type); + + assert_true(type >= 0 && type <= 2); + + state->set_process_type(type); } SHIM_CALL KeQueryPerformanceFrequency_shim(PPCContext* ppc_state, @@ -1232,6 +1243,7 @@ void xe::kernel::xboxkrnl::RegisterThreadingExports( SHIM_SET_MAPPING("xboxkrnl.exe", KeSetBasePriorityThread, state); SHIM_SET_MAPPING("xboxkrnl.exe", KeGetCurrentProcessType, state); + SHIM_SET_MAPPING("xboxkrnl.exe", KeSetCurrentProcessType, state); SHIM_SET_MAPPING("xboxkrnl.exe", KeQueryPerformanceFrequency, state); SHIM_SET_MAPPING("xboxkrnl.exe", KeDelayExecutionThread, state);