2018-04-19 02:52:23 +00:00
|
|
|
using ChocolArm64.State;
|
2018-04-24 18:57:39 +00:00
|
|
|
using Ryujinx.Core.Logging;
|
2018-04-19 02:52:23 +00:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-04-21 19:07:16 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
using static Ryujinx.Core.OsHle.ErrorCode;
|
|
|
|
|
|
|
|
namespace Ryujinx.Core.OsHle.Kernel
|
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-04-21 19:07:16 +00:00
|
|
|
private const int MutexHasListenersMask = 0x40000000;
|
|
|
|
|
2018-04-19 02:52:23 +00:00
|
|
|
private void SvcArbitrateLock(AThreadState ThreadState)
|
|
|
|
{
|
2018-04-21 19:07:16 +00:00
|
|
|
int OwnerThreadHandle = (int)ThreadState.X0;
|
|
|
|
long MutexAddress = (long)ThreadState.X1;
|
|
|
|
int WaitThreadHandle = (int)ThreadState.X2;
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Ns.Log.PrintDebug(LogClass.KernelSvc,
|
|
|
|
"OwnerThreadHandle = " + OwnerThreadHandle.ToString("x8") + ", " +
|
|
|
|
"MutexAddress = " + MutexAddress .ToString("x16") + ", " +
|
|
|
|
"WaitThreadHandle = " + WaitThreadHandle .ToString("x8"));
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWordAddressUnaligned(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAlignment);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
KThread OwnerThread = Process.HandleTable.GetData<KThread>(OwnerThreadHandle);
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Ns.Log.PrintDebug(LogClass.KernelSvc, "lock tid: " + OwnerThread.ThreadId.ToString());
|
|
|
|
|
2018-04-19 02:52:23 +00:00
|
|
|
if (OwnerThread == null)
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid owner thread handle 0x{OwnerThreadHandle:x8}!");
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
KThread WaitThread = Process.HandleTable.GetData<KThread>(WaitThreadHandle);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (WaitThread == null)
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid requesting thread handle 0x{WaitThreadHandle:x8}!");
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
MutexLock(CurrThread, WaitThread, OwnerThreadHandle, WaitThreadHandle, MutexAddress);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SvcArbitrateUnlock(AThreadState ThreadState)
|
|
|
|
{
|
|
|
|
long MutexAddress = (long)ThreadState.X0;
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Ns.Log.PrintDebug(LogClass.KernelSvc, "MutexAddress = " + MutexAddress.ToString("x16"));
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWordAddressUnaligned(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAlignment);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MutexUnlock(Process.GetThread(ThreadState.Tpidr), MutexAddress))
|
|
|
|
{
|
|
|
|
Process.Scheduler.Yield(Process.GetThread(ThreadState.Tpidr));
|
|
|
|
}
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SvcWaitProcessWideKeyAtomic(AThreadState ThreadState)
|
|
|
|
{
|
2018-04-19 07:06:23 +00:00
|
|
|
long MutexAddress = (long)ThreadState.X0;
|
|
|
|
long CondVarAddress = (long)ThreadState.X1;
|
|
|
|
int ThreadHandle = (int)ThreadState.X2;
|
|
|
|
ulong Timeout = ThreadState.X3;
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Ns.Log.PrintDebug(LogClass.KernelSvc,
|
|
|
|
"OwnerThreadHandle = " + MutexAddress .ToString("x16") + ", " +
|
|
|
|
"MutexAddress = " + CondVarAddress.ToString("x16") + ", " +
|
|
|
|
"WaitThreadHandle = " + ThreadHandle .ToString("x8") + ", " +
|
|
|
|
"Timeout = " + Timeout .ToString("x16"));
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWordAddressUnaligned(MutexAddress))
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAlignment);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-19 02:52:23 +00:00
|
|
|
KThread Thread = Process.HandleTable.GetData<KThread>(ThreadHandle);
|
|
|
|
|
|
|
|
if (Thread == null)
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{ThreadHandle:x8}!");
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-19 07:06:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
MutexUnlock(CurrThread, MutexAddress);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (!CondVarWait(CurrThread, ThreadHandle, MutexAddress, CondVarAddress, Timeout))
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.Timeout);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
Process.Scheduler.Yield(Process.GetThread(ThreadState.Tpidr));
|
2018-04-19 07:06:23 +00:00
|
|
|
|
2018-04-19 02:52:23 +00:00
|
|
|
ThreadState.X0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SvcSignalProcessWideKey(AThreadState ThreadState)
|
|
|
|
{
|
|
|
|
long CondVarAddress = (long)ThreadState.X0;
|
|
|
|
int Count = (int)ThreadState.X1;
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
CondVarSignal(CondVarAddress, Count);
|
2018-04-19 02:52:23 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
private void MutexLock(
|
|
|
|
KThread CurrThread,
|
|
|
|
KThread WaitThread,
|
|
|
|
int OwnerThreadHandle,
|
|
|
|
int WaitThreadHandle,
|
|
|
|
long MutexAddress)
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
2018-04-21 19:07:16 +00:00
|
|
|
int MutexValue = Process.Memory.ReadInt32(MutexAddress);
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Ns.Log.PrintDebug(LogClass.KernelSvc, "MutexValue = " + MutexValue.ToString("x8"));
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (MutexValue != (OwnerThreadHandle | MutexHasListenersMask))
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
2018-04-21 19:07:16 +00:00
|
|
|
return;
|
2018-04-19 02:52:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
CurrThread.WaitHandle = WaitThreadHandle;
|
|
|
|
CurrThread.MutexAddress = MutexAddress;
|
|
|
|
|
|
|
|
InsertWaitingMutexThread(OwnerThreadHandle, WaitThread);
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
Process.Scheduler.EnterWait(CurrThread);
|
2018-04-19 02:52:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
private bool MutexUnlock(KThread CurrThread, long MutexAddress)
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
2018-04-21 19:07:16 +00:00
|
|
|
if (CurrThread == null)
|
2018-04-19 02:52:23 +00:00
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid mutex 0x{MutexAddress:x16}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
return false;
|
2018-04-19 02:52:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
lock (CurrThread)
|
|
|
|
{
|
|
|
|
//This is the new thread that will not own the mutex.
|
|
|
|
//If no threads are waiting for the lock, then it should be null.
|
|
|
|
KThread OwnerThread = CurrThread.NextMutexThread;
|
|
|
|
|
|
|
|
while (OwnerThread != null && OwnerThread.MutexAddress != MutexAddress)
|
|
|
|
{
|
|
|
|
OwnerThread = OwnerThread.NextMutexThread;
|
|
|
|
}
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
UpdateMutexOwner(CurrThread, OwnerThread, MutexAddress);
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
CurrThread.NextMutexThread = null;
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
CurrThread.UpdatePriority();
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
if (OwnerThread != null)
|
|
|
|
{
|
|
|
|
int HasListeners = OwnerThread.NextMutexThread != null ? MutexHasListenersMask : 0;
|
|
|
|
|
|
|
|
Process.Memory.WriteInt32(MutexAddress, HasListeners | OwnerThread.WaitHandle);
|
|
|
|
|
|
|
|
OwnerThread.WaitHandle = 0;
|
|
|
|
OwnerThread.MutexAddress = 0;
|
|
|
|
OwnerThread.CondVarAddress = 0;
|
|
|
|
|
|
|
|
OwnerThread.MutexOwner = null;
|
|
|
|
|
|
|
|
OwnerThread.UpdatePriority();
|
|
|
|
|
|
|
|
Process.Scheduler.WakeUp(OwnerThread);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Process.Memory.WriteInt32(MutexAddress, 0);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CondVarWait(
|
|
|
|
KThread WaitThread,
|
|
|
|
int WaitThreadHandle,
|
|
|
|
long MutexAddress,
|
|
|
|
long CondVarAddress,
|
|
|
|
ulong Timeout)
|
|
|
|
{
|
|
|
|
WaitThread.WaitHandle = WaitThreadHandle;
|
|
|
|
WaitThread.MutexAddress = MutexAddress;
|
|
|
|
WaitThread.CondVarAddress = CondVarAddress;
|
|
|
|
|
|
|
|
lock (CondVarLock)
|
|
|
|
{
|
|
|
|
KThread CurrThread = Process.ThreadArbiterList;
|
|
|
|
|
|
|
|
if (CurrThread != null)
|
|
|
|
{
|
|
|
|
bool DoInsert = CurrThread != WaitThread;
|
|
|
|
|
|
|
|
while (CurrThread.NextCondVarThread != null)
|
|
|
|
{
|
|
|
|
if (CurrThread.NextCondVarThread.ActualPriority < WaitThread.ActualPriority)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrThread = CurrThread.NextCondVarThread;
|
|
|
|
|
|
|
|
DoInsert &= CurrThread != WaitThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Only insert if the node doesn't already exist in the list.
|
|
|
|
//This prevents circular references.
|
|
|
|
if (DoInsert)
|
|
|
|
{
|
|
|
|
if (WaitThread.NextCondVarThread != null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitThread.NextCondVarThread = CurrThread.NextCondVarThread;
|
|
|
|
CurrThread.NextCondVarThread = WaitThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Process.ThreadArbiterList = WaitThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Timeout != ulong.MaxValue)
|
|
|
|
{
|
|
|
|
return Process.Scheduler.EnterWait(WaitThread, NsTimeConverter.GetTimeMs(Timeout));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-26 02:11:26 +00:00
|
|
|
Process.Scheduler.EnterWait(WaitThread);
|
|
|
|
|
|
|
|
return true;
|
2018-04-21 19:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CondVarSignal(long CondVarAddress, int Count)
|
|
|
|
{
|
|
|
|
lock (CondVarLock)
|
|
|
|
{
|
|
|
|
KThread PrevThread = null;
|
|
|
|
KThread CurrThread = Process.ThreadArbiterList;
|
|
|
|
|
|
|
|
while (CurrThread != null && (Count == -1 || Count > 0))
|
|
|
|
{
|
|
|
|
if (CurrThread.CondVarAddress == CondVarAddress)
|
|
|
|
{
|
|
|
|
if (PrevThread != null)
|
|
|
|
{
|
|
|
|
PrevThread.NextCondVarThread = CurrThread.NextCondVarThread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Process.ThreadArbiterList = CurrThread.NextCondVarThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrThread.NextCondVarThread = null;
|
|
|
|
|
|
|
|
AcquireMutexValue(CurrThread.MutexAddress);
|
|
|
|
|
|
|
|
int MutexValue = Process.Memory.ReadInt32(CurrThread.MutexAddress);
|
|
|
|
|
|
|
|
if (MutexValue == 0)
|
|
|
|
{
|
|
|
|
//Give the lock to this thread.
|
|
|
|
Process.Memory.WriteInt32(CurrThread.MutexAddress, CurrThread.WaitHandle);
|
|
|
|
|
|
|
|
CurrThread.WaitHandle = 0;
|
|
|
|
CurrThread.MutexAddress = 0;
|
|
|
|
CurrThread.CondVarAddress = 0;
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
CurrThread.MutexOwner?.UpdatePriority();
|
2018-04-21 19:07:16 +00:00
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
CurrThread.MutexOwner = null;
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
Process.Scheduler.WakeUp(CurrThread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Wait until the lock is released.
|
2018-04-26 02:11:26 +00:00
|
|
|
MutexValue &= ~MutexHasListenersMask;
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
InsertWaitingMutexThread(MutexValue, CurrThread);
|
|
|
|
|
|
|
|
MutexValue |= MutexHasListenersMask;
|
|
|
|
|
|
|
|
Process.Memory.WriteInt32(CurrThread.MutexAddress, MutexValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseMutexValue(CurrThread.MutexAddress);
|
|
|
|
|
|
|
|
Count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrevThread = CurrThread;
|
|
|
|
CurrThread = CurrThread.NextCondVarThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InsertWaitingMutexThread(int OwnerThreadHandle, KThread WaitThread)
|
|
|
|
{
|
|
|
|
KThread OwnerThread = Process.HandleTable.GetData<KThread>(OwnerThreadHandle);
|
|
|
|
|
|
|
|
if (OwnerThread == null)
|
|
|
|
{
|
2018-04-24 18:57:39 +00:00
|
|
|
Ns.Log.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{OwnerThreadHandle:x8}!");
|
2018-04-21 19:07:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitThread.MutexOwner = OwnerThread;
|
|
|
|
|
|
|
|
lock (OwnerThread)
|
|
|
|
{
|
|
|
|
KThread CurrThread = OwnerThread;
|
|
|
|
|
|
|
|
while (CurrThread.NextMutexThread != null)
|
|
|
|
{
|
|
|
|
if (CurrThread == WaitThread)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrThread.NextMutexThread.ActualPriority < WaitThread.ActualPriority)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrThread = CurrThread.NextMutexThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrThread != WaitThread)
|
|
|
|
{
|
|
|
|
if (WaitThread.NextCondVarThread != null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitThread.NextMutexThread = CurrThread.NextMutexThread;
|
|
|
|
CurrThread.NextMutexThread = WaitThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnerThread.UpdatePriority();
|
|
|
|
}
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
private void UpdateMutexOwner(KThread CurrThread, KThread NewOwner, long MutexAddress)
|
|
|
|
{
|
|
|
|
//Go through all threads waiting for the mutex,
|
|
|
|
//and update the MutexOwner field to point to the new owner.
|
|
|
|
CurrThread = CurrThread.NextMutexThread;
|
|
|
|
|
|
|
|
while (CurrThread != null)
|
|
|
|
{
|
|
|
|
if (CurrThread.MutexAddress == MutexAddress)
|
|
|
|
{
|
|
|
|
CurrThread.MutexOwner = NewOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrThread = CurrThread.NextMutexThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 19:07:16 +00:00
|
|
|
private void AcquireMutexValue(long MutexAddress)
|
|
|
|
{
|
|
|
|
while (!Process.Memory.AcquireAddress(MutexAddress))
|
|
|
|
{
|
|
|
|
Thread.Yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ReleaseMutexValue(long MutexAddress)
|
|
|
|
{
|
|
|
|
Process.Memory.ReleaseAddress(MutexAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool IsPointingInsideKernel(long Address)
|
|
|
|
{
|
|
|
|
return ((ulong)Address + 0x1000000000) < 0xffffff000;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool IsWordAddressUnaligned(long Address)
|
|
|
|
{
|
|
|
|
return (Address & 3) != 0;
|
2018-04-19 02:52:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|