2018-02-04 18:08:20 -05:00
|
|
|
using ChocolArm64;
|
2018-02-25 20:14:58 -05:00
|
|
|
using ChocolArm64.Events;
|
2018-02-04 18:08:20 -05:00
|
|
|
using ChocolArm64.Memory;
|
2018-04-22 00:21:49 -04:00
|
|
|
using ChocolArm64.State;
|
2018-08-16 19:47:36 -04:00
|
|
|
using Ryujinx.HLE.Exceptions;
|
|
|
|
using Ryujinx.HLE.HOS.Diagnostics;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Nv;
|
|
|
|
using Ryujinx.HLE.HOS.SystemState;
|
2018-06-10 20:46:42 -04:00
|
|
|
using Ryujinx.HLE.Loaders;
|
|
|
|
using Ryujinx.HLE.Loaders.Executables;
|
2018-08-02 16:14:49 -04:00
|
|
|
using Ryujinx.HLE.Loaders.Npdm;
|
2018-06-10 20:46:42 -04:00
|
|
|
using Ryujinx.HLE.Logging;
|
2018-08-16 19:47:36 -04:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
2018-07-17 15:14:27 -04:00
|
|
|
using System.IO;
|
2018-04-22 00:21:49 -04:00
|
|
|
using System.Text;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
class Process : IDisposable
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-13 20:24:17 -04:00
|
|
|
private const int TickFreq = 19_200_000;
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
public Switch Device { get; private set; }
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public bool NeedsHbAbi { get; private set; }
|
|
|
|
|
|
|
|
public long HbAbiDataPosition { get; private set; }
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
public int ProcessId { get; private set; }
|
|
|
|
|
2018-02-27 18:45:07 -05:00
|
|
|
private ATranslator Translator;
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
public AMemory Memory { get; private set; }
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
public KMemoryManager MemoryManager { get; private set; }
|
|
|
|
|
|
|
|
private List<KTlsPageManager> TlsPages;
|
|
|
|
|
2018-02-13 21:43:08 -05:00
|
|
|
public KProcessScheduler Scheduler { get; private set; }
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-05-14 02:01:10 -04:00
|
|
|
public List<KThread> ThreadArbiterList { get; private set; }
|
2018-05-12 23:22:42 -04:00
|
|
|
|
2018-05-14 02:01:10 -04:00
|
|
|
public object ThreadSyncLock { get; private set; }
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
public Npdm MetaData { get; private set; }
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public KProcessHandleTable HandleTable { get; private set; }
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public AppletStateMgr AppletState { get; private set; }
|
|
|
|
|
2018-02-14 00:43:21 -05:00
|
|
|
private SvcHandler SvcHandler;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
private ConcurrentDictionary<long, KThread> Threads;
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
private List<Executable> Executables;
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
private Dictionary<long, string> SymbolTable;
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
private long ImageBase;
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private bool ShouldDispose;
|
|
|
|
|
|
|
|
private bool Disposed;
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
public Process(Switch Device, KProcessScheduler Scheduler, int ProcessId, Npdm MetaData)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
this.Device = Device;
|
2018-04-18 22:52:23 -04:00
|
|
|
this.Scheduler = Scheduler;
|
2018-08-15 14:59:51 -04:00
|
|
|
this.MetaData = MetaData;
|
2018-02-04 18:08:20 -05:00
|
|
|
this.ProcessId = ProcessId;
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
Memory = new AMemory(Device.Memory.RamPointer);
|
2018-08-15 14:59:51 -04:00
|
|
|
|
|
|
|
MemoryManager = new KMemoryManager(this);
|
|
|
|
|
|
|
|
TlsPages = new List<KTlsPageManager>();
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-05-14 02:01:10 -04:00
|
|
|
ThreadArbiterList = new List<KThread>();
|
|
|
|
|
|
|
|
ThreadSyncLock = new object();
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
HandleTable = new KProcessHandleTable();
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
AppletState = new AppletStateMgr();
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
SvcHandler = new SvcHandler(Device, this);
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
Threads = new ConcurrentDictionary<long, KThread>();
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
Executables = new List<Executable>();
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
ImageBase = MemoryManager.CodeRegionStart;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-02-06 18:28:32 -05:00
|
|
|
public void LoadProgram(IExecutable Program)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Disposed)
|
|
|
|
{
|
|
|
|
throw new ObjectDisposedException(nameof(Process));
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
Device.Log.PrintInfo(LogClass.Loader, $"Image base at 0x{ImageBase:x16}.");
|
2018-02-17 16:06:11 -05:00
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
Executable Executable = new Executable(Program, MemoryManager, Memory, ImageBase);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Executables.Add(Executable);
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
ImageBase = IntUtils.AlignUp(Executable.ImageEnd, KMemoryManager.PageSize);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetEmptyArgs()
|
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
//TODO: This should be part of Run.
|
2018-08-15 14:59:51 -04:00
|
|
|
ImageBase += KMemoryManager.PageSize;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public bool Run(bool NeedsHbAbi = false)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Disposed)
|
|
|
|
{
|
|
|
|
throw new ObjectDisposedException(nameof(Process));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.NeedsHbAbi = NeedsHbAbi;
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
if (Executables.Count == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
MakeSymbolTable();
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
long MainStackTop = MemoryManager.CodeRegionEnd - KMemoryManager.PageSize;
|
|
|
|
|
|
|
|
long MainStackSize = 1 * 1024 * 1024;
|
2018-04-04 18:29:34 -04:00
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
long MainStackBottom = MainStackTop - MainStackSize;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
MemoryManager.HleMapCustom(
|
|
|
|
MainStackBottom,
|
|
|
|
MainStackSize,
|
|
|
|
MemoryState.MappedMemory,
|
|
|
|
MemoryPermission.ReadAndWrite);
|
|
|
|
|
|
|
|
int Handle = MakeThread(Executables[0].ImageBase, MainStackTop, 0, 44, 0);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
if (Handle == -1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
KThread MainThread = HandleTable.GetData<KThread>(Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
if (NeedsHbAbi)
|
2018-02-23 19:59:38 -05:00
|
|
|
{
|
2018-08-15 14:59:51 -04:00
|
|
|
HbAbiDataPosition = IntUtils.AlignUp(Executables[0].ImageEnd, KMemoryManager.PageSize);
|
|
|
|
|
|
|
|
const long HbAbiDataSize = KMemoryManager.PageSize;
|
|
|
|
|
|
|
|
MemoryManager.HleMapCustom(
|
|
|
|
HbAbiDataPosition,
|
|
|
|
HbAbiDataSize,
|
|
|
|
MemoryState.MappedMemory,
|
|
|
|
MemoryPermission.ReadAndWrite);
|
2018-02-23 19:59:38 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
string SwitchPath = Device.FileSystem.SystemPathToSwitchPath(Executables[0].FilePath);
|
2018-07-17 15:14:27 -04:00
|
|
|
|
|
|
|
Homebrew.WriteHbAbiData(Memory, HbAbiDataPosition, Handle, SwitchPath);
|
2018-02-25 20:44:30 -05:00
|
|
|
|
|
|
|
MainThread.Thread.ThreadState.X0 = (ulong)HbAbiDataPosition;
|
2018-02-23 19:59:38 -05:00
|
|
|
MainThread.Thread.ThreadState.X1 = ulong.MaxValue;
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:43:08 -05:00
|
|
|
Scheduler.StartThread(MainThread);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MakeThread(
|
|
|
|
long EntryPoint,
|
|
|
|
long StackTop,
|
|
|
|
long ArgsPtr,
|
|
|
|
int Priority,
|
|
|
|
int ProcessorId)
|
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Disposed)
|
2018-02-13 21:43:08 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
throw new ObjectDisposedException(nameof(Process));
|
2018-02-13 21:43:08 -05:00
|
|
|
}
|
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
AThread CpuThread = new AThread(GetTranslator(), Memory, EntryPoint);
|
2018-04-18 22:52:23 -04:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
long Tpidr = GetFreeTls();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
int ThreadId = (int)((Tpidr - MemoryManager.TlsIoRegionStart) / 0x200) + 1;
|
2018-06-26 00:09:32 -04:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
KThread Thread = new KThread(CpuThread, this, ProcessorId, Priority, ThreadId);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
Thread.LastPc = EntryPoint;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
int Handle = HandleTable.OpenHandle(Thread);
|
2018-02-27 18:45:07 -05:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
CpuThread.ThreadState.CntfrqEl0 = TickFreq;
|
|
|
|
CpuThread.ThreadState.Tpidr = Tpidr;
|
2018-04-18 22:52:23 -04:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
CpuThread.ThreadState.X0 = (ulong)ArgsPtr;
|
|
|
|
CpuThread.ThreadState.X1 = (ulong)Handle;
|
|
|
|
CpuThread.ThreadState.X31 = (ulong)StackTop;
|
2018-04-18 22:52:23 -04:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
CpuThread.ThreadState.Break += BreakHandler;
|
|
|
|
CpuThread.ThreadState.SvcCall += SvcHandler.SvcCall;
|
|
|
|
CpuThread.ThreadState.Undefined += UndefinedHandler;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
CpuThread.WorkFinished += ThreadFinished;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-04-21 15:07:16 -04:00
|
|
|
Threads.TryAdd(CpuThread.ThreadState.Tpidr, Thread);
|
2018-02-13 21:43:08 -05:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
return Handle;
|
|
|
|
}
|
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
private long GetFreeTls()
|
|
|
|
{
|
|
|
|
long Position;
|
|
|
|
|
|
|
|
lock (TlsPages)
|
|
|
|
{
|
|
|
|
for (int Index = 0; Index < TlsPages.Count; Index++)
|
|
|
|
{
|
|
|
|
if (TlsPages[Index].TryGetFreeTlsAddr(out Position))
|
|
|
|
{
|
|
|
|
return Position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long PagePosition = MemoryManager.HleMapTlsPage();
|
|
|
|
|
|
|
|
KTlsPageManager TlsPage = new KTlsPageManager(PagePosition);
|
|
|
|
|
|
|
|
TlsPages.Add(TlsPage);
|
|
|
|
|
|
|
|
TlsPage.TryGetFreeTlsAddr(out Position);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Position;
|
|
|
|
}
|
|
|
|
|
2018-02-25 20:14:58 -05:00
|
|
|
private void BreakHandler(object sender, AInstExceptionEventArgs e)
|
2018-02-10 08:24:16 -05:00
|
|
|
{
|
|
|
|
throw new GuestBrokeExecutionException();
|
|
|
|
}
|
|
|
|
|
2018-02-25 20:14:58 -05:00
|
|
|
private void UndefinedHandler(object sender, AInstUndefinedEventArgs e)
|
2018-02-10 12:20:46 -05:00
|
|
|
{
|
|
|
|
throw new UndefinedInstructionException(e.Position, e.RawOpCode);
|
|
|
|
}
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
private void MakeSymbolTable()
|
2018-02-25 20:14:58 -05:00
|
|
|
{
|
2018-04-22 00:21:49 -04:00
|
|
|
SymbolTable = new Dictionary<long, string>();
|
2018-02-25 20:14:58 -05:00
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
foreach (Executable Exe in Executables)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<long, string> KV in Exe.SymbolTable)
|
2018-02-25 20:14:58 -05:00
|
|
|
{
|
2018-04-22 00:21:49 -04:00
|
|
|
SymbolTable.TryAdd(Exe.ImageBase + KV.Key, KV.Value);
|
2018-02-25 20:14:58 -05:00
|
|
|
}
|
2018-04-22 00:21:49 -04:00
|
|
|
}
|
|
|
|
}
|
2018-02-25 20:14:58 -05:00
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
private ATranslator GetTranslator()
|
|
|
|
{
|
|
|
|
if (Translator == null)
|
|
|
|
{
|
2018-02-25 20:14:58 -05:00
|
|
|
Translator = new ATranslator(SymbolTable);
|
|
|
|
|
|
|
|
Translator.CpuTrace += CpuTraceHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Translator;
|
|
|
|
}
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
public void EnableCpuTracing()
|
|
|
|
{
|
|
|
|
Translator.EnableCpuTrace = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisableCpuTracing()
|
|
|
|
{
|
|
|
|
Translator.EnableCpuTrace = false;
|
|
|
|
}
|
|
|
|
|
2018-02-25 20:14:58 -05:00
|
|
|
private void CpuTraceHandler(object sender, ACpuTraceEventArgs e)
|
|
|
|
{
|
2018-03-03 22:06:44 -05:00
|
|
|
string NsoName = string.Empty;
|
|
|
|
|
|
|
|
for (int Index = Executables.Count - 1; Index >= 0; Index--)
|
|
|
|
{
|
|
|
|
if (e.Position >= Executables[Index].ImageBase)
|
|
|
|
{
|
|
|
|
NsoName = $"{(e.Position - Executables[Index].ImageBase):x16}";
|
2018-04-04 18:29:34 -04:00
|
|
|
|
2018-03-03 22:06:44 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
Device.Log.PrintDebug(LogClass.Cpu, $"Executing at 0x{e.Position:x16} {e.SubName} {NsoName}");
|
2018-02-25 20:14:58 -05:00
|
|
|
}
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
public void PrintStackTrace(AThreadState ThreadState)
|
2018-03-02 20:49:17 -05:00
|
|
|
{
|
2018-04-22 00:21:49 -04:00
|
|
|
long[] Positions = ThreadState.GetCallStack();
|
|
|
|
|
|
|
|
StringBuilder Trace = new StringBuilder();
|
|
|
|
|
|
|
|
Trace.AppendLine("Guest stack trace:");
|
|
|
|
|
|
|
|
foreach (long Position in Positions)
|
|
|
|
{
|
|
|
|
if (!SymbolTable.TryGetValue(Position, out string SubName))
|
|
|
|
{
|
|
|
|
SubName = $"Sub{Position:x16}";
|
|
|
|
}
|
2018-05-22 16:40:02 -04:00
|
|
|
else if (SubName.StartsWith("_Z"))
|
|
|
|
{
|
|
|
|
SubName = Demangler.Parse(SubName);
|
|
|
|
}
|
2018-04-22 00:21:49 -04:00
|
|
|
|
|
|
|
Trace.AppendLine(" " + SubName + " (" + GetNsoNameAndAddress(Position) + ")");
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
Device.Log.PrintInfo(LogClass.Cpu, Trace.ToString());
|
2018-03-02 20:49:17 -05:00
|
|
|
}
|
|
|
|
|
2018-04-22 00:21:49 -04:00
|
|
|
private string GetNsoNameAndAddress(long Position)
|
2018-03-02 20:49:17 -05:00
|
|
|
{
|
2018-04-22 00:21:49 -04:00
|
|
|
string Name = string.Empty;
|
|
|
|
|
|
|
|
for (int Index = Executables.Count - 1; Index >= 0; Index--)
|
|
|
|
{
|
|
|
|
if (Position >= Executables[Index].ImageBase)
|
|
|
|
{
|
|
|
|
long Offset = Position - Executables[Index].ImageBase;
|
|
|
|
|
|
|
|
Name = $"{Executables[Index].Name}:{Offset:x8}";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
2018-03-02 20:49:17 -05:00
|
|
|
}
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
private void ThreadFinished(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is AThread Thread)
|
|
|
|
{
|
2018-04-25 23:07:12 -04:00
|
|
|
Threads.TryRemove(Thread.ThreadState.Tpidr, out KThread KernelThread);
|
2018-04-18 22:52:23 -04:00
|
|
|
|
|
|
|
Scheduler.RemoveThread(KernelThread);
|
|
|
|
|
|
|
|
KernelThread.WaitEvent.Set();
|
2018-03-12 00:04:52 -04:00
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-08-15 14:59:51 -04:00
|
|
|
if (Threads.Count == 0)
|
2018-03-12 00:04:52 -04:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
Device.System.ExitProcess(ProcessId);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public KThread GetThread(long Tpidr)
|
2018-02-13 21:43:08 -05:00
|
|
|
{
|
2018-04-21 15:07:16 -04:00
|
|
|
if (!Threads.TryGetValue(Tpidr, out KThread Thread))
|
2018-02-19 14:37:13 -05:00
|
|
|
{
|
2018-04-24 14:57:39 -04:00
|
|
|
throw new InvalidOperationException();
|
2018-02-19 14:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return Thread;
|
2018-02-13 21:43:08 -05:00
|
|
|
}
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
private void Unload()
|
|
|
|
{
|
|
|
|
if (Disposed || Threads.Count > 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Disposed = true;
|
|
|
|
|
|
|
|
foreach (object Obj in HandleTable.Clear())
|
|
|
|
{
|
|
|
|
if (Obj is KSession Session)
|
|
|
|
{
|
|
|
|
Session.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INvDrvServices.UnloadProcess(this);
|
|
|
|
|
|
|
|
AppletState.Dispose();
|
|
|
|
|
|
|
|
if (NeedsHbAbi && Executables.Count > 0 && Executables[0].FilePath.EndsWith(Homebrew.TemporaryNroSuffix))
|
|
|
|
{
|
|
|
|
File.Delete(Executables[0].FilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
Device.Log.PrintInfo(LogClass.Loader, $"Process {ProcessId} exiting...");
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:43:08 -05:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool Disposing)
|
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
if (Disposing)
|
2018-02-13 21:43:08 -05:00
|
|
|
{
|
2018-08-15 14:59:51 -04:00
|
|
|
if (Threads.Count > 0)
|
2018-03-12 00:04:52 -04:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
foreach (KThread Thread in Threads.Values)
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
Thread.Thread.StopExecution();
|
|
|
|
|
|
|
|
Scheduler.ForceWakeUp(Thread);
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-16 19:47:36 -04:00
|
|
|
else
|
2018-07-19 14:44:52 -04:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
Unload();
|
2018-07-19 14:44:52 -04:00
|
|
|
}
|
2018-02-13 21:43:08 -05:00
|
|
|
}
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|