From bebda48a4f18b96fbd3564aadbd7547487b12abe Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 19 Jul 2015 20:46:14 -0700 Subject: [PATCH] More clang fixes. --- src/xenia/kernel/kernel_state.cc | 11 ++- src/xenia/kernel/objects/xkernel_module.cc | 16 ++--- src/xenia/kernel/objects/xthread.cc | 9 +-- src/xenia/kernel/objects/xthread.h | 26 +++---- src/xenia/kernel/objects/xtimer.cc | 2 - src/xenia/kernel/util/shim_utils.h | 83 +++++++++++----------- src/xenia/kernel/xam_module.cc | 16 ++--- src/xenia/kernel/xam_private.h | 2 +- src/xenia/kernel/xam_user.cc | 3 +- src/xenia/kernel/xboxkrnl_module.cc | 16 ++--- src/xenia/kernel/xboxkrnl_private.h | 2 +- src/xenia/kernel/xboxkrnl_threading.cc | 5 +- 12 files changed, 89 insertions(+), 102 deletions(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index d1ceee543..9778f8696 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -224,12 +224,12 @@ void KernelState::SetExecutableModule(object_ref module) { } // Setup the kernel's XexExecutableModuleHandle field. - auto export = processor()->export_resolver()->GetExportByOrdinal( + auto export_entry = processor()->export_resolver()->GetExportByOrdinal( "xboxkrnl.exe", ordinals::XexExecutableModuleHandle); - if (export) { - assert_not_zero(export->variable_ptr); - auto variable_ptr = - memory()->TranslateVirtual*>(export->variable_ptr); + if (export_entry) { + assert_not_zero(export_entry->variable_ptr); + auto variable_ptr = memory()->TranslateVirtual*>( + export_entry->variable_ptr); *variable_ptr = executable_module_->hmodule_ptr(); } @@ -548,7 +548,6 @@ void KernelState::CompleteOverlappedDeferredEx( xe::threading::Sleep( std::chrono::milliseconds::duration(kDeferredOverlappedDelayMillis)); completion_callback(); - auto ptr = memory()->TranslateVirtual(overlapped_ptr); CompleteOverlappedEx(overlapped_ptr, result, extended_error, length); }); dispatch_cond_.notify_all(); diff --git a/src/xenia/kernel/objects/xkernel_module.cc b/src/xenia/kernel/objects/xkernel_module.cc index 2f436841c..7c313cc91 100644 --- a/src/xenia/kernel/objects/xkernel_module.cc +++ b/src/xenia/kernel/objects/xkernel_module.cc @@ -28,23 +28,23 @@ XKernelModule::XKernelModule(KernelState* kernel_state, const char* path) XKernelModule::~XKernelModule() {} uint32_t XKernelModule::GetProcAddressByOrdinal(uint16_t ordinal) { - auto export = export_resolver_->GetExportByOrdinal(name(), ordinal); - if (!export) { + auto export_entry = export_resolver_->GetExportByOrdinal(name(), ordinal); + if (!export_entry) { // Export (or its parent library) not found. return 0; } - if (export->type == cpu::Export::Type::kVariable) { - if (export->variable_ptr) { - return export->variable_ptr; + if (export_entry->type == cpu::Export::Type::kVariable) { + if (export_entry->variable_ptr) { + return export_entry->variable_ptr; } else { XELOGW( "ERROR: var export referenced GetProcAddressByOrdinal(%.4X(%s)) is " "not implemented", - ordinal, export->name); + ordinal, export_entry->name); return 0; } } else { - if (export->function_data.shim) { + if (export_entry->function_data.shim) { // Implemented. Dynamically generate trampoline. XELOGE("GetProcAddressByOrdinal not implemented"); return 0; @@ -53,7 +53,7 @@ uint32_t XKernelModule::GetProcAddressByOrdinal(uint16_t ordinal) { XELOGW( "ERROR: fn export referenced GetProcAddressByOrdinal(%.4X(%s)) is " "not implemented", - ordinal, export->name); + ordinal, export_entry->name); return 0; } } diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 61e864671..f470583b7 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -45,14 +45,7 @@ XThread::XThread(KernelState* kernel_state, uint32_t stack_size, bool guest_thread) : XObject(kernel_state, kTypeThread), thread_id_(++next_xthread_id), - pcr_address_(0), - thread_state_address_(0), - thread_state_(0), - priority_(0), - affinity_(0), - irql_(0), - guest_thread_(guest_thread), - running_(false) { + guest_thread_(guest_thread) { creation_params_.stack_size = stack_size; creation_params_.xapi_thread_startup = xapi_thread_startup; creation_params_.start_address = start_address; diff --git a/src/xenia/kernel/objects/xthread.h b/src/xenia/kernel/objects/xthread.h index 1365a3091..d67195f29 100644 --- a/src/xenia/kernel/objects/xthread.h +++ b/src/xenia/kernel/objects/xthread.h @@ -141,27 +141,27 @@ class XThread : public XObject { uint32_t start_address; uint32_t start_context; uint32_t creation_flags; - } creation_params_; + } creation_params_ = {0}; - uint32_t thread_id_; + uint32_t thread_id_ = 0; std::unique_ptr thread_; - uint32_t scratch_address_; - uint32_t scratch_size_; - uint32_t tls_address_; - uint32_t pcr_address_; - uint32_t thread_state_address_; - cpu::ThreadState* thread_state_; - bool guest_thread_; // Launched into guest code? - bool running_; + uint32_t scratch_address_ = 0; + uint32_t scratch_size_ = 0; + uint32_t tls_address_ = 0; + uint32_t pcr_address_ = 0; + uint32_t thread_state_address_ = 0; + cpu::ThreadState* thread_state_ = nullptr; + bool guest_thread_ = false; // Launched into guest code. + bool running_ = false; std::string name_; - int32_t priority_; - uint32_t affinity_; + int32_t priority_ = 0; + uint32_t affinity_ = 0; std::atomic irql_; xe::mutex apc_lock_; - NativeList* apc_list_; + NativeList* apc_list_ = nullptr; }; class XHostThread : public XThread { diff --git a/src/xenia/kernel/objects/xtimer.cc b/src/xenia/kernel/objects/xtimer.cc index b16ac4c9b..84e59a131 100644 --- a/src/xenia/kernel/objects/xtimer.cc +++ b/src/xenia/kernel/objects/xtimer.cc @@ -22,8 +22,6 @@ XTimer::~XTimer() = default; void XTimer::Initialize(uint32_t timer_type) { assert_false(timer_); - - bool manual_reset = false; switch (timer_type) { case 0: // NotificationTimer timer_ = xe::threading::Timer::CreateManualResetTimer(); diff --git a/src/xenia/kernel/util/shim_utils.h b/src/xenia/kernel/util/shim_utils.h index f0629e057..d7f733cc5 100644 --- a/src/xenia/kernel/util/shim_utils.h +++ b/src/xenia/kernel/util/shim_utils.h @@ -107,41 +107,40 @@ class Param { Param() : ordinal_(-1) {} explicit Param(Init& init) : ordinal_(--init.ordinal) {} + template + void LoadValue(Init& init, V* out_value) { + if (ordinal_ <= 7) { + *out_value = V(init.ppc_context->r[3 + ordinal_]); + } else { + uint32_t stack_ptr = + uint32_t(init.ppc_context->r[1]) + 0x54 + (ordinal_ - 7) * 8; + *out_value = + xe::load_and_swap(init.ppc_context->virtual_membase + stack_ptr); + } + } + int ordinal_; }; +template <> +inline void Param::LoadValue(Param::Init& init, float* out_value) { + *out_value = float(init.ppc_context->f[1 + ++init.float_ordinal]); +} +template <> +inline void Param::LoadValue(Param::Init& init, double* out_value) { + *out_value = init.ppc_context->f[1 + ++init.float_ordinal]; +} template class ParamBase : public Param { public: ParamBase() : Param(), value_(0) {} ParamBase(T value) : Param(), value_(value) {} - ParamBase(Init& init) : Param(init) { LoadValue(init); } + ParamBase(Init& init) : Param(init) { LoadValue(init, &value_); } ParamBase& operator=(const T& other) { value_ = other; return *this; } operator T() const { return value_; } - private: - template - void LoadValue(Init& init) { - if (ordinal_ <= 7) { - value_ = V(init.ppc_context->r[3 + ordinal_]); - } else { - uint32_t stack_ptr = - uint32_t(init.ppc_context->r[1]) + 0x54 + (ordinal_ - 7) * 8; - value_ = - xe::load_and_swap(init.ppc_context->virtual_membase + stack_ptr); - } - } - template <> - void LoadValue(Init& init) { - value_ = init.ppc_context->f[1 + ++init.float_ordinal]; - } - template <> - void LoadValue(Init& init) { - value_ = init.ppc_context->f[1 + ++init.float_ordinal]; - } - protected: T value_; }; @@ -365,34 +364,34 @@ enum class KernelModuleId { template typename std::enable_if::type AppendKernelCallParams( - StringBuffer& string_buffer, xe::cpu::Export* export, + StringBuffer& string_buffer, xe::cpu::Export* export_entry, const std::tuple&) {} template typename std::enable_if < I::type AppendKernelCallParams( - StringBuffer& string_buffer, xe::cpu::Export* export, + StringBuffer& string_buffer, xe::cpu::Export* export_entry, const std::tuple& params) { if (I) { string_buffer.Append(", "); } auto param = std::get(params); AppendParam(string_buffer, param); - AppendKernelCallParams(string_buffer, export, params); + AppendKernelCallParams(string_buffer, export_entry, params); } StringBuffer* thread_local_string_buffer(); template -void PrintKernelCall(cpu::Export* export, const Tuple& params) { +void PrintKernelCall(cpu::Export* export_entry, const Tuple& params) { auto& string_buffer = *thread_local_string_buffer(); string_buffer.Reset(); - string_buffer.Append(export->name); + string_buffer.Append(export_entry->name); string_buffer.Append('('); - AppendKernelCallParams(string_buffer, export, params); + AppendKernelCallParams(string_buffer, export_entry, params); string_buffer.Append(')'); auto str = string_buffer.GetString(); - if (export->tags & ExportTag::kImportant) { + if (export_entry->tags & ExportTag::kImportant) { XELOGI(str); } else { XELOGD(str); @@ -407,56 +406,56 @@ auto KernelTrampoline(F&& f, Tuple&& t, std::index_sequence) { template xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name, xe::cpu::ExportTag::type tags) { - static const auto export = + static const auto export_entry = new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, tags | ExportTag::kImplemented | ExportTag::kLog); static R (*FN)(Ps&...) = fn; struct X { static void Trampoline(PPCContext* ppc_context) { - ++export->function_data.call_count; + ++export_entry->function_data.call_count; Param::Init init = { ppc_context, sizeof...(Ps), 0, }; auto params = std::make_tuple(Ps(init)...); - if (export->tags & ExportTag::kLog) { - PrintKernelCall(export, params); + if (export_entry->tags & ExportTag::kLog) { + PrintKernelCall(export_entry, params); } auto result = KernelTrampoline(FN, std::forward>(params), std::make_index_sequence()); result.Store(ppc_context); - if (export->tags & (ExportTag::kLog | ExportTag::kLogResult)) { + if (export_entry->tags & (ExportTag::kLog | ExportTag::kLogResult)) { // TODO(benvanik): log result. } } }; - export->function_data.trampoline = &X::Trampoline; - return export; + export_entry->function_data.trampoline = &X::Trampoline; + return export_entry; } template xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name, xe::cpu::ExportTag::type tags) { - static const auto export = + static const auto export_entry = new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, tags | ExportTag::kImplemented | ExportTag::kLog); static void (*FN)(Ps&...) = fn; struct X { static void Trampoline(PPCContext* ppc_context) { - ++export->function_data.call_count; + ++export_entry->function_data.call_count; Param::Init init = { ppc_context, sizeof...(Ps), }; auto params = std::make_tuple(Ps(init)...); - if (export->tags & ExportTag::kLog) { - PrintKernelCall(export, params); + if (export_entry->tags & ExportTag::kLog) { + PrintKernelCall(export_entry, params); } KernelTrampoline(FN, std::forward>(params), std::make_index_sequence()); } }; - export->function_data.trampoline = &X::Trampoline; - return export; + export_entry->function_data.trampoline = &X::Trampoline; + return export_entry; } } // namespace shim diff --git a/src/xenia/kernel/xam_module.cc b/src/xenia/kernel/xam_module.cc index 79199217d..aa9e297d7 100644 --- a/src/xenia/kernel/xam_module.cc +++ b/src/xenia/kernel/xam_module.cc @@ -37,10 +37,10 @@ XamModule::XamModule(Emulator* emulator, KernelState* kernel_state) std::vector xam_exports(4096); -xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export) { - assert_true(export->ordinal < xam_exports.size()); - xam_exports[export->ordinal] = export; - return export; +xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export_entry) { + assert_true(export_entry->ordinal < xam_exports.size()); + xam_exports[export_entry->ordinal] = export_entry; + return export_entry; } void XamModule::RegisterExportTable(xe::cpu::ExportResolver* export_resolver) { @@ -53,10 +53,10 @@ void XamModule::RegisterExportTable(xe::cpu::ExportResolver* export_resolver) { }; #include "xenia/kernel/util/export_table_post.inc" for (size_t i = 0; i < xe::countof(xam_export_table); ++i) { - auto& export = xam_export_table[i]; - assert_true(export.ordinal < xam_exports.size()); - if (!xam_exports[export.ordinal]) { - xam_exports[export.ordinal] = &export; + auto& export_entry = xam_export_table[i]; + assert_true(export_entry.ordinal < xam_exports.size()); + if (!xam_exports[export_entry.ordinal]) { + xam_exports[export_entry.ordinal] = &export_entry; } } export_resolver->RegisterTable("xam.xex", &xam_exports); diff --git a/src/xenia/kernel/xam_private.h b/src/xenia/kernel/xam_private.h index a6360f70d..c1fd9068a 100644 --- a/src/xenia/kernel/xam_private.h +++ b/src/xenia/kernel/xam_private.h @@ -18,7 +18,7 @@ namespace kernel { class KernelState; -xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export); +xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export_entry); namespace xam { // Registration functions, one per file. diff --git a/src/xenia/kernel/xam_user.cc b/src/xenia/kernel/xam_user.cc index 2962d235c..a7902a44e 100644 --- a/src/xenia/kernel/xam_user.cc +++ b/src/xenia/kernel/xam_user.cc @@ -280,9 +280,8 @@ SHIM_CALL XamUserWriteProfileSettings_shim(PPCContext* ppc_context, return; } - const auto& user_profile = kernel_state->user_profile(); - // TODO: Update and save settings. + // const auto& user_profile = kernel_state->user_profile(); if (overlapped_ptr) { kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); diff --git a/src/xenia/kernel/xboxkrnl_module.cc b/src/xenia/kernel/xboxkrnl_module.cc index b44ba686f..6a5579d1b 100644 --- a/src/xenia/kernel/xboxkrnl_module.cc +++ b/src/xenia/kernel/xboxkrnl_module.cc @@ -139,10 +139,10 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) std::vector xboxkrnl_exports(4096); -xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export) { - assert_true(export->ordinal < xboxkrnl_exports.size()); - xboxkrnl_exports[export->ordinal] = export; - return export; +xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export_entry) { + assert_true(export_entry->ordinal < xboxkrnl_exports.size()); + xboxkrnl_exports[export_entry->ordinal] = export_entry; + return export_entry; } void XboxkrnlModule::RegisterExportTable( @@ -156,10 +156,10 @@ void XboxkrnlModule::RegisterExportTable( }; #include "xenia/kernel/util/export_table_post.inc" for (size_t i = 0; i < xe::countof(xboxkrnl_export_table); ++i) { - auto& export = xboxkrnl_export_table[i]; - assert_true(export.ordinal < xboxkrnl_exports.size()); - if (!xboxkrnl_exports[export.ordinal]) { - xboxkrnl_exports[export.ordinal] = &export; + auto& export_entry = xboxkrnl_export_table[i]; + assert_true(export_entry.ordinal < xboxkrnl_exports.size()); + if (!xboxkrnl_exports[export_entry.ordinal]) { + xboxkrnl_exports[export_entry.ordinal] = &export_entry; } } export_resolver->RegisterTable("xboxkrnl.exe", &xboxkrnl_exports); diff --git a/src/xenia/kernel/xboxkrnl_private.h b/src/xenia/kernel/xboxkrnl_private.h index 97e2c01cf..7451568dd 100644 --- a/src/xenia/kernel/xboxkrnl_private.h +++ b/src/xenia/kernel/xboxkrnl_private.h @@ -17,7 +17,7 @@ namespace kernel { class KernelState; -xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export); +xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export_entry); namespace xboxkrnl { // Registration functions, one per file. diff --git a/src/xenia/kernel/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl_threading.cc index c073e3a88..5ed65166e 100644 --- a/src/xenia/kernel/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl_threading.cc @@ -343,8 +343,8 @@ SHIM_CALL KeDelayExecutionThread_shim(PPCContext* ppc_context, SHIM_CALL NtYieldExecution_shim(PPCContext* ppc_context, KernelState* kernel_state) { // XELOGD("NtYieldExecution()"); - XThread* thread = XThread::GetCurrentThread(); - X_STATUS result = thread->Delay(0, 0, 0); + auto thread = XThread::GetCurrentThread(); + thread->Delay(0, 0, 0); SHIM_SET_RETURN_32(0); } @@ -355,7 +355,6 @@ SHIM_CALL KeQuerySystemTime_shim(PPCContext* ppc_context, XELOGD("KeQuerySystemTime(%.8X)", time_ptr); uint64_t time = Clock::QueryGuestSystemTime(); - if (time_ptr) { SHIM_SET_MEM_64(time_ptr, time); }