diff options
Diffstat (limited to 'src')
45 files changed, 252 insertions, 159 deletions
diff --git a/src/audio_core/hle/source.cpp b/src/audio_core/hle/source.cpp index de4e88cae..c12287700 100644 --- a/src/audio_core/hle/source.cpp +++ b/src/audio_core/hle/source.cpp @@ -264,7 +264,7 @@ void Source::GenerateFrame() { break; } } - state.next_sample_number += frame_position; + state.next_sample_number += static_cast<u32>(frame_position); state.filters.ProcessFrame(current_frame); } diff --git a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp index 7d06ec28a..ce2b9fa50 100644 --- a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp @@ -26,8 +26,8 @@ namespace { QImage LoadTexture(const u8* src, const Pica::Texture::TextureInfo& info) { QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); - for (int y = 0; y < info.height; ++y) { - for (int x = 0; x < info.width; ++x) { + for (u32 y = 0; y < info.height; ++y) { + for (u32 x = 0; x < info.width; ++x) { Math::Vec4<u8> color = Pica::Texture::LookupTexture(src, x, y, info, true); decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); } diff --git a/src/citra_qt/debugger/graphics/graphics_surface.cpp b/src/citra_qt/debugger/graphics/graphics_surface.cpp index 47d9924e1..c974545ef 100644 --- a/src/citra_qt/debugger/graphics/graphics_surface.cpp +++ b/src/citra_qt/debugger/graphics/graphics_surface.cpp @@ -273,7 +273,8 @@ void GraphicsSurfaceWidget::Pick(int x, int y) { surface_picker_x_control->setValue(x); surface_picker_y_control->setValue(y); - if (x < 0 || x >= surface_width || y < 0 || y >= surface_height) { + if (x < 0 || x >= static_cast<int>(surface_width) || y < 0 || + y >= static_cast<int>(surface_height)) { surface_info_label->setText(tr("Pixel out of bounds")); surface_info_label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); return; diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index bad311793..6959915fa 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -117,7 +117,7 @@ std::string StringFromFormat(const char* format, ...) { } // For Debugging. Read out an u8 array. -std::string ArrayToString(const u8* data, u32 size, int line_len, bool spaces) { +std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { std::ostringstream oss; oss << std::setfill('0') << std::hex; diff --git a/src/common/string_util.h b/src/common/string_util.h index 075bf4ecb..259360aec 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -33,7 +33,7 @@ inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) { } // Good -std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spaces = true); +std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); std::string StripSpaces(const std::string& s); std::string StripQuotes(const std::string& s); diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2b05f66ee..3f0057d9e 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -104,8 +104,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; + *this = *this * f; } template <typename V> Vec2<decltype(T{} / V{})> operator/(const V& f) const { @@ -262,9 +261,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; + *this = *this * f; } template <typename V> Vec3<decltype(T{} / V{})> operator/(const V& f) const { @@ -478,10 +475,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; - w *= f; + *this = *this * f; } template <typename V> Vec4<decltype(T{} / V{})> operator/(const V& f) const { diff --git a/src/core/core.cpp b/src/core/core.cpp index 59b8768e7..0c7a72987 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -13,6 +13,7 @@ #include "core/core_timing.h" #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/process.h" #include "core/hle/kernel/thread.h" #include "core/hle/service/service.h" #include "core/hw/hw.h" @@ -100,7 +101,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file return init_result; } - const Loader::ResultStatus load_result{app_loader->Load()}; + const Loader::ResultStatus load_result{app_loader->Load(Kernel::g_current_process)}; if (Loader::ResultStatus::Success != load_result) { LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); System::Shutdown(); @@ -114,6 +115,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file return ResultStatus::ErrorLoader; } } + Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); status = ResultStatus::Success; return status; } @@ -196,4 +198,4 @@ void System::Shutdown() { LOG_DEBUG(Core, "Shutdown OK"); } -} // namespace +} // namespace Core diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 123fe7cd4..be2b2e25f 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -946,7 +946,7 @@ static void Init(u16 port) { WSAStartup(MAKEWORD(2, 2), &InitData); #endif - int tmpsock = socket(PF_INET, SOCK_STREAM, 0); + int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); if (tmpsock == -1) { LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); } @@ -973,7 +973,7 @@ static void Init(u16 port) { sockaddr_in saddr_client; sockaddr* client_addr = reinterpret_cast<sockaddr*>(&saddr_client); socklen_t client_addrlen = sizeof(saddr_client); - gdbserver_socket = accept(tmpsock, client_addr, &client_addrlen); + gdbserver_socket = static_cast<int>(accept(tmpsock, client_addr, &client_addrlen)); if (gdbserver_socket < 0) { // In the case that we couldn't start the server for whatever reason, just start CPU // execution like normal. diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index f7f96125a..87ed85df6 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h @@ -122,11 +122,11 @@ union StaticBufferDescInfo { BitField<14, 18, u32> size; }; -inline u32 StaticBufferDesc(u32 size, u8 buffer_id) { +inline u32 StaticBufferDesc(size_t size, u8 buffer_id) { StaticBufferDescInfo info{}; info.descriptor_type.Assign(StaticBuffer); info.buffer_id.Assign(buffer_id); - info.size.Assign(size); + info.size.Assign(static_cast<u32>(size)); return info.raw; } @@ -160,11 +160,11 @@ union MappedBufferDescInfo { BitField<4, 28, u32> size; }; -inline u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { +inline u32 MappedBufferDesc(size_t size, MappedBufferPermissions perms) { MappedBufferDescInfo info{}; info.flags.Assign(MappedBuffer); info.perms.Assign(perms); - info.size.Assign(size); + info.size.Assign(static_cast<u32>(size)); return info.raw; } diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index f0d89cffe..7cb95cbac 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -117,9 +117,9 @@ public: void PushCurrentPIDHandle(); - void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id); + void PushStaticBuffer(VAddr buffer_vaddr, size_t size, u8 buffer_id); - void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms); + void PushMappedBuffer(VAddr buffer_vaddr, size_t size, MappedBufferPermissions perms); }; /// Push /// @@ -190,12 +190,12 @@ inline void RequestBuilder::PushCurrentPIDHandle() { Push(u32(0)); } -inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { +inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, size_t size, u8 buffer_id) { Push(StaticBufferDesc(size, buffer_id)); Push(buffer_vaddr); } -inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, u32 size, +inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, size_t size, MappedBufferPermissions perms) { Push(MappedBufferDesc(size, perms)); Push(buffer_vaddr); @@ -227,8 +227,8 @@ public: bool validateHeader = true) { if (validateHeader) ValidateHeader(); - Header builderHeader{ - MakeHeader(header.command_id, normal_params_size, translate_params_size)}; + Header builderHeader{MakeHeader(static_cast<u16>(header.command_id), normal_params_size, + translate_params_size)}; if (context != nullptr) return {*context, builderHeader}; else diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 5ebe2eca4..6020e9764 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -37,7 +37,7 @@ SharedPtr<Object> HLERequestContext::GetIncomingHandle(u32 id_from_cmdbuf) const u32 HLERequestContext::AddOutgoingHandle(SharedPtr<Object> object) { request_handles.push_back(std::move(object)); - return request_handles.size() - 1; + return static_cast<u32>(request_handles.size() - 1); } void HLERequestContext::ClearIncomingObjects() { diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index cef961289..2cbca5e5b 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -90,7 +90,7 @@ void Mutex::UpdatePriority() { if (!holding_thread) return; - s32 best_priority = THREADPRIO_LOWEST; + u32 best_priority = THREADPRIO_LOWEST; for (auto& waiter : GetWaitingThreads()) { if (waiter->current_priority < best_priority) best_priority = waiter->current_priority; diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 522ad2333..cf3163e0f 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -147,7 +147,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) { } vm_manager.LogLayout(Log::Level::Debug); - Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority); + Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority, this); } VAddr Process::GetLinearHeapAreaAddress() const { diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index a8f10a3ee..517dc47a8 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -61,7 +61,7 @@ s32 ResourceLimit::GetCurrentResourceValue(u32 resource) const { } } -s32 ResourceLimit::GetMaxResourceValue(u32 resource) const { +u32 ResourceLimit::GetMaxResourceValue(u32 resource) const { switch (resource) { case PRIORITY: return max_priority; diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 6cdfbcf8d..42874eb8d 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -67,7 +67,7 @@ public: * @param resource Requested resource type * @returns The max value of the resource type */ - s32 GetMaxResourceValue(u32 resource) const; + u32 GetMaxResourceValue(u32 resource) const; /// Name of resource limit object. std::string name; diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index a7b66142f..02d5a7a36 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -42,7 +42,8 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u memory_region->used += size; shared_memory->linear_heap_phys_address = - Memory::FCRAM_PADDR + memory_region->base + shared_memory->backing_block_offset; + Memory::FCRAM_PADDR + memory_region->base + + static_cast<PAddr>(shared_memory->backing_block_offset); // Increase the amount of used linear heap memory for the owner process. if (shared_memory->owner_process != nullptr) { diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 94b335ed1..93a6f2182 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -114,7 +114,7 @@ public: /// Backing memory for this shared memory block. std::shared_ptr<std::vector<u8>> backing_block; /// Offset into the backing block for this shared memory. - u32 backing_block_offset; + size_t backing_block_offset; /// Size of the memory block. Page-aligned. u32 size; /// Permission restrictions applied to the process which created the block. diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 690cb20b3..2614a260c 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -111,7 +111,7 @@ void Thread::Stop() { Thread* ArbitrateHighestPriorityThread(u32 address) { Thread* highest_priority_thread = nullptr; - s32 priority = THREADPRIO_LOWEST; + u32 priority = THREADPRIO_LOWEST; // Iterate through threads, find highest priority thread that is waiting to be arbitrated... for (auto& thread : thread_list) { @@ -319,7 +319,7 @@ static void DebugThreadQueue() { } for (auto& t : thread_list) { - s32 priority = ready_queue.contains(t.get()); + u32 priority = ready_queue.contains(t.get()); if (priority != -1) { LOG_DEBUG(Kernel, "0x%02X %u", priority, t->GetObjectId()); } @@ -369,7 +369,8 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_ } ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority, - u32 arg, s32 processor_id, VAddr stack_top) { + u32 arg, s32 processor_id, VAddr stack_top, + SharedPtr<Process> owner_process) { // Check if priority is in ranged. Lowest priority -> highest priority id. if (priority > THREADPRIO_LOWEST) { LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority); @@ -383,7 +384,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, // TODO(yuriks): Other checks, returning 0xD9001BEA - if (!Memory::IsValidVirtualAddress(entry_point)) { + if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) { LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); // TODO: Verify error return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, @@ -406,10 +407,10 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, thread->wait_address = 0; thread->name = std::move(name); thread->callback_handle = wakeup_callback_handle_table.Create(thread).Unwrap(); - thread->owner_process = g_current_process; + thread->owner_process = owner_process; // Find the next available TLS index, and mark it as used - auto& tls_slots = Kernel::g_current_process->tls_slots; + auto& tls_slots = owner_process->tls_slots; bool needs_allocation = true; u32 available_page; // Which allocated page has free space u32 available_slot; // Which slot within the page is free @@ -428,18 +429,18 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, return ERR_OUT_OF_MEMORY; } - u32 offset = linheap_memory->size(); + size_t offset = linheap_memory->size(); // Allocate some memory from the end of the linear heap for this region. linheap_memory->insert(linheap_memory->end(), Memory::PAGE_SIZE, 0); memory_region->used += Memory::PAGE_SIZE; - Kernel::g_current_process->linear_heap_used += Memory::PAGE_SIZE; + owner_process->linear_heap_used += Memory::PAGE_SIZE; tls_slots.emplace_back(0); // The page is completely available at the start - available_page = tls_slots.size() - 1; + available_page = static_cast<u32>(tls_slots.size() - 1); available_slot = 0; // Use the first slot in the new page - auto& vm_manager = Kernel::g_current_process->vm_manager; + auto& vm_manager = owner_process->vm_manager; vm_manager.RefreshMemoryBlockMappings(linheap_memory.get()); // Map the page to the current process' address space. @@ -463,7 +464,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, return MakeResult<SharedPtr<Thread>>(std::move(thread)); } -void Thread::SetPriority(s32 priority) { +void Thread::SetPriority(u32 priority) { ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, "Invalid priority value."); // If thread was ready, adjust queues @@ -476,7 +477,7 @@ void Thread::SetPriority(s32 priority) { } void Thread::UpdatePriority() { - s32 best_priority = nominal_priority; + u32 best_priority = nominal_priority; for (auto& mutex : held_mutexes) { if (mutex->priority < best_priority) best_priority = mutex->priority; @@ -484,7 +485,7 @@ void Thread::UpdatePriority() { BoostPriority(best_priority); } -void Thread::BoostPriority(s32 priority) { +void Thread::BoostPriority(u32 priority) { // If thread was ready, adjust queues if (status == THREADSTATUS_READY) ready_queue.move(this, current_priority, priority); @@ -493,10 +494,10 @@ void Thread::BoostPriority(s32 priority) { current_priority = priority; } -SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) { +SharedPtr<Thread> SetupMainThread(u32 entry_point, u32 priority, SharedPtr<Process> owner_process) { // Initialize new "main" thread auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, - Memory::HEAP_VADDR_END); + Memory::HEAP_VADDR_END, owner_process); SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); @@ -537,7 +538,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) { s32 Thread::GetWaitObjectIndex(WaitObject* object) const { ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything"); auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object); - return std::distance(match, wait_objects.rend()) - 1; + return static_cast<s32>(std::distance(match, wait_objects.rend()) - 1); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 328f1a86a..4679c2022 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -15,7 +15,7 @@ #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" -enum ThreadPriority : s32 { +enum ThreadPriority : u32 { THREADPRIO_HIGHEST = 0, ///< Highest thread priority THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps THREADPRIO_DEFAULT = 48, ///< Default thread priority for userland apps @@ -61,10 +61,12 @@ public: * @param arg User data to pass to the thread * @param processor_id The ID(s) of the processors on which the thread is desired to be run * @param stack_top The address of the thread's stack top + * @param owner_process The parent process for the thread * @return A shared pointer to the newly created thread */ static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority, - u32 arg, s32 processor_id, VAddr stack_top); + u32 arg, s32 processor_id, VAddr stack_top, + SharedPtr<Process> owner_process); std::string GetName() const override { return name; @@ -85,7 +87,7 @@ public: * Gets the thread's current priority * @return The current thread's priority */ - s32 GetPriority() const { + u32 GetPriority() const { return current_priority; } @@ -93,7 +95,7 @@ public: * Sets the thread's current priority * @param priority The new priority */ - void SetPriority(s32 priority); + void SetPriority(u32 priority); /** * Boost's a thread's priority to the best priority among the thread's held mutexes. @@ -105,7 +107,7 @@ public: * Temporarily boosts the thread's priority until the next time it is scheduled * @param priority The new priority */ - void BoostPriority(s32 priority); + void BoostPriority(u32 priority); /** * Gets the thread's thread ID @@ -121,9 +123,9 @@ public: void ResumeFromWait(); /** - * Schedules an event to wake up the specified thread after the specified delay - * @param nanoseconds The time this thread will be allowed to sleep for - */ + * Schedules an event to wake up the specified thread after the specified delay + * @param nanoseconds The time this thread will be allowed to sleep for + */ void WakeAfterDelay(s64 nanoseconds); /** @@ -179,8 +181,8 @@ public: u32 entry_point; u32 stack_top; - s32 nominal_priority; ///< Nominal thread priority, as set by the emulated application - s32 current_priority; ///< Current thread priority, can be temporarily changed + u32 nominal_priority; ///< Nominal thread priority, as set by the emulated application + u32 current_priority; ///< Current thread priority, can be temporarily changed u64 last_running_ticks; ///< CPU tick when thread was last running @@ -223,9 +225,10 @@ private: * Sets up the primary application thread * @param entry_point The address at which the thread should start execution * @param priority The priority to give the main thread + * @param owner_process The parent process for the main thread * @return A shared pointer to the main thread */ -SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority); +SharedPtr<Thread> SetupMainThread(u32 entry_point, u32 priority, SharedPtr<Process> owner_process); /** * Returns whether there are any threads that are ready to run. @@ -285,4 +288,4 @@ void ThreadingShutdown(); */ const std::vector<SharedPtr<Thread>>& GetThreadList(); -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index 1ced26905..469554908 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -34,7 +34,7 @@ void WaitObject::RemoveWaitingThread(Thread* thread) { SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { Thread* candidate = nullptr; - s32 candidate_priority = THREADPRIO_LOWEST + 1; + u32 candidate_priority = THREADPRIO_LOWEST + 1; for (const auto& thread : waiting_threads) { // The list of waiting threads must not contain threads that are not waiting to be awakened. diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 8c0ba73f2..4c6156345 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -561,7 +561,7 @@ void ReceiveParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast<u32>(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); @@ -609,7 +609,7 @@ void GlanceParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast<u32>(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index c9f9e9d95..8172edae8 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -177,7 +177,7 @@ void CompletionEventCallBack(u64 port_id, int) { LOG_ERROR(Service_CAM, "The destination size (%u) doesn't match the source (%zu)!", port.dest_size, buffer_size); } - Memory::WriteBlock(port.dest, buffer.data(), std::min<u32>(port.dest_size, buffer_size)); + Memory::WriteBlock(port.dest, buffer.data(), std::min<size_t>(port.dest_size, buffer_size)); } port.is_receiving = false; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index f26a1f65f..f78c25fb2 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -141,7 +141,7 @@ void GetCountryCodeString(Service::Interface* self) { void GetCountryCodeID(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); - u16 country_code = cmd_buff[1]; + u16 country_code = static_cast<u16>(cmd_buff[1]); u16 country_code_id = 0; // The following algorithm will fail if the first country code isn't 0. diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 4ccb3cd32..4ee7df73c 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -217,7 +217,7 @@ void Directory::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> serve LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count); // Number of entries actually read - u32 read = backend->Read(entries.size(), entries.data()); + u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data()); cmd_buff[2] = read; Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry)); break; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index aa5d821f9..379fbd71c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -251,7 +251,7 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) { Math::Vec3<float> gyro; std::tie(std::ignore, gyro) = motion_device->GetStatus(); double stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); - gyro *= gyroscope_coef * stretch; + gyro *= gyroscope_coef * static_cast<float>(stretch); gyroscope_entry.x = static_cast<s16>(gyro.x); gyroscope_entry.y = static_cast<s16>(gyro.y); gyroscope_entry.z = static_cast<s16>(gyro.z); diff --git a/src/core/hle/service/ldr_ro/cro_helper.h b/src/core/hle/service/ldr_ro/cro_helper.h index 3bc10dbdc..57b4fb6df 100644 --- a/src/core/hle/service/ldr_ro/cro_helper.h +++ b/src/core/hle/service/ldr_ro/cro_helper.h @@ -413,7 +413,8 @@ private: */ template <typename T> void GetEntry(std::size_t index, T& data) const { - Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast<u32>(index * sizeof(T)), + &data, sizeof(T)); } /** @@ -425,7 +426,8 @@ private: */ template <typename T> void SetEntry(std::size_t index, const T& data) { - Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast<u32>(index * sizeof(T)), + &data, sizeof(T)); } /** diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 4e2af9ae6..8ef0cda09 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -316,7 +316,7 @@ static void RecvBeaconBroadcastData(Interface* self) { auto beacons = GetReceivedBeacons(mac_address); BeaconDataReplyHeader data_reply_header{}; - data_reply_header.total_entries = beacons.size(); + data_reply_header.total_entries = static_cast<u32>(beacons.size()); data_reply_header.max_output_size = out_buffer_size; Memory::WriteBlock(current_buffer_pos, &data_reply_header, sizeof(BeaconDataReplyHeader)); @@ -326,8 +326,8 @@ static void RecvBeaconBroadcastData(Interface* self) { for (const auto& beacon : beacons) { BeaconEntryHeader entry{}; // TODO(Subv): Figure out what this size is used for. - entry.unk_size = sizeof(BeaconEntryHeader) + beacon.data.size(); - entry.total_size = sizeof(BeaconEntryHeader) + beacon.data.size(); + entry.unk_size = static_cast<u32>(sizeof(BeaconEntryHeader) + beacon.data.size()); + entry.total_size = static_cast<u32>(sizeof(BeaconEntryHeader) + beacon.data.size()); entry.wifi_channel = beacon.channel; entry.header_size = sizeof(BeaconEntryHeader); entry.mac_address = beacon.transmitter_address; @@ -338,9 +338,9 @@ static void RecvBeaconBroadcastData(Interface* self) { current_buffer_pos += sizeof(BeaconEntryHeader); Memory::WriteBlock(current_buffer_pos, beacon.data.data(), beacon.data.size()); - current_buffer_pos += beacon.data.size(); + current_buffer_pos += static_cast<VAddr>(beacon.data.size()); - total_size += sizeof(BeaconEntryHeader) + beacon.data.size(); + total_size += static_cast<u32>(sizeof(BeaconEntryHeader) + beacon.data.size()); } // Update the total size in the structure and write it to the buffer again. diff --git a/src/core/hle/service/nwm/uds_beacon.cpp b/src/core/hle/service/nwm/uds_beacon.cpp index 552eaf65e..73a80d940 100644 --- a/src/core/hle/service/nwm/uds_beacon.cpp +++ b/src/core/hle/service/nwm/uds_beacon.cpp @@ -243,7 +243,7 @@ std::vector<u8> GenerateNintendoFirstEncryptedDataTag(const NetworkInfo& network EncryptedDataTag tag{}; tag.header.tag_id = static_cast<u8>(TagId::VendorSpecific); - tag.header.length = sizeof(tag) - sizeof(TagHeader) + payload_size; + tag.header.length = static_cast<u8>(sizeof(tag) - sizeof(TagHeader) + payload_size); tag.oui_type = static_cast<u8>(NintendoTagId::EncryptedData0); tag.oui = NintendoOUI; @@ -279,7 +279,7 @@ std::vector<u8> GenerateNintendoSecondEncryptedDataTag(const NetworkInfo& networ EncryptedDataTag tag{}; tag.header.tag_id = static_cast<u8>(TagId::VendorSpecific); - tag.header.length = tag_length; + tag.header.length = static_cast<u8>(tag_length); tag.oui_type = static_cast<u8>(NintendoTagId::EncryptedData1); tag.oui = NintendoOUI; diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 0fd9b8b8c..3ef2a84b6 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -197,7 +197,7 @@ static std::vector<u8> DecryptDataFrame(const std::vector<u8>& encrypted_payload df.ChannelMessageEnd(CryptoPP::DEFAULT_CHANNEL); df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector<u8> pdata(size); df.Get(pdata.data(), size); @@ -251,7 +251,7 @@ static std::vector<u8> EncryptDataFrame(const std::vector<u8>& payload, df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector<u8> cipher(size); df.Get(cipher.data(), size); @@ -266,8 +266,8 @@ static std::vector<u8> EncryptDataFrame(const std::vector<u8>& payload, std::vector<u8> GenerateDataPayload(const std::vector<u8>& data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number) { std::vector<u8> buffer = GenerateLLCHeader(EtherType::SecureData); - std::vector<u8> securedata_header = - GenerateSecureDataHeader(data.size(), channel, dest_node, src_node, sequence_number); + std::vector<u8> securedata_header = GenerateSecureDataHeader( + static_cast<u16>(data.size()), channel, dest_node, src_node, sequence_number); buffer.insert(buffer.end(), securedata_header.begin(), securedata_header.end()); buffer.insert(buffer.end(), data.begin(), data.end()); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 41e62cf62..fefd50805 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -396,7 +396,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha // We found a ready object, acquire it and set the result value Kernel::WaitObject* object = itr->get(); object->Acquire(thread); - *out = std::distance(objects.begin(), itr); + *out = static_cast<s32>(std::distance(objects.begin(), itr)); return RESULT_SUCCESS; } @@ -520,7 +520,7 @@ static ResultCode ReplyAndReceive(s32* index, Kernel::Handle* handles, s32 handl // We found a ready object, acquire it and set the result value Kernel::WaitObject* object = itr->get(); object->Acquire(thread); - *index = std::distance(objects.begin(), itr); + *index = static_cast<s32>(std::distance(objects.begin(), itr)); if (object->GetHandleType() == Kernel::HandleType::ServerSession) { auto server_session = static_cast<Kernel::ServerSession*>(object); @@ -717,8 +717,9 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 ent "Newly created thread must run in the SysCore (Core1), unimplemented."); } - CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create(name, entry_point, priority, - arg, processor_id, stack_top)); + CASCADE_RESULT(SharedPtr<Thread> thread, + Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, + Kernel::g_current_process)); thread->context.fpscr = FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 @@ -743,7 +744,7 @@ static void ExitThread() { } /// Gets the priority for the specified thread -static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { +static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) { const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -753,7 +754,7 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { } /// Sets the priority for the specified thread -static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { +static ResultCode SetThreadPriority(Kernel::Handle handle, u32 priority) { if (priority > THREADPRIO_LOWEST) { return Kernel::ERR_OUT_OF_RANGE; } diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 5ad5c5287..918038f1e 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -91,8 +91,8 @@ static u32 TranslateAddr(u32 addr, const THREEloadinfo* loadinfo, u32* offsets) return loadinfo->seg_addrs[2] + addr - offsets[1]; } -using Kernel::SharedPtr; using Kernel::CodeSet; +using Kernel::SharedPtr; static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr, SharedPtr<CodeSet>* out_codeset) { @@ -255,7 +255,7 @@ FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_THREEDSX::Load() { +ResultStatus AppLoader_THREEDSX::Load(Kernel::SharedPtr<Kernel::Process>& process) { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; @@ -267,16 +267,15 @@ ResultStatus AppLoader_THREEDSX::Load() { return ResultStatus::Error; codeset->name = filename; - Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); - Kernel::g_current_process->svc_access_mask.set(); - Kernel::g_current_process->address_mappings = default_address_mappings; - Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); + process = Kernel::Process::Create(std::move(codeset)); + process->svc_access_mask.set(); + process->address_mappings = default_address_mappings; // Attach the default resource limit (APPLICATION) to the process - Kernel::g_current_process->resource_limit = + process->resource_limit = Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); - Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); + process->Run(48, Kernel::DEFAULT_STACK_SIZE); Service::FS::RegisterSelfNCCH(*this); diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index 3f376778a..1e59bbb9d 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h @@ -31,7 +31,7 @@ public: return IdentifyType(file); } - ResultStatus Load() override; + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 2de1f4e81..e36e42120 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -13,8 +13,8 @@ #include "core/loader/elf.h" #include "core/memory.h" -using Kernel::SharedPtr; using Kernel::CodeSet; +using Kernel::SharedPtr; //////////////////////////////////////////////////////////////////////////////////////////////////// // ELF Header Constants @@ -375,7 +375,7 @@ FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_ELF::Load() { +ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; @@ -394,16 +394,15 @@ ResultStatus AppLoader_ELF::Load() { SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); codeset->name = filename; - Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); - Kernel::g_current_process->svc_access_mask.set(); - Kernel::g_current_process->address_mappings = default_address_mappings; - Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); + process = Kernel::Process::Create(std::move(codeset)); + process->svc_access_mask.set(); + process->address_mappings = default_address_mappings; // Attach the default resource limit (APPLICATION) to the process - Kernel::g_current_process->resource_limit = + process->resource_limit = Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); - Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); + process->Run(48, Kernel::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 862aa90d8..113da5917 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -30,7 +30,7 @@ public: return IdentifyType(file); } - ResultStatus Load() override; + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; private: std::string filename; diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 3160fd2fd..82b2be6a3 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -13,10 +13,12 @@ #include <boost/optional.hpp> #include "common/common_types.h" #include "common/file_util.h" +#include "core/hle/kernel/kernel.h" namespace Kernel { struct AddressMapping; -} +class Process; +} // namespace Kernel //////////////////////////////////////////////////////////////////////////////////////////////////// // Loader namespace @@ -92,10 +94,11 @@ public: virtual FileType GetFileType() = 0; /** - * Load the application - * @return ResultStatus result of function + * Load the application and return the created Process instance + * @param process The newly created process. + * @return The status result of the operation. */ - virtual ResultStatus Load() = 0; + virtual ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) = 0; /** * Loads the system mode that this application needs. @@ -206,4 +209,4 @@ extern const std::initializer_list<Kernel::AddressMapping> default_address_mappi */ std::unique_ptr<AppLoader> GetLoader(const std::string& filename); -} // namespace +} // namespace Loader diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 5107135f9..66bc5823d 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -67,9 +67,9 @@ std::pair<boost::optional<u32>, ResultStatus> AppLoader_NCCH::LoadKernelSystemMo ResultStatus::Success); } -ResultStatus AppLoader_NCCH::LoadExec() { - using Kernel::SharedPtr; +ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr<Kernel::Process>& process) { using Kernel::CodeSet; + using Kernel::SharedPtr; if (!is_loaded) return ResultStatus::ErrorNotLoaded; @@ -107,16 +107,15 @@ ResultStatus AppLoader_NCCH::LoadExec() { codeset->entrypoint = codeset->code.addr; codeset->memory = std::make_shared<std::vector<u8>>(std::move(code)); - Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); - Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table); + process = Kernel::Process::Create(std::move(codeset)); // Attach a resource limit to the process based on the resource limit category - Kernel::g_current_process->resource_limit = + process->resource_limit = Kernel::ResourceLimit::GetForCategory(static_cast<Kernel::ResourceLimitCategory>( overlay_ncch->exheader_header.arm11_system_local_caps.resource_limit_category)); // Set the default CPU core for this process - Kernel::g_current_process->ideal_processor = + process->ideal_processor = overlay_ncch->exheader_header.arm11_system_local_caps.ideal_processor; // Copy data while converting endianness @@ -124,11 +123,11 @@ ResultStatus AppLoader_NCCH::LoadExec() { kernel_caps; std::copy_n(overlay_ncch->exheader_header.arm11_kernel_caps.descriptors, kernel_caps.size(), begin(kernel_caps)); - Kernel::g_current_process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size()); + process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size()); s32 priority = overlay_ncch->exheader_header.arm11_system_local_caps.priority; u32 stack_size = overlay_ncch->exheader_header.codeset_info.stack_size; - Kernel::g_current_process->Run(priority, stack_size); + process->Run(priority, stack_size); return ResultStatus::Success; } return ResultStatus::Error; @@ -151,7 +150,7 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() { } } -ResultStatus AppLoader_NCCH::Load() { +ResultStatus AppLoader_NCCH::Load(Kernel::SharedPtr<Kernel::Process>& process) { u64_le ncch_program_id; if (is_loaded) @@ -183,7 +182,7 @@ ResultStatus AppLoader_NCCH::Load() { is_loaded = true; // Set state to loaded - result = LoadExec(); // Load the executable into memory for booting + result = LoadExec(process); // Load the executable into memory for booting if (ResultStatus::Success != result) return result; diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 9b56465cb..09230ae33 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -33,7 +33,7 @@ public: return IdentifyType(file); } - ResultStatus Load() override; + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; /** * Loads the Exheader and returns the system mode for this application. @@ -62,9 +62,10 @@ public: private: /** * Loads .code section into memory for booting + * @param process The newly created process * @return ResultStatus result of function */ - ResultStatus LoadExec(); + ResultStatus LoadExec(Kernel::SharedPtr<Kernel::Process>& process); /// Reads the region lockout info in the SMDH and send it to CFG service void ParseRegionLockoutInfo(); diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 9b394f84b..847e69710 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -110,8 +110,8 @@ static u8* GetPointerFromVMA(VAddr vaddr) { /** * This function should only be called for virtual addreses with attribute `PageType::Special`. */ -static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { - for (const auto& region : current_page_table->special_regions) { +static MMIORegionPointer GetMMIOHandler(const PageTable& page_table, VAddr vaddr) { + for (const auto& region : page_table.special_regions) { if (vaddr >= region.base && vaddr < (region.base + region.size)) { return region.handler; } @@ -120,6 +120,11 @@ static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { return nullptr; // Should never happen } +static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { + const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; + return GetMMIOHandler(page_table, vaddr); +} + template <typename T> T ReadMMIO(MMIORegionPointer mmio_handler, VAddr addr); @@ -204,18 +209,20 @@ void Write(const VAddr vaddr, const T data) { } } -bool IsValidVirtualAddress(const VAddr vaddr) { - const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; +bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { + auto& page_table = process.vm_manager.page_table; + + const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS]; if (page_pointer) return true; - if (current_page_table->attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) + if (page_table.attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) return true; - if (current_page_table->attributes[vaddr >> PAGE_BITS] != PageType::Special) + if (page_table.attributes[vaddr >> PAGE_BITS] != PageType::Special) return false; - MMIORegionPointer mmio_region = GetMMIOHandler(vaddr); + MMIORegionPointer mmio_region = GetMMIOHandler(page_table, vaddr); if (mmio_region) { return mmio_region->IsValidAddress(vaddr); } @@ -223,6 +230,10 @@ bool IsValidVirtualAddress(const VAddr vaddr) { return false; } +bool IsValidVirtualAddress(const VAddr vaddr) { + return IsValidVirtualAddress(*Kernel::g_current_process, vaddr); +} + bool IsValidPhysicalAddress(const PAddr paddr) { return GetPhysicalPointer(paddr) != nullptr; } @@ -466,7 +477,7 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -489,13 +500,15 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::Flush); std::memcpy(dest_buffer, GetPointerFromVMA(current_vaddr), copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::Flush); GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, dest_buffer, copy_amount); break; } @@ -533,7 +546,7 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -556,13 +569,15 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::FlushAndInvalidate); std::memcpy(GetPointerFromVMA(current_vaddr), src_buffer, copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::FlushAndInvalidate); GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, src_buffer, copy_amount); break; } @@ -586,7 +601,7 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -608,13 +623,15 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::FlushAndInvalidate); std::memset(GetPointerFromVMA(current_vaddr), 0, copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::FlushAndInvalidate); GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, zeros.data(), copy_amount); break; } @@ -635,7 +652,7 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -659,13 +676,15 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::Flush); WriteBlock(dest_addr, GetPointerFromVMA(current_vaddr), copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount), + FlushMode::Flush); std::vector<u8> buffer(copy_amount); GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, buffer.data(), buffer.size()); @@ -678,8 +697,8 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { page_index++; page_offset = 0; - dest_addr += copy_amount; - src_addr += copy_amount; + dest_addr += static_cast<VAddr>(copy_amount); + src_addr += static_cast<VAddr>(copy_amount); remaining_size -= copy_amount; } } diff --git a/src/core/memory.h b/src/core/memory.h index 1865bfea0..347c08c78 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -12,6 +12,10 @@ #include "common/common_types.h" #include "core/mmio.h" +namespace Kernel { +class Process; +} + namespace Memory { /** @@ -185,7 +189,10 @@ enum : VAddr { void SetCurrentPageTable(PageTable* page_table); PageTable* GetCurrentPageTable(); +/// Determines if the given VAddr is valid for the specified process. +bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr); bool IsValidVirtualAddress(const VAddr addr); + bool IsValidPhysicalAddress(const PAddr addr); u8 Read8(VAddr addr); diff --git a/src/network/packet.cpp b/src/network/packet.cpp index cc60f2fbc..7e1a812f3 100644 --- a/src/network/packet.cpp +++ b/src/network/packet.cpp @@ -233,7 +233,7 @@ Packet& Packet::operator<<(double in_data) { Packet& Packet::operator<<(const char* in_data) { // First insert string length - u32 length = std::strlen(in_data); + u32 length = static_cast<u32>(std::strlen(in_data)); *this << length; // Then insert characters diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 5e9c4c2bf..1aac0daa2 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -4,6 +4,7 @@ set(SRCS core/arm/dyncom/arm_dyncom_vfp_tests.cpp core/file_sys/path_parser.cpp core/hle/kernel/hle_ipc.cpp + core/memory/memory.cpp glad.cpp tests.cpp ) diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index cfe0d503a..484713a92 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp @@ -3,30 +3,34 @@ // Refer to the license.txt file included. #include "core/core.h" +#include "core/hle/kernel/process.h" #include "core/memory.h" #include "core/memory_setup.h" #include "tests/core/arm/arm_test_common.h" namespace ArmTests { -static Memory::PageTable page_table; +static Memory::PageTable* page_table = nullptr; TestEnvironment::TestEnvironment(bool mutable_memory_) : mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) { - page_table.pointers.fill(nullptr); - page_table.attributes.fill(Memory::PageType::Unmapped); - page_table.cached_res_count.fill(0); + Kernel::g_current_process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); + page_table = &Kernel::g_current_process->vm_manager.page_table; - Memory::MapIoRegion(page_table, 0x00000000, 0x80000000, test_memory); - Memory::MapIoRegion(page_table, 0x80000000, 0x80000000, test_memory); + page_table->pointers.fill(nullptr); + page_table->attributes.fill(Memory::PageType::Unmapped); + page_table->cached_res_count.fill(0); - Memory::SetCurrentPageTable(&page_table); + Memory::MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory); + Memory::MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory); + + Memory::SetCurrentPageTable(page_table); } TestEnvironment::~TestEnvironment() { - Memory::UnmapRegion(page_table, 0x80000000, 0x80000000); - Memory::UnmapRegion(page_table, 0x00000000, 0x80000000); + Memory::UnmapRegion(*page_table, 0x80000000, 0x80000000); + Memory::UnmapRegion(*page_table, 0x00000000, 0x80000000); } void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) { diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp new file mode 100644 index 000000000..a01b896f7 --- /dev/null +++ b/src/tests/core/memory/memory.cpp @@ -0,0 +1,56 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <catch.hpp> +#include "core/hle/kernel/memory.h" +#include "core/hle/kernel/process.h" +#include "core/memory.h" + +TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { + SECTION("these regions should not be mapped on an empty process") { + auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::VRAM_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == false); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::TLS_AREA_VADDR) == false); + } + + SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { + auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); + Kernel::MapSharedPages(process->vm_manager); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); + } + + SECTION("special regions should be valid after mapping them") { + auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); + SECTION("VRAM") { + Kernel::HandleSpecialMapping(process->vm_manager, + {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::VRAM_VADDR) == true); + } + + SECTION("IO (Not yet implemented)") { + Kernel::HandleSpecialMapping( + process->vm_manager, {Memory::IO_AREA_VADDR, Memory::IO_AREA_SIZE, false, false}); + CHECK_FALSE(Memory::IsValidVirtualAddress(*process, Memory::IO_AREA_VADDR) == true); + } + + SECTION("DSP") { + Kernel::HandleSpecialMapping( + process->vm_manager, {Memory::DSP_RAM_VADDR, Memory::DSP_RAM_SIZE, false, false}); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::DSP_RAM_VADDR) == true); + } + } + + SECTION("Unmapping a VAddr should make it invalid") { + auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); + Kernel::MapSharedPages(process->vm_manager); + process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); + CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); + } +} diff --git a/src/video_core/geometry_pipeline.cpp b/src/video_core/geometry_pipeline.cpp index b146e2ecb..98ff2ccd3 100644 --- a/src/video_core/geometry_pipeline.cpp +++ b/src/video_core/geometry_pipeline.cpp @@ -105,7 +105,7 @@ public: DEBUG_ASSERT(need_index); // The number of vertex input is put to the uniform register - float24 vertex_num = float24::FromFloat32(val); + float24 vertex_num = float24::FromFloat32(static_cast<float>(val)); setup.uniforms.f[0] = Math::MakeVec(vertex_num, vertex_num, vertex_num, vertex_num); // The second uniform register and so on are used for receiving input vertices diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 06a905766..5770ae08f 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -267,9 +267,9 @@ void OpenGLState::Apply() const { for (size_t i = 0; i < clip_distance.size(); ++i) { if (clip_distance[i] != cur_state.clip_distance[i]) { if (clip_distance[i]) { - glEnable(GL_CLIP_DISTANCE0 + i); + glEnable(GL_CLIP_DISTANCE0 + static_cast<GLenum>(i)); } else { - glDisable(GL_CLIP_DISTANCE0 + i); + glDisable(GL_CLIP_DISTANCE0 + static_cast<GLenum>(i)); } } } |