From f9c9ce20050a2aad66d40d0f49bf97065b624848 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 3 Feb 2018 13:29:18 -0500 Subject: ArbitrateLock: Assert that requesting_thread is current_thread. --- src/core/hle/kernel/svc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4c0276cf0..f516927cd 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -263,6 +263,7 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, SharedPtr requesting_thread = g_handle_table.Get(requesting_thread_handle); ASSERT(requesting_thread); + ASSERT(requesting_thread == GetCurrentThread()); SharedPtr mutex = g_object_address_table.Get(mutex_addr); if (!mutex) { -- cgit v1.2.3 From 647364db8fa7792b640a035d410feb12e3fde848 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 3 Feb 2018 13:36:54 -0500 Subject: svc: SharedMemory size should be 64-bits and cleanup. --- src/core/hle/kernel/shared_memory.cpp | 2 +- src/core/hle/kernel/shared_memory.h | 4 ++-- src/core/hle/kernel/svc.cpp | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index f8aa429dc..835fc710b 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -14,7 +14,7 @@ namespace Kernel { SharedMemory::SharedMemory() {} SharedMemory::~SharedMemory() {} -SharedPtr SharedMemory::Create(SharedPtr owner_process, u32 size, +SharedPtr SharedMemory::Create(SharedPtr owner_process, u64 size, MemoryPermission permissions, MemoryPermission other_permissions, VAddr address, MemoryRegion region, std::string name) { diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index e948819c0..86f818e90 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -39,7 +39,7 @@ public: * linear heap. * @param name Optional object name, used for debugging purposes. */ - static SharedPtr Create(SharedPtr owner_process, u32 size, + static SharedPtr Create(SharedPtr owner_process, u64 size, MemoryPermission permissions, MemoryPermission other_permissions, VAddr address = 0, MemoryRegion region = MemoryRegion::BASE, @@ -116,7 +116,7 @@ public: /// Offset into the backing block for this shared memory. size_t backing_block_offset; /// Size of the memory block. Page-aligned. - u32 size; + u64 size; /// Permission restrictions applied to the process which created the block. MemoryPermission permissions; /// Permission restrictions applied to other processes mapping the block. diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index f516927cd..4e395ed31 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -416,8 +416,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s "called, shared_memory_handle=0x%08X, addr=0x%llx, size=0x%llx, permissions=0x%08X", shared_memory_handle, addr, size, permissions); - SharedPtr shared_memory = - Kernel::g_handle_table.Get(shared_memory_handle); + SharedPtr shared_memory = g_handle_table.Get(shared_memory_handle); if (!shared_memory) { return ERR_INVALID_HANDLE; } @@ -432,7 +431,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s case MemoryPermission::WriteExecute: case MemoryPermission::ReadWriteExecute: case MemoryPermission::DontCare: - return shared_memory->Map(Kernel::g_current_process.get(), addr, permissions_type, + return shared_memory->Map(g_current_process.get(), addr, permissions_type, MemoryPermission::DontCare); default: LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); @@ -739,13 +738,14 @@ static ResultCode SetThreadCoreMask(u64, u64, u64) { return RESULT_SUCCESS; } -static ResultCode CreateSharedMemory(Handle* handle, u64 sz, u32 local_permissions, +static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permissions, u32 remote_permissions) { - LOG_TRACE(Kernel_SVC, "called, sz=0x%llx, localPerms=0x%08x, remotePerms=0x%08x", sz, + LOG_TRACE(Kernel_SVC, "called, size=0x%llx, localPerms=0x%08x, remotePerms=0x%08x", size, local_permissions, remote_permissions); - auto sharedMemHandle = SharedMemory::Create( - g_handle_table.Get(KernelHandle::CurrentProcess), sz, - (Kernel::MemoryPermission)local_permissions, (Kernel::MemoryPermission)remote_permissions); + auto sharedMemHandle = + SharedMemory::Create(g_handle_table.Get(KernelHandle::CurrentProcess), size, + static_cast(local_permissions), + static_cast(remote_permissions)); CASCADE_RESULT(*handle, g_handle_table.Create(sharedMemHandle)); return RESULT_SUCCESS; -- cgit v1.2.3 From 0b6b147939c3abd1f98ecf639fb1ee51c5a445a1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 4 Feb 2018 12:30:51 -0500 Subject: WaitProcessWideKeyAtomic: Handle case where condition variable was already created. --- src/core/hle/kernel/condition_variable.cpp | 3 +-- src/core/hle/kernel/condition_variable.h | 4 +--- src/core/hle/kernel/svc.cpp | 23 +++++++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/core/hle/kernel/condition_variable.cpp b/src/core/hle/kernel/condition_variable.cpp index 561666384..a786d7f74 100644 --- a/src/core/hle/kernel/condition_variable.cpp +++ b/src/core/hle/kernel/condition_variable.cpp @@ -15,13 +15,12 @@ ConditionVariable::ConditionVariable() {} ConditionVariable::~ConditionVariable() {} ResultVal> ConditionVariable::Create(VAddr guest_addr, - VAddr mutex_addr, std::string name) { SharedPtr condition_variable(new ConditionVariable); condition_variable->name = std::move(name); condition_variable->guest_addr = guest_addr; - condition_variable->mutex_addr = mutex_addr; + condition_variable->mutex_addr = 0; // Condition variables are referenced by guest address, so track this in the kernel g_object_address_table.Insert(guest_addr, condition_variable); diff --git a/src/core/hle/kernel/condition_variable.h b/src/core/hle/kernel/condition_variable.h index 0d54031cb..1c9f06769 100644 --- a/src/core/hle/kernel/condition_variable.h +++ b/src/core/hle/kernel/condition_variable.h @@ -19,12 +19,10 @@ public: * Creates a condition variable. * @param guest_addr Address of the object tracking the condition variable in guest memory. If * specified, this condition variable will update the guest object when its state changes. - * @param mutex_addr Optional address of a guest mutex associated with this condition variable, - * used by the OS for implementing events. * @param name Optional name of condition variable. * @return The created condition variable. */ - static ResultVal> Create(VAddr guest_addr, VAddr mutex_addr = 0, + static ResultVal> Create(VAddr guest_addr, std::string name = "Unknown"); std::string GetTypeName() const override { diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4e395ed31..0705b264d 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -612,20 +612,29 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var mutex->name = Common::StringFromFormat("mutex-%llx", mutex_addr); } - ASSERT(mutex->GetOwnerHandle() == thread_handle); - SharedPtr condition_variable = g_object_address_table.Get(condition_variable_addr); if (!condition_variable) { // Create a new condition_variable for the specified address if one does not already exist - condition_variable = - ConditionVariable::Create(condition_variable_addr, mutex_addr).Unwrap(); + condition_variable = ConditionVariable::Create(condition_variable_addr).Unwrap(); condition_variable->name = Common::StringFromFormat("condition-variable-%llx", condition_variable_addr); } - ASSERT(condition_variable->GetAvailableCount() == 0); - ASSERT(condition_variable->mutex_addr == mutex_addr); + if (condition_variable->mutex_addr) { + // Previously created the ConditionVariable using WaitProcessWideKeyAtomic, verify + // everything is correct + ASSERT(condition_variable->mutex_addr == mutex_addr); + } else { + // Previously created the ConditionVariable using SignalProcessWideKey, set the mutex + // associated with it + condition_variable->mutex_addr = mutex_addr; + } + + if (mutex->GetOwnerHandle()) { + // Release the mutex if the current thread is holding it + mutex->Release(thread.get()); + } auto wakeup_callback = [mutex, nano_seconds](ThreadWakeupReason reason, SharedPtr thread, @@ -667,8 +676,6 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var CASCADE_CODE( WaitSynchronization1(condition_variable, thread.get(), nano_seconds, wakeup_callback)); - mutex->Release(thread.get()); - return RESULT_SUCCESS; } -- cgit v1.2.3 From 42fc437268f10c96752abd118076aa998b5f9ee8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 4 Feb 2018 12:34:45 -0500 Subject: GetInfo: Implement IsCurrentProcessBeingDebugged. --- src/core/hle/kernel/svc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 0705b264d..4d20ef134 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -332,6 +332,9 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) case GetInfoType::TotalHeapUsage: *result = vm_manager.GetTotalHeapUsage(); break; + case GetInfoType::IsCurrentProcessBeingDebugged: + *result = 0; + break; case GetInfoType::RandomEntropy: *result = 0; break; -- cgit v1.2.3