Merge pull request #1343 from lioncash/mutex
kernel/svc: Handle invalid address cases within svcArbitrateLock() and svcArbitrateUnlock()
This commit is contained in:
commit
733c47623b
2 changed files with 10 additions and 2 deletions
|
@ -62,7 +62,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
|
||||||
Handle requesting_thread_handle) {
|
Handle requesting_thread_handle) {
|
||||||
// The mutex address must be 4-byte aligned
|
// The mutex address must be 4-byte aligned
|
||||||
if ((address % sizeof(u32)) != 0) {
|
if ((address % sizeof(u32)) != 0) {
|
||||||
return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress);
|
return ERR_INVALID_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
|
SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
|
||||||
|
@ -100,7 +100,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
|
||||||
ResultCode Mutex::Release(VAddr address) {
|
ResultCode Mutex::Release(VAddr address) {
|
||||||
// The mutex address must be 4-byte aligned
|
// The mutex address must be 4-byte aligned
|
||||||
if ((address % sizeof(u32)) != 0) {
|
if ((address % sizeof(u32)) != 0) {
|
||||||
return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress);
|
return ERR_INVALID_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address);
|
auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address);
|
||||||
|
|
|
@ -280,6 +280,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
|
||||||
"requesting_current_thread_handle=0x{:08X}",
|
"requesting_current_thread_handle=0x{:08X}",
|
||||||
holding_thread_handle, mutex_addr, requesting_thread_handle);
|
holding_thread_handle, mutex_addr, requesting_thread_handle);
|
||||||
|
|
||||||
|
if (Memory::IsKernelVirtualAddress(mutex_addr)) {
|
||||||
|
return ERR_INVALID_ADDRESS_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
|
auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
|
||||||
return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle,
|
return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle,
|
||||||
requesting_thread_handle);
|
requesting_thread_handle);
|
||||||
|
@ -289,6 +293,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
|
||||||
static ResultCode ArbitrateUnlock(VAddr mutex_addr) {
|
static ResultCode ArbitrateUnlock(VAddr mutex_addr) {
|
||||||
LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr);
|
LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr);
|
||||||
|
|
||||||
|
if (Memory::IsKernelVirtualAddress(mutex_addr)) {
|
||||||
|
return ERR_INVALID_ADDRESS_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
return Mutex::Release(mutex_addr);
|
return Mutex::Release(mutex_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue