Allow more than one process, free resources on process dispose, implement SvcExitThread
This commit is contained in:
@@ -1,58 +1,48 @@
|
||||
using Ryujinx.Core.OsHle.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Handles
|
||||
{
|
||||
class HDomain : HSession
|
||||
class HDomain : HSession, IDisposable
|
||||
{
|
||||
private Dictionary<int, object> Objects;
|
||||
|
||||
private IdPool ObjIds;
|
||||
private IdDictionary Objects;
|
||||
|
||||
public HDomain(HSession Session) : base(Session)
|
||||
{
|
||||
Objects = new Dictionary<int, object>();
|
||||
|
||||
ObjIds = new IdPool();
|
||||
Objects = new IdDictionary();
|
||||
}
|
||||
|
||||
public int GenerateObjectId(object Obj)
|
||||
public int Add(object Obj)
|
||||
{
|
||||
int Id = ObjIds.GenerateId();
|
||||
|
||||
if (Id == -1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
Objects.Add(Id, Obj);
|
||||
|
||||
return Id;
|
||||
return Objects.Add(Obj);
|
||||
}
|
||||
|
||||
public void DeleteObject(int Id)
|
||||
public bool Delete(int Id)
|
||||
{
|
||||
if (Objects.TryGetValue(Id, out object Obj))
|
||||
{
|
||||
if (Obj is IDisposable DisposableObj)
|
||||
{
|
||||
DisposableObj.Dispose();
|
||||
}
|
||||
|
||||
ObjIds.DeleteId(Id);
|
||||
Objects.Remove(Id);
|
||||
}
|
||||
return Objects.Delete(Id);
|
||||
}
|
||||
|
||||
public object GetObject(int Id)
|
||||
{
|
||||
if (Objects.TryGetValue(Id, out object Obj))
|
||||
{
|
||||
return Obj;
|
||||
}
|
||||
return Objects.GetData(Id);
|
||||
}
|
||||
|
||||
return null;
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool Disposing)
|
||||
{
|
||||
if (Disposing)
|
||||
{
|
||||
foreach (object Obj in Objects)
|
||||
{
|
||||
if (Obj is IDisposable DisposableObj)
|
||||
{
|
||||
DisposableObj.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Ryujinx.Core.OsHle.Handles
|
||||
{
|
||||
class HNvMap
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int Size { get; private set; }
|
||||
|
||||
public int Align { get; set; }
|
||||
public int Kind { get; set; }
|
||||
public long Address { get; set; }
|
||||
|
||||
public HNvMap(int Id, int Size)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Size = Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using ChocolArm64.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -5,37 +6,37 @@ namespace Ryujinx.Core.OsHle.Handles
|
||||
{
|
||||
class HSharedMem
|
||||
{
|
||||
private List<long> Positions;
|
||||
private List<(AMemory, long)> Positions;
|
||||
|
||||
public EventHandler<EventArgs> MemoryMapped;
|
||||
public EventHandler<EventArgs> MemoryUnmapped;
|
||||
|
||||
public HSharedMem()
|
||||
{
|
||||
Positions = new List<long>();
|
||||
Positions = new List<(AMemory, long)>();
|
||||
}
|
||||
|
||||
public void AddVirtualPosition(long Position)
|
||||
public void AddVirtualPosition(AMemory Memory, long Position)
|
||||
{
|
||||
lock (Positions)
|
||||
{
|
||||
Positions.Add(Position);
|
||||
Positions.Add((Memory, Position));
|
||||
|
||||
MemoryMapped?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveVirtualPosition(long Position)
|
||||
public void RemoveVirtualPosition(AMemory Memory, long Position)
|
||||
{
|
||||
lock (Positions)
|
||||
{
|
||||
Positions.Remove(Position);
|
||||
Positions.Remove((Memory, Position));
|
||||
|
||||
MemoryUnmapped?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public long[] GetVirtualPositions()
|
||||
public (AMemory, long)[] GetVirtualPositions()
|
||||
{
|
||||
return Positions.ToArray();
|
||||
}
|
||||
|
||||
63
Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs
Normal file
63
Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Handles
|
||||
{
|
||||
class KProcessHandleTable : IDisposable
|
||||
{
|
||||
private IdDictionary Handles;
|
||||
|
||||
public KProcessHandleTable()
|
||||
{
|
||||
Handles = new IdDictionary();
|
||||
}
|
||||
|
||||
public int OpenHandle(object Obj)
|
||||
{
|
||||
return Handles.Add(Obj);
|
||||
}
|
||||
|
||||
public T GetData<T>(int Handle)
|
||||
{
|
||||
return Handles.GetData<T>(Handle);
|
||||
}
|
||||
|
||||
public bool ReplaceData(int Id, object Data)
|
||||
{
|
||||
return Handles.ReplaceData(Id, Data);
|
||||
}
|
||||
|
||||
public bool CloseHandle(int Handle)
|
||||
{
|
||||
object Data = Handles.GetData(Handle);
|
||||
|
||||
if (Data is HTransferMem TMem)
|
||||
{
|
||||
TMem.Memory.Manager.Reprotect(
|
||||
TMem.Position,
|
||||
TMem.Size,
|
||||
TMem.Perm);
|
||||
}
|
||||
|
||||
return Handles.Delete(Handle);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool Disposing)
|
||||
{
|
||||
if (Disposing)
|
||||
{
|
||||
foreach (object Obj in Handles)
|
||||
{
|
||||
if (Obj is IDisposable DisposableObj)
|
||||
{
|
||||
DisposableObj.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user