diff --git a/src/xenia/debug/ui/premake5.lua b/src/xenia/debug/ui/premake5.lua index cfa983f55..02ba6a81f 100644 --- a/src/xenia/debug/ui/premake5.lua +++ b/src/xenia/debug/ui/premake5.lua @@ -7,17 +7,13 @@ project("xenia-debug-ui") kind("StaticLib") language("C++") links({ - "glew", "imgui", "xenia-base", "xenia-cpu", "xenia-debug", "xenia-ui", - "xenia-ui-gl", }) defines({ - "GLEW_STATIC=1", - "GLEW_MX=1", }) includedirs({ project_root.."/third_party/gflags/src", diff --git a/src/xenia/kernel/util/shim_utils.h b/src/xenia/kernel/util/shim_utils.h index 42b7b9070..5717be1d9 100644 --- a/src/xenia/kernel/util/shim_utils.h +++ b/src/xenia/kernel/util/shim_utils.h @@ -16,6 +16,7 @@ #include #include "xenia/base/byte_order.h" +#include "xenia/base/logging.h" #include "xenia/base/memory.h" #include "xenia/base/string_buffer.h" #include "xenia/cpu/export_resolver.h" @@ -29,7 +30,7 @@ namespace kernel { using PPCContext = xe::cpu::ppc::PPCContext; -#define SHIM_CALL void _cdecl +#define SHIM_CALL void __cdecl #define SHIM_SET_MAPPING(library_name, export_name, shim_data) \ export_resolver->SetFunctionMapping( \ library_name, ordinals::export_name, \ @@ -403,7 +404,7 @@ void PrintKernelCall(cpu::Export* export_entry, const Tuple& params) { string_buffer.Append('('); AppendKernelCallParams(string_buffer, export_entry, params); string_buffer.Append(')'); - if (export_entry->tags & ExportTag::kImportant) { + if (export_entry->tags & xe::cpu::ExportTag::kImportant) { xe::LogLine('i', string_buffer.GetString(), string_buffer.length()); } else { xe::LogLine('d', string_buffer.GetString(), string_buffer.length()); @@ -418,9 +419,9 @@ 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_entry = - new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, - tags | ExportTag::kImplemented | ExportTag::kLog); + static const auto export_entry = new cpu::Export( + ORDINAL, xe::cpu::Export::Type::kFunction, name, + tags | xe::cpu::ExportTag::kImplemented | xe::cpu::ExportTag::kLog); static R (*FN)(Ps&...) = fn; struct X { static void Trampoline(PPCContext* ppc_context) { @@ -429,8 +430,8 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name, ppc_context, sizeof...(Ps), 0, }; auto params = std::make_tuple(Ps(init)...); - if (export_entry->tags & ExportTag::kLog && - (!(export_entry->tags & ExportTag::kHighFrequency) || + if (export_entry->tags & xe::cpu::ExportTag::kLog && + (!(export_entry->tags & xe::cpu::ExportTag::kHighFrequency) || FLAGS_log_high_frequency_kernel_calls)) { PrintKernelCall(export_entry, params); } @@ -438,7 +439,8 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name, KernelTrampoline(FN, std::forward>(params), std::make_index_sequence()); result.Store(ppc_context); - if (export_entry->tags & (ExportTag::kLog | ExportTag::kLogResult)) { + if (export_entry->tags & + (xe::cpu::ExportTag::kLog | xe::cpu::ExportTag::kLogResult)) { // TODO(benvanik): log result. } } @@ -450,9 +452,9 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name, template xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name, xe::cpu::ExportTag::type tags) { - static const auto export_entry = - new cpu::Export(ORDINAL, xe::cpu::Export::Type::kFunction, name, - tags | ExportTag::kImplemented | ExportTag::kLog); + static const auto export_entry = new cpu::Export( + ORDINAL, xe::cpu::Export::Type::kFunction, name, + tags | xe::cpu::ExportTag::kImplemented | xe::cpu::ExportTag::kLog); static void (*FN)(Ps&...) = fn; struct X { static void Trampoline(PPCContext* ppc_context) { @@ -461,8 +463,8 @@ xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name, ppc_context, sizeof...(Ps), }; auto params = std::make_tuple(Ps(init)...); - if (export_entry->tags & ExportTag::kLog && - (!(export_entry->tags & ExportTag::kHighFrequency) || + if (export_entry->tags & xe::cpu::ExportTag::kLog && + (!(export_entry->tags & xe::cpu::ExportTag::kHighFrequency) || FLAGS_log_high_frequency_kernel_calls)) { PrintKernelCall(export_entry, params); } diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index 5a8620907..2525d6c39 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -869,9 +869,17 @@ int xe_xex2_load_pe(xe_xex2_ref xex) { // IAT Import Address Table ptr // opthdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_X].VirtualAddress / .Size +// The macros in pe_image.h don't work with clang, for some reason. +// offsetof seems to be unable to find OptionalHeader. +#define offsetof1(type, member) ((std::size_t) & (((type*)0)->member)) +#define IMAGE_FIRST_SECTION1(ntheader) \ + ((PIMAGE_SECTION_HEADER)( \ + (uint8_t*)ntheader + offsetof1(IMAGE_NT_HEADERS, OptionalHeader) + \ + ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader)) + // Quick scan to determine bounds of sections. size_t upper_address = 0; - const IMAGE_SECTION_HEADER* sechdr = IMAGE_FIRST_SECTION(nthdr); + const IMAGE_SECTION_HEADER* sechdr = IMAGE_FIRST_SECTION1(nthdr); for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) { const size_t physical_address = opthdr->ImageBase + sechdr->VirtualAddress; upper_address = @@ -879,7 +887,7 @@ int xe_xex2_load_pe(xe_xex2_ref xex) { } // Setup/load sections. - sechdr = IMAGE_FIRST_SECTION(nthdr); + sechdr = IMAGE_FIRST_SECTION1(nthdr); for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) { PESection* section = (PESection*)calloc(1, sizeof(PESection)); memcpy(section->name, sechdr->Name, sizeof(sechdr->Name)); diff --git a/src/xenia/kernel/xam/xam_content.cc b/src/xenia/kernel/xam/xam_content.cc index 6c453be71..86aad86b3 100644 --- a/src/xenia/kernel/xam/xam_content.cc +++ b/src/xenia/kernel/xam/xam_content.cc @@ -182,7 +182,9 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id, // Get all content data. auto content_datas = kernel_state()->content_manager()->ListContent( - device_id ? device_id : dummy_device_info_.device_id, content_type); + device_id ? static_cast(device_id) + : dummy_device_info_.device_id, + content_type); for (auto& content_data : content_datas) { auto ptr = e->AppendItem(); if (!ptr) { diff --git a/src/xenia/kernel/xam/xam_ui.cc b/src/xenia/kernel/xam/xam_ui.cc index 88be3e335..860f96d90 100644 --- a/src/xenia/kernel/xam/xam_ui.cc +++ b/src/xenia/kernel/xam/xam_ui.cc @@ -21,7 +21,7 @@ namespace xe { namespace kernel { namespace xam { -std::atomic xam_dialogs_shown_ = 0; +std::atomic xam_dialogs_shown_ = {0}; SHIM_CALL XamIsUIActive_shim(PPCContext* ppc_context, KernelState* kernel_state) { @@ -54,7 +54,7 @@ class MessageBoxDialog : public xe::ui::ImGuiDialog { } if (ImGui::BeginPopupModal(title_.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text(description_.c_str()); + ImGui::Text("%s", description_.c_str()); if (first_draw) { ImGui::SetKeyboardFocusHere(); } @@ -185,7 +185,7 @@ class KeyboardInputDialog : public xe::ui::ImGuiDialog { } if (ImGui::BeginPopupModal(title_.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextWrapped(description_.c_str()); + ImGui::TextWrapped("%s", description_.c_str()); if (first_draw) { ImGui::SetKeyboardFocusHere(); } diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc index 342730be9..2ebc63258 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc @@ -196,9 +196,10 @@ dword_result_t NtReadFile(dword_t file_handle, dword_t event_handle, if (true || file->is_synchronous()) { // Synchronous. size_t bytes_read = 0; - result = file->Read(buffer, buffer_length, - byte_offset_ptr ? *byte_offset_ptr : -1, &bytes_read, - apc_context); + result = file->Read( + buffer, buffer_length, + byte_offset_ptr ? static_cast(*byte_offset_ptr) : -1u, + &bytes_read, apc_context); if (io_status_block) { io_status_block->status = result; io_status_block->information = static_cast(bytes_read); @@ -210,8 +211,8 @@ dword_result_t NtReadFile(dword_t file_handle, dword_t event_handle, if ((uint32_t)apc_routine_ptr & ~1) { if (apc_context) { auto thread = XThread::GetCurrentThread(); - thread->EnqueueApc((uint32_t)apc_routine_ptr & ~1, apc_context, - io_status_block, 0); + thread->EnqueueApc(static_cast(apc_routine_ptr) & ~1u, + apc_context, io_status_block, 0); } } @@ -286,9 +287,10 @@ dword_result_t NtWriteFile(dword_t file_handle, dword_t event_handle, if (true || file->is_synchronous()) { // Synchronous request. size_t bytes_written = 0; - result = file->Write(buffer, buffer_length, - byte_offset_ptr ? *byte_offset_ptr : -1, - &bytes_written, apc_context); + result = file->Write( + buffer, buffer_length, + byte_offset_ptr ? static_cast(*byte_offset_ptr) : -1u, + &bytes_written, apc_context); if (XSUCCEEDED(result)) { info = (int32_t)bytes_written; } @@ -356,7 +358,7 @@ dword_result_t NtRemoveIoCompletion( status = X_STATUS_INVALID_HANDLE; } - uint64_t timeout_ticks = timeout ? *timeout : 0; + uint64_t timeout_ticks = timeout ? static_cast(*timeout) : 0u; if (port->WaitForNotification(timeout_ticks)) { auto notification = port->DequeueNotification(); if (key_context) { diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc index 1bfc7da25..80d78939f 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc @@ -323,7 +323,8 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_context, void AppendParam(StringBuffer* string_buffer, pointer_t reg) { string_buffer->AppendFormat("%.8X(%.8X, %.8X)", reg.guest_address(), - reg->notification_routine, reg->priority); + static_cast(reg->notification_routine), + static_cast(reg->priority)); } void ExRegisterTitleTerminateNotification( diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc index fdecef51e..54cd15f76 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc @@ -832,7 +832,7 @@ dword_result_t KeWaitForSingleObject(lpvoid_t object_ptr, dword_t wait_reason, return X_STATUS_ABANDONED_WAIT_0; } - uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; + uint64_t timeout = timeout_ptr ? static_cast(*timeout_ptr) : 0u; X_STATUS result = object->Wait(wait_reason, processor_mode, alertable, timeout_ptr ? &timeout : nullptr); @@ -850,7 +850,7 @@ dword_result_t NtWaitForSingleObjectEx(dword_t object_handle, dword_t wait_mode, auto object = kernel_state()->object_table()->LookupObject(object_handle); if (object) { - uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; + uint64_t timeout = timeout_ptr ? static_cast(*timeout_ptr) : 0u; result = object->Wait(3, wait_mode, alertable, timeout_ptr ? &timeout : nullptr); } else { @@ -885,7 +885,7 @@ dword_result_t KeWaitForMultipleObjects(dword_t count, lpdword_t objects_ptr, objects.push_back(std::move(object_ref)); } - uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; + uint64_t timeout = timeout_ptr ? static_cast(*timeout_ptr) : 0u; result = XObject::WaitMultiple(uint32_t(objects.size()), reinterpret_cast(objects.data()), wait_type, wait_reason, processor_mode, @@ -937,7 +937,7 @@ dword_result_t NtSignalAndWaitForSingleObjectEx(dword_t signal_handle, auto wait_object = kernel_state()->object_table()->LookupObject(wait_handle); if (signal_object && wait_object) { - uint64_t timeout = timeout_ptr ? *timeout_ptr : 0; + uint64_t timeout = timeout_ptr ? static_cast(*timeout_ptr) : 0u; result = XObject::SignalAndWait(signal_object.get(), wait_object.get(), 3, 1, alertable, timeout_ptr ? &timeout : nullptr); diff --git a/src/xenia/kernel/xenumerator.h b/src/xenia/kernel/xenumerator.h index dafded9fe..fd19e9ed2 100644 --- a/src/xenia/kernel/xenumerator.h +++ b/src/xenia/kernel/xenumerator.h @@ -64,7 +64,7 @@ class XStaticEnumerator : public XEnumerator { std::memcpy(buffer, buffer_.data(), item_count_ * item_size_); } - bool WriteItem(uint8_t* buffer) { + bool WriteItem(uint8_t* buffer) override { if (current_item_ >= item_count_) { return false; } diff --git a/src/xenia/kernel/xobject.cc b/src/xenia/kernel/xobject.cc index bd27409d7..d5a925fe0 100644 --- a/src/xenia/kernel/xobject.cc +++ b/src/xenia/kernel/xobject.cc @@ -150,6 +150,8 @@ object_ref XObject::Restore(KernelState* kernel_state, Type type, return XThread::Restore(kernel_state, stream); case kTypeTimer: break; + case kTypeUndefined: + break; } assert_always("No restore handler exists for this object!"); diff --git a/src/xenia/kernel/xthread.cc b/src/xenia/kernel/xthread.cc index c14257cb9..e90703870 100644 --- a/src/xenia/kernel/xthread.cc +++ b/src/xenia/kernel/xthread.cc @@ -1145,12 +1145,12 @@ object_ref XThread::Restore(KernelState* kernel_state, thread->kernel_state_ = kernel_state; if (!thread->RestoreObject(stream)) { - return false; + return nullptr; } if (stream->Read() != 'THRD') { XELOGE("Could not restore XThread - invalid magic!"); - return false; + return nullptr; } XELOGD("XThread %.8X", thread->handle());