Compare commits

..

6 Commits

Author SHA1 Message Date
Ac_K
e876c43ce9 Misc; Remove duplicated entries and clean locale csproj (#4209) 2023-01-05 04:30:55 +01:00
Mary
8639245533 hle: Add safety measure around overflow in ScheduleFutureInvocation
Fix crash on Linux since 08831eecf7.
2023-01-05 01:55:27 +01:00
Ac_K
d6b86a6629 Readd Ryujinx.Ui.LocaleGenerator removed in #4188 (again) 2023-01-05 00:23:17 +01:00
Ac_K
8f2b7b5b8e Readd Ryujinx.Ui.LocaleGenerator removed in #4188 2023-01-05 00:20:47 +01:00
gdkchan
fc4b7cba2c Make PPTC state non-static (#4157)
* Make PPTC state non-static

* DiskCacheLoadState can be null
2023-01-05 00:01:44 +01:00
gdkchan
08831eecf7 IPC refactor part 3+4: New server HIPC message processor (#4188)
* IPC refactor part 3 + 4: New server HIPC message processor with source generator based serialization

* Make types match on calls to AlignUp/AlignDown

* Formatting

* Address some PR feedback

* Move BitfieldExtensions to Ryujinx.Common.Utilities and consolidate implementations

* Rename Reader/Writer to SpanReader/SpanWriter and move to Ryujinx.Common.Memory

* Implement EventType

* Address more PR feedback

* Log request processing errors since they are not normal

* Rename waitable to multiwait and add missing lock

* PR feedback

* Ac_K PR feedback
2023-01-04 23:15:45 +01:00
236 changed files with 10209 additions and 1246 deletions

View File

@@ -6,7 +6,6 @@ using ARMeilleure.Instructions;
using ARMeilleure.IntermediateRepresentation;
using ARMeilleure.Memory;
using ARMeilleure.State;
using ARMeilleure.Translation.PTC;
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -44,14 +43,13 @@ namespace ARMeilleure.Translation
public IMemoryManager Memory { get; }
public bool HasPtc { get; }
public EntryTable<uint> CountTable { get; }
public AddressTable<ulong> FunctionTable { get; }
public TranslatorStubs Stubs { get; }
public ulong EntryAddress { get; }
public bool HighCq { get; }
public bool HasPtc { get; }
public Aarch32Mode Mode { get; }
private int _ifThenBlockStateIndex = 0;
@@ -66,15 +64,16 @@ namespace ARMeilleure.Translation
TranslatorStubs stubs,
ulong entryAddress,
bool highCq,
bool hasPtc,
Aarch32Mode mode)
{
HasPtc = Ptc.State != PtcState.Disabled;
Memory = memory;
CountTable = countTable;
FunctionTable = funcTable;
Stubs = stubs;
EntryAddress = entryAddress;
HighCq = highCq;
HasPtc = hasPtc;
Mode = mode;
_labels = new Dictionary<ulong, Operand>();

View File

@@ -0,0 +1,10 @@
using System;
namespace ARMeilleure.Translation.PTC
{
public interface IPtcLoadState
{
event Action<PtcLoadingState, int, int> PtcStateChanged;
void Continue();
}
}

View File

@@ -22,7 +22,7 @@ using static ARMeilleure.Translation.PTC.PtcFormatter;
namespace ARMeilleure.Translation.PTC
{
public static class Ptc
class Ptc : IPtcLoadState
{
private const string OuterHeaderMagicString = "PTCohd\0\0";
private const string InnerHeaderMagicString = "PTCihd\0\0";
@@ -35,45 +35,49 @@ namespace ARMeilleure.Translation.PTC
private const string TitleIdTextDefault = "0000000000000000";
private const string DisplayVersionDefault = "0";
internal static readonly Symbol PageTableSymbol = new(SymbolType.Special, 1);
internal static readonly Symbol CountTableSymbol = new(SymbolType.Special, 2);
internal static readonly Symbol DispatchStubSymbol = new(SymbolType.Special, 3);
public static readonly Symbol PageTableSymbol = new(SymbolType.Special, 1);
public static readonly Symbol CountTableSymbol = new(SymbolType.Special, 2);
public static readonly Symbol DispatchStubSymbol = new(SymbolType.Special, 3);
private const byte FillingByte = 0x00;
private const CompressionLevel SaveCompressionLevel = CompressionLevel.Fastest;
public PtcProfiler Profiler { get; }
// Carriers.
private static MemoryStream _infosStream;
private static List<byte[]> _codesList;
private static MemoryStream _relocsStream;
private static MemoryStream _unwindInfosStream;
private MemoryStream _infosStream;
private List<byte[]> _codesList;
private MemoryStream _relocsStream;
private MemoryStream _unwindInfosStream;
private static readonly ulong _outerHeaderMagic;
private static readonly ulong _innerHeaderMagic;
private readonly ulong _outerHeaderMagic;
private readonly ulong _innerHeaderMagic;
private static readonly ManualResetEvent _waitEvent;
private readonly ManualResetEvent _waitEvent;
private static readonly object _lock;
private readonly object _lock;
private static bool _disposed;
private bool _disposed;
internal static string TitleIdText { get; private set; }
internal static string DisplayVersion { get; private set; }
public string TitleIdText { get; private set; }
public string DisplayVersion { get; private set; }
private static MemoryManagerMode _memoryMode;
private MemoryManagerType _memoryMode;
internal static string CachePathActual { get; private set; }
internal static string CachePathBackup { get; private set; }
public string CachePathActual { get; private set; }
public string CachePathBackup { get; private set; }
internal static PtcState State { get; private set; }
public PtcState State { get; private set; }
// Progress reporting helpers.
private static volatile int _translateCount;
private static volatile int _translateTotalCount;
public static event Action<PtcLoadingState, int, int> PtcStateChanged;
private volatile int _translateCount;
private volatile int _translateTotalCount;
public event Action<PtcLoadingState, int, int> PtcStateChanged;
static Ptc()
public Ptc()
{
Profiler = new PtcProfiler(this);
InitializeCarriers();
_outerHeaderMagic = BinaryPrimitives.ReadUInt64LittleEndian(EncodingCache.UTF8NoBOM.GetBytes(OuterHeaderMagicString).AsSpan());
@@ -94,12 +98,12 @@ namespace ARMeilleure.Translation.PTC
Disable();
}
public static void Initialize(string titleIdText, string displayVersion, bool enabled, MemoryManagerMode memoryMode)
public void Initialize(string titleIdText, string displayVersion, bool enabled, MemoryManagerType memoryMode)
{
Wait();
PtcProfiler.Wait();
PtcProfiler.ClearEntries();
Profiler.Wait();
Profiler.ClearEntries();
Logger.Info?.Print(LogClass.Ptc, $"Initializing Profiled Persistent Translation Cache (enabled: {enabled}).");
@@ -137,12 +141,12 @@ namespace ARMeilleure.Translation.PTC
CachePathBackup = Path.Combine(workPathBackup, DisplayVersion);
PreLoad();
PtcProfiler.PreLoad();
Profiler.PreLoad();
Enable();
}
private static void InitializeCarriers()
private void InitializeCarriers()
{
_infosStream = new MemoryStream();
_codesList = new List<byte[]>();
@@ -150,7 +154,7 @@ namespace ARMeilleure.Translation.PTC
_unwindInfosStream = new MemoryStream();
}
private static void DisposeCarriers()
private void DisposeCarriers()
{
_infosStream.Dispose();
_codesList.Clear();
@@ -158,12 +162,12 @@ namespace ARMeilleure.Translation.PTC
_unwindInfosStream.Dispose();
}
private static bool AreCarriersEmpty()
private bool AreCarriersEmpty()
{
return _infosStream.Length == 0L && _codesList.Count == 0 && _relocsStream.Length == 0L && _unwindInfosStream.Length == 0L;
}
private static void ResetCarriersIfNeeded()
private void ResetCarriersIfNeeded()
{
if (AreCarriersEmpty())
{
@@ -175,7 +179,7 @@ namespace ARMeilleure.Translation.PTC
InitializeCarriers();
}
private static void PreLoad()
private void PreLoad()
{
string fileNameActual = string.Concat(CachePathActual, ".cache");
string fileNameBackup = string.Concat(CachePathBackup, ".cache");
@@ -199,7 +203,7 @@ namespace ARMeilleure.Translation.PTC
}
}
private static unsafe bool Load(string fileName, bool isBackup)
private unsafe bool Load(string fileName, bool isBackup)
{
using (FileStream compressedStream = new(fileName, FileMode.Open))
using (DeflateStream deflateStream = new(compressedStream, CompressionMode.Decompress, true))
@@ -376,12 +380,12 @@ namespace ARMeilleure.Translation.PTC
return true;
}
private static void InvalidateCompressedStream(FileStream compressedStream)
private void InvalidateCompressedStream(FileStream compressedStream)
{
compressedStream.SetLength(0L);
}
private static void PreSave()
private void PreSave()
{
_waitEvent.Reset();
@@ -409,7 +413,7 @@ namespace ARMeilleure.Translation.PTC
_waitEvent.Set();
}
private static unsafe void Save(string fileName)
private unsafe void Save(string fileName)
{
int translatedFuncsCount;
@@ -517,7 +521,7 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void LoadTranslations(Translator translator)
public void LoadTranslations(Translator translator)
{
if (AreCarriersEmpty())
{
@@ -550,7 +554,7 @@ namespace ARMeilleure.Translation.PTC
bool isEntryChanged = infoEntry.Hash != ComputeHash(translator.Memory, infoEntry.Address, infoEntry.GuestSize);
if (isEntryChanged || (!infoEntry.HighCq && PtcProfiler.ProfiledFuncs.TryGetValue(infoEntry.Address, out var value) && value.HighCq))
if (isEntryChanged || (!infoEntry.HighCq && Profiler.ProfiledFuncs.TryGetValue(infoEntry.Address, out var value) && value.HighCq))
{
infoEntry.Stubbed = true;
infoEntry.CodeLength = 0;
@@ -601,38 +605,38 @@ namespace ARMeilleure.Translation.PTC
Logger.Info?.Print(LogClass.Ptc, $"{translator.Functions.Count} translated functions loaded");
}
private static int GetEntriesCount()
private int GetEntriesCount()
{
return _codesList.Count;
}
[Conditional("DEBUG")]
private static void SkipCode(int index, int codeLength)
private void SkipCode(int index, int codeLength)
{
Debug.Assert(_codesList[index].Length == 0);
Debug.Assert(codeLength == 0);
}
private static void SkipReloc(int relocEntriesCount)
private void SkipReloc(int relocEntriesCount)
{
_relocsStream.Seek(relocEntriesCount * RelocEntry.Stride, SeekOrigin.Current);
}
private static void SkipUnwindInfo(BinaryReader unwindInfosReader)
private void SkipUnwindInfo(BinaryReader unwindInfosReader)
{
int pushEntriesLength = unwindInfosReader.ReadInt32();
_unwindInfosStream.Seek(pushEntriesLength * UnwindPushEntry.Stride + UnwindInfo.Stride, SeekOrigin.Current);
}
private static byte[] ReadCode(int index, int codeLength)
private byte[] ReadCode(int index, int codeLength)
{
Debug.Assert(_codesList[index].Length == codeLength);
return _codesList[index];
}
private static RelocEntry[] GetRelocEntries(BinaryReader relocsReader, int relocEntriesCount)
private RelocEntry[] GetRelocEntries(BinaryReader relocsReader, int relocEntriesCount)
{
RelocEntry[] relocEntries = new RelocEntry[relocEntriesCount];
@@ -648,7 +652,7 @@ namespace ARMeilleure.Translation.PTC
return relocEntries;
}
private static void PatchCode(Translator translator, Span<byte> code, RelocEntry[] relocEntries, out Counter<uint> callCounter)
private void PatchCode(Translator translator, Span<byte> code, RelocEntry[] relocEntries, out Counter<uint> callCounter)
{
callCounter = null;
@@ -702,7 +706,7 @@ namespace ARMeilleure.Translation.PTC
}
}
private static UnwindInfo ReadUnwindInfo(BinaryReader unwindInfosReader)
private UnwindInfo ReadUnwindInfo(BinaryReader unwindInfosReader)
{
int pushEntriesLength = unwindInfosReader.ReadInt32();
@@ -723,7 +727,7 @@ namespace ARMeilleure.Translation.PTC
return new UnwindInfo(pushEntries, prologueSize);
}
private static TranslatedFunction FastTranslate(
private TranslatedFunction FastTranslate(
byte[] code,
Counter<uint> callCounter,
ulong guestSize,
@@ -736,19 +740,19 @@ namespace ARMeilleure.Translation.PTC
return new TranslatedFunction(gFunc, callCounter, guestSize, highCq);
}
private static void UpdateInfo(InfoEntry infoEntry)
private void UpdateInfo(InfoEntry infoEntry)
{
_infosStream.Seek(-Unsafe.SizeOf<InfoEntry>(), SeekOrigin.Current);
SerializeStructure(_infosStream, infoEntry);
}
private static void StubCode(int index)
private void StubCode(int index)
{
_codesList[index] = Array.Empty<byte>();
}
private static void StubReloc(int relocEntriesCount)
private void StubReloc(int relocEntriesCount)
{
for (int i = 0; i < relocEntriesCount * RelocEntry.Stride; i++)
{
@@ -756,7 +760,7 @@ namespace ARMeilleure.Translation.PTC
}
}
private static void StubUnwindInfo(BinaryReader unwindInfosReader)
private void StubUnwindInfo(BinaryReader unwindInfosReader)
{
int pushEntriesLength = unwindInfosReader.ReadInt32();
@@ -766,9 +770,9 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void MakeAndSaveTranslations(Translator translator)
public void MakeAndSaveTranslations(Translator translator)
{
var profiledFuncsToTranslate = PtcProfiler.GetProfiledFuncsToTranslate(translator.Functions);
var profiledFuncsToTranslate = Profiler.GetProfiledFuncsToTranslate(translator.Functions);
_translateCount = 0;
_translateTotalCount = profiledFuncsToTranslate.Count;
@@ -811,7 +815,7 @@ namespace ARMeilleure.Translation.PTC
{
ulong address = item.address;
Debug.Assert(PtcProfiler.IsAddressInStaticCodeRange(address));
Debug.Assert(Profiler.IsAddressInStaticCodeRange(address));
TranslatedFunction func = translator.Translate(address, item.funcProfile.Mode, item.funcProfile.HighCq);
@@ -861,7 +865,7 @@ namespace ARMeilleure.Translation.PTC
preSaveThread.Start();
}
private static void ReportProgress(object state)
private void ReportProgress(object state)
{
const int refreshRate = 50; // ms.
@@ -882,12 +886,12 @@ namespace ARMeilleure.Translation.PTC
while (!endEvent.WaitOne(refreshRate));
}
internal static Hash128 ComputeHash(IMemoryManager memory, ulong address, ulong guestSize)
public static Hash128 ComputeHash(IMemoryManager memory, ulong address, ulong guestSize)
{
return XXHash128.ComputeHash(memory.GetSpan(address, checked((int)(guestSize))));
}
internal static void WriteCompiledFunction(ulong address, ulong guestSize, Hash128 hash, bool highCq, CompiledFunction compiledFunc)
public void WriteCompiledFunction(ulong address, ulong guestSize, Hash128 hash, bool highCq, CompiledFunction compiledFunc)
{
lock (_lock)
{
@@ -936,12 +940,12 @@ namespace ARMeilleure.Translation.PTC
}
}
private static void WriteCode(ReadOnlySpan<byte> code)
private void WriteCode(ReadOnlySpan<byte> code)
{
_codesList.Add(code.ToArray());
}
internal static bool GetEndianness()
public static bool GetEndianness()
{
return BitConverter.IsLittleEndian;
}
@@ -955,7 +959,7 @@ namespace ARMeilleure.Translation.PTC
(uint)HardwareCapabilities.FeatureInfo7Ecx);
}
private static byte GetMemoryManagerMode()
private byte GetMemoryManagerMode()
{
return (byte)_memoryMode;
}
@@ -1050,12 +1054,12 @@ namespace ARMeilleure.Translation.PTC
public int RelocEntriesCount;
}
private static void Enable()
private void Enable()
{
State = PtcState.Enabled;
}
public static void Continue()
public void Continue()
{
if (State == PtcState.Enabled)
{
@@ -1063,7 +1067,7 @@ namespace ARMeilleure.Translation.PTC
}
}
public static void Close()
public void Close()
{
if (State == PtcState.Enabled ||
State == PtcState.Continuing)
@@ -1072,17 +1076,17 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void Disable()
public void Disable()
{
State = PtcState.Disabled;
}
private static void Wait()
private void Wait()
{
_waitEvent.WaitOne();
}
public static void Dispose()
public void Dispose()
{
if (!_disposed)
{

View File

@@ -16,7 +16,7 @@ using static ARMeilleure.Translation.PTC.PtcFormatter;
namespace ARMeilleure.Translation.PTC
{
public static class PtcProfiler
class PtcProfiler
{
private const string OuterHeaderMagicString = "Pohd\0\0\0\0";
@@ -26,27 +26,31 @@ namespace ARMeilleure.Translation.PTC
private const CompressionLevel SaveCompressionLevel = CompressionLevel.Fastest;
private static readonly System.Timers.Timer _timer;
private readonly Ptc _ptc;
private static readonly ulong _outerHeaderMagic;
private readonly System.Timers.Timer _timer;
private static readonly ManualResetEvent _waitEvent;
private readonly ulong _outerHeaderMagic;
private static readonly object _lock;
private readonly ManualResetEvent _waitEvent;
private static bool _disposed;
private readonly object _lock;
private static Hash128 _lastHash;
private bool _disposed;
internal static Dictionary<ulong, FuncProfile> ProfiledFuncs { get; private set; }
private Hash128 _lastHash;
internal static bool Enabled { get; private set; }
public Dictionary<ulong, FuncProfile> ProfiledFuncs { get; private set; }
public static ulong StaticCodeStart { internal get; set; }
public static ulong StaticCodeSize { internal get; set; }
public bool Enabled { get; private set; }
static PtcProfiler()
public ulong StaticCodeStart { get; set; }
public ulong StaticCodeSize { get; set; }
public PtcProfiler(Ptc ptc)
{
_ptc = ptc;
_timer = new System.Timers.Timer((double)SaveInterval * 1000d);
_timer.Elapsed += PreSave;
@@ -63,7 +67,7 @@ namespace ARMeilleure.Translation.PTC
Enabled = false;
}
internal static void AddEntry(ulong address, ExecutionMode mode, bool highCq)
public void AddEntry(ulong address, ExecutionMode mode, bool highCq)
{
if (IsAddressInStaticCodeRange(address))
{
@@ -76,7 +80,7 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void UpdateEntry(ulong address, ExecutionMode mode, bool highCq)
public void UpdateEntry(ulong address, ExecutionMode mode, bool highCq)
{
if (IsAddressInStaticCodeRange(address))
{
@@ -91,12 +95,12 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static bool IsAddressInStaticCodeRange(ulong address)
public bool IsAddressInStaticCodeRange(ulong address)
{
return address >= StaticCodeStart && address < StaticCodeStart + StaticCodeSize;
}
internal static ConcurrentQueue<(ulong address, FuncProfile funcProfile)> GetProfiledFuncsToTranslate(TranslatorCache<TranslatedFunction> funcs)
public ConcurrentQueue<(ulong address, FuncProfile funcProfile)> GetProfiledFuncsToTranslate(TranslatorCache<TranslatedFunction> funcs)
{
var profiledFuncsToTranslate = new ConcurrentQueue<(ulong address, FuncProfile funcProfile)>();
@@ -111,18 +115,18 @@ namespace ARMeilleure.Translation.PTC
return profiledFuncsToTranslate;
}
internal static void ClearEntries()
public void ClearEntries()
{
ProfiledFuncs.Clear();
ProfiledFuncs.TrimExcess();
}
internal static void PreLoad()
public void PreLoad()
{
_lastHash = default;
string fileNameActual = string.Concat(Ptc.CachePathActual, ".info");
string fileNameBackup = string.Concat(Ptc.CachePathBackup, ".info");
string fileNameActual = string.Concat(_ptc.CachePathActual, ".info");
string fileNameBackup = string.Concat(_ptc.CachePathBackup, ".info");
FileInfo fileInfoActual = new FileInfo(fileNameActual);
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
@@ -143,7 +147,7 @@ namespace ARMeilleure.Translation.PTC
}
}
private static bool Load(string fileName, bool isBackup)
private bool Load(string fileName, bool isBackup)
{
using (FileStream compressedStream = new(fileName, FileMode.Open))
using (DeflateStream deflateStream = new(compressedStream, CompressionMode.Decompress, true))
@@ -228,22 +232,22 @@ namespace ARMeilleure.Translation.PTC
return DeserializeDictionary<ulong, FuncProfile>(stream, (stream) => DeserializeStructure<FuncProfile>(stream));
}
private static ReadOnlySpan<byte> GetReadOnlySpan(MemoryStream memoryStream)
private ReadOnlySpan<byte> GetReadOnlySpan(MemoryStream memoryStream)
{
return new(memoryStream.GetBuffer(), (int)memoryStream.Position, (int)memoryStream.Length - (int)memoryStream.Position);
}
private static void InvalidateCompressedStream(FileStream compressedStream)
private void InvalidateCompressedStream(FileStream compressedStream)
{
compressedStream.SetLength(0L);
}
private static void PreSave(object source, System.Timers.ElapsedEventArgs e)
private void PreSave(object source, System.Timers.ElapsedEventArgs e)
{
_waitEvent.Reset();
string fileNameActual = string.Concat(Ptc.CachePathActual, ".info");
string fileNameBackup = string.Concat(Ptc.CachePathBackup, ".info");
string fileNameActual = string.Concat(_ptc.CachePathActual, ".info");
string fileNameBackup = string.Concat(_ptc.CachePathBackup, ".info");
FileInfo fileInfoActual = new FileInfo(fileNameActual);
@@ -257,7 +261,7 @@ namespace ARMeilleure.Translation.PTC
_waitEvent.Set();
}
private static void Save(string fileName)
private void Save(string fileName)
{
int profiledFuncsCount;
@@ -329,7 +333,7 @@ namespace ARMeilleure.Translation.PTC
}
}
private static void Serialize(Stream stream, Dictionary<ulong, FuncProfile> profiledFuncs)
private void Serialize(Stream stream, Dictionary<ulong, FuncProfile> profiledFuncs)
{
SerializeDictionary(stream, profiledFuncs, (stream, structure) => SerializeStructure(stream, structure));
}
@@ -361,7 +365,7 @@ namespace ARMeilleure.Translation.PTC
}
[StructLayout(LayoutKind.Sequential, Pack = 1/*, Size = 5*/)]
internal struct FuncProfile
public struct FuncProfile
{
public ExecutionMode Mode;
public bool HighCq;
@@ -373,10 +377,10 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void Start()
public void Start()
{
if (Ptc.State == PtcState.Enabled ||
Ptc.State == PtcState.Continuing)
if (_ptc.State == PtcState.Enabled ||
_ptc.State == PtcState.Continuing)
{
Enabled = true;
@@ -384,7 +388,7 @@ namespace ARMeilleure.Translation.PTC
}
}
public static void Stop()
public void Stop()
{
Enabled = false;
@@ -394,12 +398,12 @@ namespace ARMeilleure.Translation.PTC
}
}
internal static void Wait()
public void Wait()
{
_waitEvent.WaitOne();
}
public static void Dispose()
public void Dispose()
{
if (!_disposed)
{

View File

@@ -44,6 +44,8 @@ namespace ARMeilleure.Translation
private readonly IJitMemoryAllocator _allocator;
private readonly ConcurrentQueue<KeyValuePair<ulong, TranslatedFunction>> _oldFuncs;
private readonly Ptc _ptc;
internal TranslatorCache<TranslatedFunction> Functions { get; }
internal AddressTable<ulong> FunctionTable { get; }
internal EntryTable<uint> CountTable { get; }
@@ -63,6 +65,8 @@ namespace ARMeilleure.Translation
_oldFuncs = new ConcurrentQueue<KeyValuePair<ulong, TranslatedFunction>>();
_ptc = new Ptc();
Queue = new TranslatorQueue();
JitCache.Initialize(allocator);
@@ -80,22 +84,37 @@ namespace ARMeilleure.Translation
}
}
public IPtcLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled)
{
_ptc.Initialize(titleIdText, displayVersion, enabled, Memory.Type);
return _ptc;
}
public void PrepareCodeRange(ulong address, ulong size)
{
if (_ptc.Profiler.StaticCodeSize == 0)
{
_ptc.Profiler.StaticCodeStart = address;
_ptc.Profiler.StaticCodeSize = size;
}
}
public void Execute(State.ExecutionContext context, ulong address)
{
if (Interlocked.Increment(ref _threadCount) == 1)
{
IsReadyForTranslation.WaitOne();
if (Ptc.State == PtcState.Enabled)
if (_ptc.State == PtcState.Enabled)
{
Debug.Assert(Functions.Count == 0);
Ptc.LoadTranslations(this);
Ptc.MakeAndSaveTranslations(this);
_ptc.LoadTranslations(this);
_ptc.MakeAndSaveTranslations(this);
}
PtcProfiler.Start();
_ptc.Profiler.Start();
Ptc.Disable();
_ptc.Disable();
// Simple heuristic, should be user configurable in future. (1 for 4 core/ht or less, 2 for 6 core + ht
// etc). All threads are normal priority except from the last, which just fills as much of the last core
@@ -148,6 +167,12 @@ namespace ARMeilleure.Translation
Stubs.Dispose();
FunctionTable.Dispose();
CountTable.Dispose();
_ptc.Close();
_ptc.Profiler.Stop();
_ptc.Dispose();
_ptc.Profiler.Dispose();
}
}
@@ -189,9 +214,9 @@ namespace ARMeilleure.Translation
func = oldFunc;
}
if (PtcProfiler.Enabled)
if (_ptc.Profiler.Enabled)
{
PtcProfiler.AddEntry(address, mode, highCq: false);
_ptc.Profiler.AddEntry(address, mode, highCq: false);
}
RegisterFunction(address, func);
@@ -217,6 +242,7 @@ namespace ARMeilleure.Translation
Stubs,
address,
highCq,
_ptc.State != PtcState.Disabled,
mode: Aarch32Mode.User);
Logger.StartPass(PassName.Decoding);
@@ -262,7 +288,7 @@ namespace ARMeilleure.Translation
{
Hash128 hash = Ptc.ComputeHash(Memory, address, funcSize);
Ptc.WriteCompiledFunction(address, funcSize, hash, highCq, compiledFunc);
_ptc.WriteCompiledFunction(address, funcSize, hash, highCq, compiledFunc);
}
GuestFunction func = compiledFunc.Map<GuestFunction>();
@@ -284,9 +310,9 @@ namespace ARMeilleure.Translation
return func;
});
if (PtcProfiler.Enabled)
if (_ptc.Profiler.Enabled)
{
PtcProfiler.UpdateEntry(request.Address, request.Mode, highCq: true);
_ptc.Profiler.UpdateEntry(request.Address, request.Mode, highCq: true);
}
RegisterFunction(request.Address, func);

View File

@@ -50,7 +50,5 @@
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
<PackageVersion Include="System.Threading.ThreadPool" Version="4.3.0" />
<PackageVersion Include="XamlNameReferenceGenerator" Version="1.5.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3"/>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
</ItemGroup>
</Project>

View File

@@ -1,5 +1,4 @@
using ARMeilleure.Translation;
using ARMeilleure.Translation.PTC;
using Avalonia.Input;
using Avalonia.Threading;
using LibHac.Tools.FsSystem;
@@ -280,7 +279,7 @@ namespace Ryujinx.Ava
_parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
});
_parent.ViewModel.HandleShaderProgress(Device);
_parent.ViewModel.SetUiProgressHandlers(Device);
Renderer.SizeChanged += Window_SizeChanged;
@@ -357,8 +356,6 @@ namespace Ryujinx.Ava
DisplaySleep.Restore();
Ptc.Close();
PtcProfiler.Stop();
NpadManager.Dispose();
TouchScreenManager.Dispose();
Device.Dispose();
@@ -949,7 +946,7 @@ namespace Ryujinx.Ava
if (_keyboardInterface.GetKeyboardStateSnapshot().IsPressed(Key.Delete) && _parent.WindowState != WindowState.FullScreen)
{
Ptc.Continue();
Device.Application.DiskCacheLoadState?.Cancel();
}
});
}

View File

@@ -1,4 +1,3 @@
using ARMeilleure.Translation.PTC;
using Avalonia;
using Avalonia.Threading;
using Ryujinx.Ava.UI.Windows;
@@ -197,9 +196,6 @@ namespace Ryujinx.Ava
private static void ProcessUnhandledException(Exception ex, bool isTerminating)
{
Ptc.Close();
PtcProfiler.Stop();
string message = $"Unhandled exception caught: {ex}";
Logger.Error?.PrintMsg(LogClass.Application, message);
@@ -219,9 +215,6 @@ namespace Ryujinx.Ava
{
DiscordIntegrationModule.Exit();
Ptc.Dispose();
PtcProfiler.Dispose();
Logger.Shutdown();
}
}

View File

@@ -1,4 +1,3 @@
using ARMeilleure.Translation.PTC;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
@@ -18,6 +17,7 @@ using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS;
@@ -107,9 +107,6 @@ namespace Ryujinx.Ava.UI.ViewModels
{
ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated;
ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded;
Ptc.PtcStateChanged -= ProgressHandler;
Ptc.PtcStateChanged += ProgressHandler;
}
public string SearchText
@@ -745,8 +742,14 @@ namespace Ryujinx.Ava.UI.ViewModels
}
}
public void HandleShaderProgress(Switch emulationContext)
public void SetUiProgressHandlers(Switch emulationContext)
{
if (emulationContext.Application.DiskCacheLoadState != null)
{
emulationContext.Application.DiskCacheLoadState.StateChanged -= ProgressHandler;
emulationContext.Application.DiskCacheLoadState.StateChanged += ProgressHandler;
}
emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
}
@@ -1033,16 +1036,16 @@ namespace Ryujinx.Ava.UI.ViewModels
switch (state)
{
case PtcLoadingState ptcState:
case LoadState ptcState:
CacheLoadStatus = $"{current} / {total}";
switch (ptcState)
{
case PtcLoadingState.Start:
case PtcLoadingState.Loading:
case LoadState.Unloaded:
case LoadState.Loading:
LoadHeading = LocaleManager.Instance[LocaleKeys.CompilingPPTC];
IsLoadingIndeterminate = false;
break;
case PtcLoadingState.Loaded:
case LoadState.Loaded:
LoadHeading = string.Format(LocaleManager.Instance[LocaleKeys.LoadingHeading], TitleName);
IsLoadingIndeterminate = true;
CacheLoadStatus = "";

View File

@@ -0,0 +1,51 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Common.Memory
{
public ref struct SpanReader
{
private ReadOnlySpan<byte> _input;
public int Length => _input.Length;
public SpanReader(ReadOnlySpan<byte> input)
{
_input = input;
}
public T Read<T>() where T : unmanaged
{
T value = MemoryMarshal.Cast<byte, T>(_input)[0];
_input = _input.Slice(Unsafe.SizeOf<T>());
return value;
}
public ReadOnlySpan<byte> GetSpan(int size)
{
ReadOnlySpan<byte> data = _input.Slice(0, size);
_input = _input.Slice(size);
return data;
}
public T ReadAt<T>(int offset) where T : unmanaged
{
return MemoryMarshal.Cast<byte, T>(_input.Slice(offset))[0];
}
public ReadOnlySpan<byte> GetSpanAt(int offset, int size)
{
return _input.Slice(offset, size);
}
public void Skip(int size)
{
_input = _input.Slice(size);
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Common.Memory
{
public ref struct SpanWriter
{
private Span<byte> _output;
public int Length => _output.Length;
public SpanWriter(Span<byte> output)
{
_output = output;
}
public void Write<T>(T value) where T : unmanaged
{
MemoryMarshal.Cast<byte, T>(_output)[0] = value;
_output = _output.Slice(Unsafe.SizeOf<T>());
}
public void Write(ReadOnlySpan<byte> data)
{
data.CopyTo(_output.Slice(0, data.Length));
_output = _output.Slice(data.Length);
}
public void WriteAt<T>(int offset, T value) where T : unmanaged
{
MemoryMarshal.Cast<byte, T>(_output.Slice(offset))[0] = value;
}
public void WriteAt(int offset, ReadOnlySpan<byte> data)
{
data.CopyTo(_output.Slice(offset, data.Length));
}
public void Skip(int size)
{
_output = _output.Slice(size);
}
}
}

View File

@@ -0,0 +1,57 @@
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ryujinx.Common.Utilities
{
public static class BitfieldExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Extract<T>(this T value, int lsb) where T : IBinaryInteger<T>
{
int bitSize = Unsafe.SizeOf<T>() * 8;
lsb &= bitSize - 1;
return !T.IsZero((value >>> lsb) & T.One);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Extract<T>(this T value, int lsb, int length) where T : IBinaryInteger<T>
{
int bitSize = Unsafe.SizeOf<T>() * 8;
lsb &= bitSize - 1;
return (value >>> lsb) & (~T.Zero >>> (bitSize - length));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ExtractSx<T>(this T value, int lsb, int length) where T : IBinaryInteger<T>
{
int bitSize = Unsafe.SizeOf<T>() * 8;
int shift = lsb & (bitSize - 1);
return (value << (bitSize - (shift + length))) >> (bitSize - length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Insert<T>(this T value, int lsb, bool toInsert) where T : IBinaryInteger<T>
{
int bitSize = Unsafe.SizeOf<T>() * 8;
lsb &= bitSize - 1;
T mask = T.One << lsb;
return (value & ~mask) | (toInsert ? mask : T.Zero);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Insert<T>(this T value, int lsb, int length, T toInsert) where T : IBinaryInteger<T>
{
int bitSize = Unsafe.SizeOf<T>() * 8;
lsb &= bitSize - 1;
T mask = (~T.Zero >>> (bitSize - length)) << lsb;
return (value & ~mask) | ((toInsert << lsb) & mask);
}
}
}

View File

@@ -35,5 +35,27 @@ namespace Ryujinx.Cpu
/// <param name="address">Address of the region to be invalidated</param>
/// <param name="size">Size of the region to be invalidated</param>
void InvalidateCacheRegion(ulong address, ulong size);
/// <summary>
/// Loads cached code from disk for a given application.
/// </summary>
/// <remarks>
/// If the execution engine is recompiling guest code, this can be used to load cached code from disk.
/// </remarks>
/// <param name="titleIdText">Title ID of the application in padded hex form</param>
/// <param name="displayVersion">Version of the application</param>
/// <param name="enabled">True if the cache should be loaded from disk if it exists, false otherwise</param>
/// <returns>Disk cache load progress reporter and manager</returns>
IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled);
/// <summary>
/// Indicates that code has been loaded into guest memory, and that it might be executed in the future.
/// </summary>
/// <remarks>
/// Some execution engines might use this information to cache recompiled code on disk or to ensure it can be executed.
/// </remarks>
/// <param name="address">CPU virtual address where the code starts</param>
/// <param name="size">Size of the code range in bytes</param>
void PrepareCodeRange(ulong address, ulong size);
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Ryujinx.Cpu
{
/// <summary>
/// Disk cache load state report and management interface.
/// </summary>
public interface IDiskCacheLoadState
{
/// <summary>
/// Event used to report the cache load progress.
/// </summary>
event Action<LoadState, int, int> StateChanged;
/// <summary>
/// Cancels the disk cache load process.
/// </summary>
void Cancel();
}
}

View File

@@ -37,5 +37,17 @@ namespace Ryujinx.Cpu.Jit
{
_translator.InvalidateJitCacheRegion(address, size);
}
/// <inheritdoc/>
public IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled)
{
return new JitDiskCacheLoadState(_translator.LoadDiskCache(titleIdText, displayVersion, enabled));
}
/// <inheritdoc/>
public void PrepareCodeRange(ulong address, ulong size)
{
_translator.PrepareCodeRange(address, size);
}
}
}

View File

@@ -0,0 +1,38 @@
using ARMeilleure.Translation.PTC;
using System;
namespace Ryujinx.Cpu.Jit
{
public class JitDiskCacheLoadState : IDiskCacheLoadState
{
/// <inheritdoc/>
public event Action<LoadState, int, int> StateChanged;
private readonly IPtcLoadState _loadState;
public JitDiskCacheLoadState(IPtcLoadState loadState)
{
loadState.PtcStateChanged += LoadStateChanged;
_loadState = loadState;
}
private void LoadStateChanged(PtcLoadingState newState, int current, int total)
{
LoadState state = newState switch
{
PtcLoadingState.Start => LoadState.Unloaded,
PtcLoadingState.Loading => LoadState.Loading,
PtcLoadingState.Loaded => LoadState.Loaded,
_ => throw new ArgumentException($"Invalid load state \"{newState}\".")
};
StateChanged?.Invoke(state, current, total);
}
/// <inheritdoc/>
public void Cancel()
{
_loadState.Continue();
}
}
}

12
Ryujinx.Cpu/LoadState.cs Normal file
View File

@@ -0,0 +1,12 @@
namespace Ryujinx.Cpu
{
/// <summary>
/// Load state.
/// </summary>
public enum LoadState
{
Unloaded,
Loading,
Loaded
}
}

View File

@@ -1,15 +0,0 @@
namespace Ryujinx.Graphics.Shader.Decoders
{
static class BitfieldExtensions
{
public static bool Extract(this int value, int lsb)
{
return ((value >> lsb) & 1) != 0;
}
public static int Extract(this int value, int lsb, int length)
{
return (value >> lsb) & (int)(uint.MaxValue >> (32 - length));
}
}
}

View File

@@ -1,4 +1,4 @@
using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Common.Utilities;
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using System;

View File

@@ -1,4 +1,4 @@
using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Common.Utilities;
using System;
using System.Runtime.InteropServices;

View File

@@ -1,39 +0,0 @@
using System.Runtime.CompilerServices;
namespace Ryujinx.Graphics.Vic.Types
{
static class BitfieldExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Extract(this int value, int lsb)
{
return ((value >> (lsb & 0x1f)) & 1) != 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Extract(this int value, int lsb, int length)
{
return (value >> (lsb & 0x1f)) & (int)(uint.MaxValue >> (32 - length));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Extract(this long value, int lsb)
{
return ((int)(value >> (lsb & 0x3f)) & 1) != 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Extract(this long value, int lsb, int length)
{
return (int)(value >> (lsb & 0x3f)) & (int)(uint.MaxValue >> (32 - length));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ExtractSx(this long value, int lsb, int length)
{
int shift = lsb & 0x3f;
return (int)((value << (64 - (shift + length))) >> (64 - length));
}
}
}

View File

@@ -1,20 +1,22 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct BlendingSlotStruct
{
private long _word0;
private long _word1;
public int AlphaK1 => _word0.Extract(0, 10);
public int AlphaK2 => _word0.Extract(16, 10);
public int SrcFactCMatchSelect => _word0.Extract(32, 3);
public int DstFactCMatchSelect => _word0.Extract(36, 3);
public int SrcFactAMatchSelect => _word0.Extract(40, 3);
public int DstFactAMatchSelect => _word0.Extract(44, 3);
public int OverrideR => _word1.Extract(66, 10);
public int OverrideG => _word1.Extract(76, 10);
public int OverrideB => _word1.Extract(86, 10);
public int OverrideA => _word1.Extract(96, 10);
public int AlphaK1 => (int)_word0.Extract(0, 10);
public int AlphaK2 => (int)_word0.Extract(16, 10);
public int SrcFactCMatchSelect => (int)_word0.Extract(32, 3);
public int DstFactCMatchSelect => (int)_word0.Extract(36, 3);
public int SrcFactAMatchSelect => (int)_word0.Extract(40, 3);
public int DstFactAMatchSelect => (int)_word0.Extract(44, 3);
public int OverrideR => (int)_word1.Extract(66, 10);
public int OverrideG => (int)_word1.Extract(76, 10);
public int OverrideB => (int)_word1.Extract(86, 10);
public int OverrideA => (int)_word1.Extract(96, 10);
public bool UseOverrideR => _word1.Extract(108);
public bool UseOverrideG => _word1.Extract(109);
public bool UseOverrideB => _word1.Extract(110);

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct ClearRectStruct
{
@@ -7,13 +9,13 @@
private long _word1;
#pragma warning restore CS0649
public int ClearRect0Left => _word0.Extract(0, 14);
public int ClearRect0Right => _word0.Extract(16, 14);
public int ClearRect0Top => _word0.Extract(32, 14);
public int ClearRect0Bottom => _word0.Extract(48, 14);
public int ClearRect1Left => _word1.Extract(64, 14);
public int ClearRect1Right => _word1.Extract(80, 14);
public int ClearRect1Top => _word1.Extract(96, 14);
public int ClearRect1Bottom => _word1.Extract(112, 14);
public int ClearRect0Left => (int)_word0.Extract(0, 14);
public int ClearRect0Right => (int)_word0.Extract(16, 14);
public int ClearRect0Top => (int)_word0.Extract(32, 14);
public int ClearRect0Bottom => (int)_word0.Extract(48, 14);
public int ClearRect1Left => (int)_word1.Extract(64, 14);
public int ClearRect1Right => (int)_word1.Extract(80, 14);
public int ClearRect1Top => (int)_word1.Extract(96, 14);
public int ClearRect1Bottom => (int)_word1.Extract(112, 14);
}
}

View File

@@ -1,17 +1,19 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct LumaKeyStruct
{
private long _word0;
private long _word1;
public int LumaCoeff0 => _word0.Extract(0, 20);
public int LumaCoeff1 => _word0.Extract(20, 20);
public int LumaCoeff2 => _word0.Extract(40, 20);
public int LumaRShift => _word0.Extract(60, 4);
public int LumaCoeff3 => _word1.Extract(64, 20);
public int LumaKeyLower => _word1.Extract(84, 10);
public int LumaKeyUpper => _word1.Extract(94, 10);
public int LumaCoeff0 => (int)_word0.Extract(0, 20);
public int LumaCoeff1 => (int)_word0.Extract(20, 20);
public int LumaCoeff2 => (int)_word0.Extract(40, 20);
public int LumaRShift => (int)_word0.Extract(60, 4);
public int LumaCoeff3 => (int)_word1.Extract(64, 20);
public int LumaKeyLower => (int)_word1.Extract(84, 10);
public int LumaKeyUpper => (int)_word1.Extract(94, 10);
public bool LumaKeyEnabled => _word1.Extract(104);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct MatrixStruct
{
@@ -7,19 +9,19 @@
private long _word2;
private long _word3;
public int MatrixCoeff00 => _word0.ExtractSx(0, 20);
public int MatrixCoeff10 => _word0.ExtractSx(20, 20);
public int MatrixCoeff20 => _word0.ExtractSx(40, 20);
public int MatrixRShift => _word0.Extract(60, 4);
public int MatrixCoeff01 => _word1.ExtractSx(64, 20);
public int MatrixCoeff11 => _word1.ExtractSx(84, 20);
public int MatrixCoeff21 => _word1.ExtractSx(104, 20);
public int MatrixCoeff00 => (int)_word0.ExtractSx(0, 20);
public int MatrixCoeff10 => (int)_word0.ExtractSx(20, 20);
public int MatrixCoeff20 => (int)_word0.ExtractSx(40, 20);
public int MatrixRShift => (int)_word0.Extract(60, 4);
public int MatrixCoeff01 => (int)_word1.ExtractSx(64, 20);
public int MatrixCoeff11 => (int)_word1.ExtractSx(84, 20);
public int MatrixCoeff21 => (int)_word1.ExtractSx(104, 20);
public bool MatrixEnable => _word1.Extract(127);
public int MatrixCoeff02 => _word2.ExtractSx(128, 20);
public int MatrixCoeff12 => _word2.ExtractSx(148, 20);
public int MatrixCoeff22 => _word2.ExtractSx(168, 20);
public int MatrixCoeff03 => _word3.ExtractSx(192, 20);
public int MatrixCoeff13 => _word3.ExtractSx(212, 20);
public int MatrixCoeff23 => _word3.ExtractSx(232, 20);
public int MatrixCoeff02 => (int)_word2.ExtractSx(128, 20);
public int MatrixCoeff12 => (int)_word2.ExtractSx(148, 20);
public int MatrixCoeff22 => (int)_word2.ExtractSx(168, 20);
public int MatrixCoeff03 => (int)_word3.ExtractSx(192, 20);
public int MatrixCoeff13 => (int)_word3.ExtractSx(212, 20);
public int MatrixCoeff23 => (int)_word3.ExtractSx(232, 20);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct OutputConfig
{
@@ -7,19 +9,19 @@
private long _word1;
#pragma warning restore CS0649
public int AlphaFillMode => _word0.Extract(0, 3);
public int AlphaFillSlot => _word0.Extract(3, 3);
public int BackgroundAlpha => _word0.Extract(6, 10);
public int BackgroundR => _word0.Extract(16, 10);
public int BackgroundG => _word0.Extract(26, 10);
public int BackgroundB => _word0.Extract(36, 10);
public int RegammaMode => _word0.Extract(46, 2);
public int AlphaFillMode => (int)_word0.Extract(0, 3);
public int AlphaFillSlot => (int)_word0.Extract(3, 3);
public int BackgroundAlpha => (int)_word0.Extract(6, 10);
public int BackgroundR => (int)_word0.Extract(16, 10);
public int BackgroundG => (int)_word0.Extract(26, 10);
public int BackgroundB => (int)_word0.Extract(36, 10);
public int RegammaMode => (int)_word0.Extract(46, 2);
public bool OutputFlipX => _word0.Extract(48);
public bool OutputFlipY => _word0.Extract(49);
public bool OutputTranspose => _word0.Extract(50);
public int TargetRectLeft => _word1.Extract(64, 14);
public int TargetRectRight => _word1.Extract(80, 14);
public int TargetRectTop => _word1.Extract(96, 14);
public int TargetRectBottom => _word1.Extract(112, 14);
public int TargetRectLeft => (int)_word1.Extract(64, 14);
public int TargetRectRight => (int)_word1.Extract(80, 14);
public int TargetRectTop => (int)_word1.Extract(96, 14);
public int TargetRectBottom => (int)_word1.Extract(112, 14);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct OutputSurfaceConfig
{
@@ -8,15 +10,15 @@
#pragma warning restore CS0649
public PixelFormat OutPixelFormat => (PixelFormat)_word0.Extract(0, 7);
public int OutChromaLocHoriz => _word0.Extract(7, 2);
public int OutChromaLocVert => _word0.Extract(9, 2);
public int OutBlkKind => _word0.Extract(11, 4);
public int OutBlkHeight => _word0.Extract(15, 4);
public int OutSurfaceWidth => _word0.Extract(32, 14);
public int OutSurfaceHeight => _word0.Extract(46, 14);
public int OutLumaWidth => _word1.Extract(64, 14);
public int OutLumaHeight => _word1.Extract(78, 14);
public int OutChromaWidth => _word1.Extract(96, 14);
public int OutChromaHeight => _word1.Extract(110, 14);
public int OutChromaLocHoriz => (int)_word0.Extract(7, 2);
public int OutChromaLocVert => (int)_word0.Extract(9, 2);
public int OutBlkKind => (int)_word0.Extract(11, 4);
public int OutBlkHeight => (int)_word0.Extract(15, 4);
public int OutSurfaceWidth => (int)_word0.Extract(32, 14);
public int OutSurfaceHeight => (int)_word0.Extract(46, 14);
public int OutLumaWidth => (int)_word1.Extract(64, 14);
public int OutLumaHeight => (int)_word1.Extract(78, 14);
public int OutChromaWidth => (int)_word1.Extract(96, 14);
public int OutChromaHeight => (int)_word1.Extract(110, 14);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct PipeConfig
{
@@ -7,7 +9,7 @@
private long _word1;
#pragma warning restore CS0169, CS0649
public int DownsampleHoriz => _word0.Extract(0, 11);
public int DownsampleVert => _word0.Extract(16, 11);
public int DownsampleHoriz => (int)_word0.Extract(0, 11);
public int DownsampleVert => (int)_word0.Extract(16, 11);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct SlotConfig
{
@@ -28,36 +30,36 @@
public bool PpMotionFieldEnable => _word0.Extract(14);
public bool CombMotionFieldEnable => _word0.Extract(15);
public FrameFormat FrameFormat => (FrameFormat)_word0.Extract(16, 4);
public int FilterLengthY => _word0.Extract(20, 2);
public int FilterLengthX => _word0.Extract(22, 2);
public int Panoramic => _word0.Extract(24, 12);
public int DetailFltClamp => _word0.Extract(58, 6);
public int FilterNoise => _word1.Extract(64, 10);
public int FilterDetail => _word1.Extract(74, 10);
public int ChromaNoise => _word1.Extract(84, 10);
public int ChromaDetail => _word1.Extract(94, 10);
public int FilterLengthY => (int)_word0.Extract(20, 2);
public int FilterLengthX => (int)_word0.Extract(22, 2);
public int Panoramic => (int)_word0.Extract(24, 12);
public int DetailFltClamp => (int)_word0.Extract(58, 6);
public int FilterNoise => (int)_word1.Extract(64, 10);
public int FilterDetail => (int)_word1.Extract(74, 10);
public int ChromaNoise => (int)_word1.Extract(84, 10);
public int ChromaDetail => (int)_word1.Extract(94, 10);
public DeinterlaceMode DeinterlaceMode => (DeinterlaceMode)_word1.Extract(104, 4);
public int MotionAccumWeight => _word1.Extract(108, 3);
public int NoiseIir => _word1.Extract(111, 11);
public int LightLevel => _word1.Extract(122, 4);
public int SoftClampLow => _word2.Extract(128, 10);
public int SoftClampHigh => _word2.Extract(138, 10);
public int PlanarAlpha => _word2.Extract(160, 10);
public int MotionAccumWeight => (int)_word1.Extract(108, 3);
public int NoiseIir => (int)_word1.Extract(111, 11);
public int LightLevel => (int)_word1.Extract(122, 4);
public int SoftClampLow => (int)_word2.Extract(128, 10);
public int SoftClampHigh => (int)_word2.Extract(138, 10);
public int PlanarAlpha => (int)_word2.Extract(160, 10);
public bool ConstantAlpha => _word2.Extract(170);
public int StereoInterleave => _word2.Extract(171, 3);
public int StereoInterleave => (int)_word2.Extract(171, 3);
public bool ClipEnabled => _word2.Extract(174);
public int ClearRectMask => _word2.Extract(175, 8);
public int DegammaMode => _word2.Extract(183, 2);
public int ClearRectMask => (int)_word2.Extract(175, 8);
public int DegammaMode => (int)_word2.Extract(183, 2);
public bool DecompressEnable => _word2.Extract(186);
public int DecompressCtbCount => _word3.Extract(192, 8);
public int DecompressZbcColor => _word3.Extract(200, 32);
public int SourceRectLeft => _word4.Extract(256, 30);
public int SourceRectRight => _word4.Extract(288, 30);
public int SourceRectTop => _word5.Extract(320, 30);
public int SourceRectBottom => _word5.Extract(352, 30);
public int DstRectLeft => _word6.Extract(384, 14);
public int DstRectRight => _word6.Extract(400, 14);
public int DstRectTop => _word6.Extract(416, 14);
public int DstRectBottom => _word6.Extract(432, 14);
public int DecompressCtbCount => (int)_word3.Extract(192, 8);
public int DecompressZbcColor => (int)_word3.Extract(200, 32);
public int SourceRectLeft => (int)_word4.Extract(256, 30);
public int SourceRectRight => (int)_word4.Extract(288, 30);
public int SourceRectTop => (int)_word5.Extract(320, 30);
public int SourceRectBottom => (int)_word5.Extract(352, 30);
public int DstRectLeft => (int)_word6.Extract(384, 14);
public int DstRectRight => (int)_word6.Extract(400, 14);
public int DstRectTop => (int)_word6.Extract(416, 14);
public int DstRectBottom => (int)_word6.Extract(432, 14);
}
}

View File

@@ -1,4 +1,6 @@
namespace Ryujinx.Graphics.Vic.Types
using Ryujinx.Common.Utilities;
namespace Ryujinx.Graphics.Vic.Types
{
struct SlotSurfaceConfig
{
@@ -6,16 +8,16 @@
private long _word1;
public PixelFormat SlotPixelFormat => (PixelFormat)_word0.Extract(0, 7);
public int SlotChromaLocHoriz => _word0.Extract(7, 2);
public int SlotChromaLocVert => _word0.Extract(9, 2);
public int SlotBlkKind => _word0.Extract(11, 4);
public int SlotBlkHeight => _word0.Extract(15, 4);
public int SlotCacheWidth => _word0.Extract(19, 3);
public int SlotSurfaceWidth => _word0.Extract(32, 14);
public int SlotSurfaceHeight => _word0.Extract(46, 14);
public int SlotLumaWidth => _word1.Extract(64, 14);
public int SlotLumaHeight => _word1.Extract(78, 14);
public int SlotChromaWidth => _word1.Extract(96, 14);
public int SlotChromaHeight => _word1.Extract(110, 14);
public int SlotChromaLocHoriz => (int)_word0.Extract(7, 2);
public int SlotChromaLocVert => (int)_word0.Extract(9, 2);
public int SlotBlkKind => (int)_word0.Extract(11, 4);
public int SlotBlkHeight => (int)_word0.Extract(15, 4);
public int SlotCacheWidth => (int)_word0.Extract(19, 3);
public int SlotSurfaceWidth => (int)_word0.Extract(32, 14);
public int SlotSurfaceHeight => (int)_word0.Extract(46, 14);
public int SlotLumaWidth => (int)_word1.Extract(64, 14);
public int SlotLumaHeight => (int)_word1.Extract(78, 14);
public int SlotChromaWidth => (int)_word1.Extract(96, 14);
public int SlotChromaHeight => (int)_word1.Extract(110, 14);
}
}

View File

@@ -1,4 +1,3 @@
using ARMeilleure.Translation.PTC;
using LibHac;
using LibHac.Account;
using LibHac.Common;
@@ -14,8 +13,8 @@ using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.Memory;
using System;
@@ -67,6 +66,8 @@ namespace Ryujinx.HLE.HOS
public string TitleIdText => TitleId.ToString("x16");
public IDiskCacheLoadState DiskCacheLoadState { get; private set; }
public ApplicationLoader(Switch device)
{
_device = device;
@@ -94,7 +95,7 @@ namespace Ryujinx.HLE.HOS
EnsureSaveData(new ApplicationId(TitleId));
}
LoadExeFs(codeFs, metaData);
LoadExeFs(codeFs, string.Empty, metaData);
}
public static (Nca main, Nca patch, Nca control) GetGameData(VirtualFileSystem fileSystem, PartitionFileSystem pfs, int programIndex)
@@ -302,12 +303,6 @@ namespace Ryujinx.HLE.HOS
public void LoadServiceNca(string ncaFile)
{
// Disable PPTC here as it does not support multiple processes running.
// TODO: This should be eventually removed and it should stop using global state and
// instead manage the cache per process.
Ptc.Close();
PtcProfiler.Stop();
FileStream file = new FileStream(ncaFile, FileMode.Open, FileAccess.Read);
Nca mainNca = new Nca(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false));
@@ -369,16 +364,12 @@ namespace Ryujinx.HLE.HOS
// Collect the nsos, ignoring ones that aren't used.
NsoExecutable[] programs = nsos.Where(x => x != null).ToArray();
MemoryManagerMode memoryManagerMode = _device.Configuration.MemoryManagerMode;
if (!MemoryBlock.SupportsFlags(MemoryAllocationFlags.ViewCompatible))
{
memoryManagerMode = MemoryManagerMode.SoftwarePageTable;
}
string displayVersion = _device.System.ContentManager.GetCurrentFirmwareVersion().VersionString;
bool usePtc = _device.System.EnablePtc;
metaData.GetNpdm(out Npdm npdm).ThrowIfFailure();
ProgramInfo programInfo = new ProgramInfo(in npdm, allowCodeMemoryForJit: false);
ProgramLoader.LoadNsos(_device.System.KernelContext, out _, metaData, programInfo, executables: programs);
ProgramInfo programInfo = new ProgramInfo(in npdm, displayVersion, usePtc, allowCodeMemoryForJit: false);
ProgramLoader.LoadNsos(_device.System.KernelContext, metaData, programInfo, executables: programs);
string titleIdText = npdm.Aci.Value.ProgramId.Value.ToString("x16");
bool titleIs64Bit = (npdm.Meta.Value.Flags & 1) != 0;
@@ -477,9 +468,11 @@ namespace Ryujinx.HLE.HOS
_device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
_device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath());
string displayVersion = string.Empty;
if (controlNca != null)
{
ReadControlData(_device, controlNca, ref _controlData, ref _titleName, ref _displayVersion);
ReadControlData(_device, controlNca, ref _controlData, ref _titleName, ref displayVersion);
}
else
{
@@ -493,9 +486,11 @@ namespace Ryujinx.HLE.HOS
string dummyTitleName = "";
BlitStruct<ApplicationControlProperty> dummyControl = new BlitStruct<ApplicationControlProperty>(1);
ReadControlData(_device, updateProgram0ControlNca, ref dummyControl, ref dummyTitleName, ref _displayVersion);
ReadControlData(_device, updateProgram0ControlNca, ref dummyControl, ref dummyTitleName, ref displayVersion);
}
_displayVersion = displayVersion;
if (dataStorage == null)
{
Logger.Warning?.Print(LogClass.Loader, "No RomFS found in NCA");
@@ -515,7 +510,7 @@ namespace Ryujinx.HLE.HOS
EnsureSaveData(new ApplicationId(TitleId & ~0xFul));
}
LoadExeFs(codeFs, metaData);
LoadExeFs(codeFs, displayVersion, metaData);
Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {TitleName} v{DisplayVersion} [{TitleIdText}] [{(TitleIs64Bit ? "64-bit" : "32-bit")}]");
}
@@ -584,7 +579,7 @@ namespace Ryujinx.HLE.HOS
}
}
private void LoadExeFs(IFileSystem codeFs, MetaLoader metaData = null, bool isHomebrew = false)
private void LoadExeFs(IFileSystem codeFs, string displayVersion, MetaLoader metaData = null, bool isHomebrew = false)
{
if (_device.Configuration.VirtualFileSystem.ModLoader.ReplaceExefsPartition(TitleId, ref codeFs))
{
@@ -649,23 +644,23 @@ namespace Ryujinx.HLE.HOS
memoryManagerMode = MemoryManagerMode.SoftwarePageTable;
}
Ptc.Initialize(TitleIdText, DisplayVersion, usePtc, memoryManagerMode);
// We allow it for nx-hbloader because it can be used to launch homebrew.
bool allowCodeMemoryForJit = TitleId == 0x010000000000100DUL || isHomebrew;
metaData.GetNpdm(out Npdm npdm).ThrowIfFailure();
ProgramInfo programInfo = new ProgramInfo(in npdm, allowCodeMemoryForJit);
ProgramLoader.LoadNsos(_device.System.KernelContext, out ProcessTamperInfo tamperInfo, metaData, programInfo, executables: programs);
ProgramInfo programInfo = new ProgramInfo(in npdm, displayVersion, usePtc, allowCodeMemoryForJit);
ProgramLoadResult result = ProgramLoader.LoadNsos(_device.System.KernelContext, metaData, programInfo, executables: programs);
_device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(TitleId, tamperInfo, _device.TamperMachine);
DiskCacheLoadState = result.DiskCacheLoadState;
_device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(TitleId, result.TamperInfo, _device.TamperMachine);
}
public void LoadProgram(string filePath)
{
MetaLoader metaData = GetDefaultNpdm();
metaData.GetNpdm(out Npdm npdm).ThrowIfFailure();
ProgramInfo programInfo = new ProgramInfo(in npdm, allowCodeMemoryForJit: true);
ProgramInfo programInfo = new ProgramInfo(in npdm, string.Empty, diskCacheEnabled: false, allowCodeMemoryForJit: true);
bool isNro = Path.GetExtension(filePath).ToLower() == ".nro";
@@ -761,9 +756,11 @@ namespace Ryujinx.HLE.HOS
Graphics.Gpu.GraphicsConfig.TitleId = null;
_device.Gpu.HostInitalized.Set();
ProgramLoader.LoadNsos(_device.System.KernelContext, out ProcessTamperInfo tamperInfo, metaData, programInfo, executables: executable);
ProgramLoadResult result = ProgramLoader.LoadNsos(_device.System.KernelContext, metaData, programInfo, executables: executable);
_device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(TitleId, tamperInfo, _device.TamperMachine);
DiskCacheLoadState = result.DiskCacheLoadState;
_device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(TitleId, result.TamperInfo, _device.TamperMachine);
}
private MetaLoader GetDefaultNpdm()

View File

@@ -6,7 +6,17 @@ using Ryujinx.Memory;
namespace Ryujinx.HLE.HOS
{
class ArmProcessContext<T> : IProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager
interface IArmProcessContext : IProcessContext
{
IDiskCacheLoadState Initialize(
string titleIdText,
string displayVersion,
bool diskCacheEnabled,
ulong codeAddress,
ulong codeSize);
}
class ArmProcessContext<T> : IArmProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager
{
private readonly ulong _pid;
private readonly GpuContext _gpuContext;
@@ -40,6 +50,17 @@ namespace Ryujinx.HLE.HOS
_cpuContext.Execute(context, codeAddress);
}
public IDiskCacheLoadState Initialize(
string titleIdText,
string displayVersion,
bool diskCacheEnabled,
ulong codeAddress,
ulong codeSize)
{
_cpuContext.PrepareCodeRange(codeAddress, codeSize);
return _cpuContext.LoadDiskCache(titleIdText, displayVersion, diskCacheEnabled);
}
public void InvalidateCacheRegion(ulong address, ulong size)
{
_cpuContext.InvalidateCacheRegion(address, size);

View File

@@ -13,11 +13,30 @@ namespace Ryujinx.HLE.HOS
{
private readonly ICpuEngine _cpuEngine;
private readonly GpuContext _gpu;
private readonly string _titleIdText;
private readonly string _displayVersion;
private readonly bool _diskCacheEnabled;
private readonly ulong _codeAddress;
private readonly ulong _codeSize;
public ArmProcessContextFactory(ICpuEngine cpuEngine, GpuContext gpu)
public IDiskCacheLoadState DiskCacheLoadState { get; private set; }
public ArmProcessContextFactory(
ICpuEngine cpuEngine,
GpuContext gpu,
string titleIdText,
string displayVersion,
bool diskCacheEnabled,
ulong codeAddress,
ulong codeSize)
{
_cpuEngine = cpuEngine;
_gpu = gpu;
_titleIdText = titleIdText;
_displayVersion = displayVersion;
_diskCacheEnabled = diskCacheEnabled;
_codeAddress = codeAddress;
_codeSize = codeSize;
}
public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
@@ -29,21 +48,29 @@ namespace Ryujinx.HLE.HOS
mode = MemoryManagerMode.SoftwarePageTable;
}
IArmProcessContext processContext;
switch (mode)
{
case MemoryManagerMode.SoftwarePageTable:
var memoryManager = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
return new ArmProcessContext<MemoryManager>(pid, _cpuEngine, _gpu, memoryManager, for64Bit);
processContext = new ArmProcessContext<MemoryManager>(pid, _cpuEngine, _gpu, memoryManager, for64Bit);
break;
case MemoryManagerMode.HostMapped:
case MemoryManagerMode.HostMappedUnsafe:
bool unsafeMode = mode == MemoryManagerMode.HostMappedUnsafe;
var memoryManagerHostMapped = new MemoryManagerHostMapped(context.Memory, addressSpaceSize, unsafeMode, invalidAccessHandler);
return new ArmProcessContext<MemoryManagerHostMapped>(pid, _cpuEngine, _gpu, memoryManagerHostMapped, for64Bit);
processContext = new ArmProcessContext<MemoryManagerHostMapped>(pid, _cpuEngine, _gpu, memoryManagerHostMapped, for64Bit);
break;
default:
throw new ArgumentOutOfRangeException();
}
DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize);
return processContext;
}
}
}

View File

@@ -36,6 +36,7 @@ using Ryujinx.HLE.HOS.Services.SurfaceFlinger;
using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.Horizon;
using System;
using System.Collections.Generic;
using System.IO;
@@ -319,6 +320,42 @@ namespace Ryujinx.HLE.HOS
ViServer = new ServerBase(KernelContext, "ViServerU");
ViServerM = new ServerBase(KernelContext, "ViServerM");
ViServerS = new ServerBase(KernelContext, "ViServerS");
StartNewServices();
}
private void StartNewServices()
{
var services = ServiceTable.GetServices(new HorizonOptions(Device.Configuration.IgnoreMissingServices));
foreach (var service in services)
{
const ProcessCreationFlags flags =
ProcessCreationFlags.EnableAslr |
ProcessCreationFlags.AddressSpace64Bit |
ProcessCreationFlags.Is64Bit |
ProcessCreationFlags.PoolPartitionSystem;
ProcessCreationInfo creationInfo = new ProcessCreationInfo("Service", 1, 0, 0x8000000, 1, flags, 0, 0);
int[] defaultCapabilities = new int[]
{
0x030363F7,
0x1FFFFFCF,
0x207FFFEF,
0x47E0060F,
0x0048BFFF,
0x01007FFF
};
// TODO:
// - Pass enough information (capabilities, process creation info, etc) on ServiceEntry for proper initialization.
// - Have the ThreadStart function take the syscall, address space and thread context parameters instead of passing them here.
KernelStatic.StartInitialProcess(KernelContext, creationInfo, defaultCapabilities, 44, () =>
{
service.Start(KernelContext.Syscall, KernelStatic.GetCurrentProcess().CpuMemory, KernelStatic.GetCurrentThread().ThreadContext);
});
}
}
public void LoadKip(string kipPath)

View File

@@ -1,3 +1,4 @@
using Ryujinx.Horizon.Common;
using System.Diagnostics;
using System.Threading;
@@ -16,24 +17,24 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
_referenceCount = 1;
}
public virtual KernelResult SetName(string name)
public virtual Result SetName(string name)
{
if (!KernelContext.AutoObjectNames.TryAdd(name, this))
{
return KernelResult.InvalidState;
}
return KernelResult.Success;
return Result.Success;
}
public static KernelResult RemoveName(KernelContext context, string name)
public static Result RemoveName(KernelContext context, string name)
{
if (!context.AutoObjectNames.TryRemove(name, out _))
{
return KernelResult.NotFound;
}
return KernelResult.Success;
return Result.Success;
}
public static KAutoObject FindNamedObject(KernelContext context, string name)

View File

@@ -1,5 +1,6 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel.Common
@@ -159,7 +160,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
}
}
public KernelResult SetLimitValue(LimitableResource resource, long limit)
public Result SetLimitValue(LimitableResource resource, long limit)
{
int index = GetIndex(resource);
@@ -170,7 +171,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
_limit[index] = limit;
_peak[index] = _current[index];
return KernelResult.Success;
return Result.Success;
}
else
{

View File

@@ -44,7 +44,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
public void ScheduleFutureInvocation(IKFutureSchedulerObject schedulerObj, long timeout)
{
long timePoint = PerformanceCounter.ElapsedTicks + ConvertNanosecondsToHostTicks(timeout);
long startTime = PerformanceCounter.ElapsedTicks;
long timePoint = startTime + ConvertNanosecondsToHostTicks(timeout);
if (timePoint < startTime)
{
timePoint = long.MaxValue;
}
lock (_context.CriticalSection.Lock)
{

View File

@@ -1,4 +1,5 @@
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Common
@@ -21,9 +22,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
public static void InitializeResourceLimit(KResourceLimit resourceLimit, MemorySize size)
{
void EnsureSuccess(KernelResult result)
void EnsureSuccess(Result result)
{
if (result != KernelResult.Success)
if (result != Result.Success)
{
throw new InvalidOperationException($"Unexpected result \"{result}\".");
}

View File

@@ -1,37 +0,0 @@
namespace Ryujinx.HLE.HOS.Kernel.Common
{
enum KernelResult
{
Success = 0,
SessionCountExceeded = 0xe01,
InvalidCapability = 0x1c01,
ThreadNotStarted = 0x7201,
ThreadTerminating = 0x7601,
InvalidSize = 0xca01,
InvalidAddress = 0xcc01,
OutOfResource = 0xce01,
OutOfMemory = 0xd001,
HandleTableFull = 0xd201,
InvalidMemState = 0xd401,
InvalidPermission = 0xd801,
InvalidMemRange = 0xdc01,
InvalidPriority = 0xe001,
InvalidCpuCore = 0xe201,
InvalidHandle = 0xe401,
UserCopyFailed = 0xe601,
InvalidCombination = 0xe801,
TimedOut = 0xea01,
Cancelled = 0xec01,
MaximumExceeded = 0xee01,
InvalidEnumValue = 0xf001,
NotFound = 0xf201,
InvalidThread = 0xf401,
PortRemoteClosed = 0xf601,
InvalidState = 0xfa01,
ReservedValue = 0xfc01,
PortClosed = 0x10601,
ResLimitExceeded = 0x10801,
OutOfVaSpace = 0x20601,
CmdBufferTooSmall = 0x20801
}
}

View File

@@ -1,11 +0,0 @@
using System;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
readonly struct OnScopeExit : IDisposable
{
private readonly Action _action;
public OnScopeExit(Action action) => _action = action;
public void Dispose() => _action();
}
}

View File

@@ -1,6 +1,6 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.Horizon.Common;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel.Ipc
@@ -20,38 +20,38 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
_exchangeBufferDescriptors = new List<KBufferDescriptor>(MaxInternalBuffersCount);
}
public KernelResult AddSendBuffer(ulong src, ulong dst, ulong size, MemoryState state)
public Result AddSendBuffer(ulong src, ulong dst, ulong size, MemoryState state)
{
return Add(_sendBufferDescriptors, src, dst, size, state);
}
public KernelResult AddReceiveBuffer(ulong src, ulong dst, ulong size, MemoryState state)
public Result AddReceiveBuffer(ulong src, ulong dst, ulong size, MemoryState state)
{
return Add(_receiveBufferDescriptors, src, dst, size, state);
}
public KernelResult AddExchangeBuffer(ulong src, ulong dst, ulong size, MemoryState state)
public Result AddExchangeBuffer(ulong src, ulong dst, ulong size, MemoryState state)
{
return Add(_exchangeBufferDescriptors, src, dst, size, state);
}
private KernelResult Add(List<KBufferDescriptor> list, ulong src, ulong dst, ulong size, MemoryState state)
private Result Add(List<KBufferDescriptor> list, ulong src, ulong dst, ulong size, MemoryState state)
{
if (list.Count < MaxInternalBuffersCount)
{
list.Add(new KBufferDescriptor(src, dst, size, state));
return KernelResult.Success;
return Result.Success;
}
return KernelResult.OutOfMemory;
}
public KernelResult CopyBuffersToClient(KPageTableBase memoryManager)
public Result CopyBuffersToClient(KPageTableBase memoryManager)
{
KernelResult result = CopyToClient(memoryManager, _receiveBufferDescriptors);
Result result = CopyToClient(memoryManager, _receiveBufferDescriptors);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -59,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return CopyToClient(memoryManager, _exchangeBufferDescriptors);
}
private KernelResult CopyToClient(KPageTableBase memoryManager, List<KBufferDescriptor> list)
private Result CopyToClient(KPageTableBase memoryManager, List<KBufferDescriptor> list)
{
foreach (KBufferDescriptor desc in list)
{
@@ -94,7 +94,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
copySize = desc.Size;
}
KernelResult result = memoryManager.CopyDataFromCurrentProcess(
Result result = memoryManager.CopyDataFromCurrentProcess(
desc.ClientAddress,
copySize,
stateMask,
@@ -104,7 +104,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MemoryAttribute.None,
desc.ServerAddress);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -120,7 +120,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
if (clientEndAddrTruncated < clientEndAddrRounded &&
(clientAddrTruncated == clientAddrRounded || clientAddrTruncated < clientEndAddrTruncated))
{
KernelResult result = memoryManager.CopyDataFromCurrentProcess(
Result result = memoryManager.CopyDataFromCurrentProcess(
clientEndAddrTruncated,
clientEndAddr - clientEndAddrTruncated,
stateMask,
@@ -130,28 +130,28 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MemoryAttribute.None,
serverEndAddrTruncated);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
}
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult UnmapServerBuffers(KPageTableBase memoryManager)
public Result UnmapServerBuffers(KPageTableBase memoryManager)
{
KernelResult result = UnmapServer(memoryManager, _sendBufferDescriptors);
Result result = UnmapServer(memoryManager, _sendBufferDescriptors);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = UnmapServer(memoryManager, _receiveBufferDescriptors);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -159,36 +159,36 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return UnmapServer(memoryManager, _exchangeBufferDescriptors);
}
private KernelResult UnmapServer(KPageTableBase memoryManager, List<KBufferDescriptor> list)
private Result UnmapServer(KPageTableBase memoryManager, List<KBufferDescriptor> list)
{
foreach (KBufferDescriptor descriptor in list)
{
KernelResult result = memoryManager.UnmapNoAttributeIfStateEquals(
Result result = memoryManager.UnmapNoAttributeIfStateEquals(
descriptor.ServerAddress,
descriptor.Size,
descriptor.State);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult RestoreClientBuffers(KPageTableBase memoryManager)
public Result RestoreClientBuffers(KPageTableBase memoryManager)
{
KernelResult result = RestoreClient(memoryManager, _sendBufferDescriptors);
Result result = RestoreClient(memoryManager, _sendBufferDescriptors);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = RestoreClient(memoryManager, _receiveBufferDescriptors);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -196,22 +196,22 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return RestoreClient(memoryManager, _exchangeBufferDescriptors);
}
private KernelResult RestoreClient(KPageTableBase memoryManager, List<KBufferDescriptor> list)
private Result RestoreClient(KPageTableBase memoryManager, List<KBufferDescriptor> list)
{
foreach (KBufferDescriptor descriptor in list)
{
KernelResult result = memoryManager.UnmapIpcRestorePermission(
Result result = memoryManager.UnmapIpcRestorePermission(
descriptor.ClientAddress,
descriptor.Size,
descriptor.State);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
}
return KernelResult.Success;
return Result.Success;
}
}
}

View File

@@ -1,5 +1,6 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel.Ipc
@@ -19,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
_parent = parent;
}
public KernelResult Connect(out KClientSession clientSession)
public Result Connect(out KClientSession clientSession)
{
clientSession = null;
@@ -40,9 +41,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
KSession session = new KSession(KernelContext, this);
KernelResult result = _parent.EnqueueIncomingSession(session.ServerSession);
Result result = _parent.EnqueueIncomingSession(session.ServerSession);
if (result != KernelResult.Success)
if (result != Result.Success)
{
session.ClientSession.DecrementReferenceCount();
session.ServerSession.DecrementReferenceCount();
@@ -55,7 +56,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return result;
}
public KernelResult ConnectLight(out KLightClientSession clientSession)
public Result ConnectLight(out KLightClientSession clientSession)
{
clientSession = null;
@@ -76,9 +77,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
KLightSession session = new KLightSession(KernelContext);
KernelResult result = _parent.EnqueueIncomingLightSession(session.ServerSession);
Result result = _parent.EnqueueIncomingLightSession(session.ServerSession);
if (result != KernelResult.Success)
if (result != Result.Success)
{
session.ClientSession.DecrementReferenceCount();
session.ServerSession.DecrementReferenceCount();
@@ -128,7 +129,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
public new static KernelResult RemoveName(KernelContext context, string name)
public new static Result RemoveName(KernelContext context, string name)
{
KAutoObject foundObj = FindNamedObject(context, name);

View File

@@ -1,6 +1,7 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
@@ -27,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
CreatorProcess.IncrementReferenceCount();
}
public KernelResult SendSyncRequest(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
public Result SendSyncRequest(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -36,13 +37,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
KernelContext.CriticalSection.Enter();
currentThread.SignaledObj = null;
currentThread.ObjSyncResult = KernelResult.Success;
currentThread.ObjSyncResult = Result.Success;
KernelResult result = _parent.ServerSession.EnqueueRequest(request);
Result result = _parent.ServerSession.EnqueueRequest(request);
KernelContext.CriticalSection.Leave();
if (result == KernelResult.Success)
if (result == Result.Success)
{
result = currentThread.ObjSyncResult;
}
@@ -50,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return result;
}
public KernelResult SendAsyncRequest(KWritableEvent asyncEvent, ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
public Result SendAsyncRequest(KWritableEvent asyncEvent, ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -58,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
KernelContext.CriticalSection.Enter();
KernelResult result = _parent.ServerSession.EnqueueRequest(request);
Result result = _parent.ServerSession.EnqueueRequest(request);
KernelContext.CriticalSection.Leave();

View File

@@ -1,4 +1,5 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
@@ -7,26 +8,26 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
public KServerPort ServerPort { get; }
public KClientPort ClientPort { get; }
private long _nameAddress;
private string _name;
private ChannelState _state;
public bool IsLight { get; private set; }
public KPort(KernelContext context, int maxSessions, bool isLight, long nameAddress) : base(context)
public KPort(KernelContext context, int maxSessions, bool isLight, string name) : base(context)
{
ServerPort = new KServerPort(context, this);
ClientPort = new KClientPort(context, this, maxSessions);
IsLight = isLight;
_nameAddress = nameAddress;
_name = name;
_state = ChannelState.Open;
}
public KernelResult EnqueueIncomingSession(KServerSession session)
public Result EnqueueIncomingSession(KServerSession session)
{
KernelResult result;
Result result;
KernelContext.CriticalSection.Enter();
@@ -34,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
ServerPort.EnqueueIncomingSession(session);
result = KernelResult.Success;
result = Result.Success;
}
else
{
@@ -46,9 +47,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return result;
}
public KernelResult EnqueueIncomingLightSession(KLightServerSession session)
public Result EnqueueIncomingLightSession(KLightServerSession session)
{
KernelResult result;
Result result;
KernelContext.CriticalSection.Enter();
@@ -56,7 +57,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
ServerPort.EnqueueIncomingLightSession(session);
result = KernelResult.Success;
result = Result.Success;
}
else
{

View File

@@ -3,6 +3,7 @@ using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel.Ipc
@@ -178,7 +179,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
_requests = new LinkedList<KSessionRequest>();
}
public KernelResult EnqueueRequest(KSessionRequest request)
public Result EnqueueRequest(KSessionRequest request)
{
if (_parent.ClientSession.State != ChannelState.Open)
{
@@ -203,10 +204,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
Signal();
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult Receive(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
public Result Receive(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
{
KThread serverThread = KernelStatic.GetCurrentThread();
KProcess serverProcess = serverThread.Owner;
@@ -249,12 +250,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg);
MessageHeader serverHeader = GetServerMessageHeader(serverMsg);
KernelResult serverResult = KernelResult.NotFound;
KernelResult clientResult = KernelResult.Success;
Result serverResult = KernelResult.NotFound;
Result clientResult = Result.Success;
void CleanUpForError()
{
if (request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager) == KernelResult.Success)
if (request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager) == Result.Success)
{
request.BufferDescriptorTable.RestoreClientBuffers(clientProcess.MemoryManager);
}
@@ -348,7 +349,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
int newHandle = 0;
int handle = clientProcess.CpuMemory.Read<int>(clientMsg.Address + offset * 4);
if (clientResult == KernelResult.Success && handle != 0)
if (clientResult == Result.Success && handle != 0)
{
clientResult = GetCopyObjectHandle(clientThread, serverProcess, handle, out newHandle);
}
@@ -365,7 +366,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
if (handle != 0)
{
if (clientResult == KernelResult.Success)
if (clientResult == Result.Success)
{
clientResult = GetMoveObjectHandle(clientProcess, serverProcess, handle, out newHandle);
}
@@ -380,7 +381,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset++;
}
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -412,7 +413,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ref recvListDstOffset,
out ulong recvListBufferAddress);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -429,7 +430,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MemoryAttribute.Uncached,
MemoryAttribute.None);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -498,7 +499,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
notReceiveDesc,
out dstAddress);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -518,7 +519,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
clientResult = request.BufferDescriptorTable.AddExchangeBuffer(bufferAddress, dstAddress, bufferSize, state);
}
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -573,7 +574,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
}
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -581,10 +582,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult Reply(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
public Result Reply(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
{
KThread serverThread = KernelStatic.GetCurrentThread();
KProcess serverProcess = serverThread.Owner;
@@ -618,8 +619,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg);
MessageHeader serverHeader = GetServerMessageHeader(serverMsg);
KernelResult clientResult = KernelResult.Success;
KernelResult serverResult = KernelResult.Success;
Result clientResult = Result.Success;
Result serverResult = Result.Success;
void CleanUpForError()
{
@@ -683,7 +684,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
// Copy receive and exchange buffers.
clientResult = request.BufferDescriptorTable.CopyBuffersToClient(clientProcess.MemoryManager);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -734,7 +735,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
if (handle != 0)
{
if (clientResult == KernelResult.Success)
if (clientResult == Result.Success)
{
clientResult = GetMoveObjectHandle(serverProcess, clientProcess, handle, out newHandle);
}
@@ -776,7 +777,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ref recvListDstOffset,
out recvListBufferAddress);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -793,7 +794,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
MemoryAttribute.None,
descriptor.BufferAddress);
if (clientResult != KernelResult.Success)
if (clientResult != Result.Success)
{
CleanUpForError();
@@ -888,7 +889,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return new MessageHeader(word0, word1, word2);
}
private KernelResult GetCopyObjectHandle(KThread srcThread, KProcess dstProcess, int srcHandle, out int dstHandle)
private Result GetCopyObjectHandle(KThread srcThread, KProcess dstProcess, int srcHandle, out int dstHandle)
{
dstHandle = 0;
@@ -919,7 +920,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
private KernelResult GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle)
private Result GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle)
{
dstHandle = 0;
@@ -927,7 +928,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
if (obj != null)
{
KernelResult result = dstProcess.HandleTable.GenerateHandle(obj, out dstHandle);
Result result = dstProcess.HandleTable.GenerateHandle(obj, out dstHandle);
srcProcess.HandleTable.CloseHandle(srcHandle);
@@ -964,7 +965,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return receiveList;
}
private KernelResult GetReceiveListAddress(
private Result GetReceiveListAddress(
PointerBufferDesc descriptor,
Message message,
uint recvListType,
@@ -1038,7 +1039,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
address = recvListBufferAddress;
return KernelResult.Success;
return Result.Success;
}
private void CloseAllHandles(Message message, MessageHeader header, KProcess process)
@@ -1166,19 +1167,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return hasRequest;
}
private void FinishRequest(KSessionRequest request, KernelResult result)
private void FinishRequest(KSessionRequest request, Result result)
{
KProcess clientProcess = request.ClientThread.Owner;
KProcess serverProcess = request.ServerProcess;
KernelResult unmapResult = KernelResult.Success;
Result unmapResult = Result.Success;
if (serverProcess != null)
{
unmapResult = request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager);
}
if (unmapResult == KernelResult.Success)
if (unmapResult == Result.Success)
{
request.BufferDescriptorTable.RestoreClientBuffers(clientProcess.MemoryManager);
}
@@ -1186,7 +1187,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
WakeClientThread(request, result);
}
private void WakeClientThread(KSessionRequest request, KernelResult result)
private void WakeClientThread(KSessionRequest request, Result result)
{
// Wait client thread waiting for a response for the given request.
if (request.AsyncEvent != null)
@@ -1203,16 +1204,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
private void SendResultToAsyncRequestClient(KSessionRequest request, KernelResult result)
private void SendResultToAsyncRequestClient(KSessionRequest request, Result result)
{
KProcess clientProcess = request.ClientThread.Owner;
if (result != KernelResult.Success)
if (result != Result.Success)
{
ulong address = request.CustomCmdBuffAddr;
clientProcess.CpuMemory.Write<ulong>(address, 0);
clientProcess.CpuMemory.Write(address + 8, (int)result);
clientProcess.CpuMemory.Write(address + 8, result.ErrorCode);
}
clientProcess.MemoryManager.UnborrowIpcBuffer(request.CustomCmdBuffAddr, request.CustomCmdBuffSize);
@@ -1220,24 +1221,24 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
request.AsyncEvent.Signal();
}
private void WakeServerThreads(KernelResult result)
private void WakeServerThreads(Result result)
{
// Wake all server threads waiting for requests.
KernelContext.CriticalSection.Enter();
foreach (KThread thread in WaitingThreads)
{
WakeAndSetResult(thread, result);
WakeAndSetResult(thread, result, this);
}
KernelContext.CriticalSection.Leave();
}
private void WakeAndSetResult(KThread thread, KernelResult result)
private void WakeAndSetResult(KThread thread, Result result, KSynchronizationObject signaledObj = null)
{
if ((thread.SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused)
{
thread.SignaledObj = null;
thread.SignaledObj = signaledObj;
thread.ObjSyncResult = result;
thread.Reschedule(ThreadSchedState.Running);

View File

@@ -2,6 +2,7 @@
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
using System.Threading;
@@ -15,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Kernel
[ThreadStatic]
private static KThread CurrentThread;
public static KernelResult StartInitialProcess(
public static Result StartInitialProcess(
KernelContext context,
ProcessCreationInfo creationInfo,
ReadOnlySpan<int> capabilities,
@@ -24,7 +25,7 @@ namespace Ryujinx.HLE.HOS.Kernel
{
KProcess process = new KProcess(context);
KernelResult result = process.Initialize(
Result result = process.Initialize(
creationInfo,
capabilities,
context.ResourceLimit,
@@ -32,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Kernel
null,
customThreadStart);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}

View File

@@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
using System;
using System.Diagnostics;
@@ -21,13 +22,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_lock = new object();
}
public KernelResult Initialize(ulong address, ulong size)
public Result Initialize(ulong address, ulong size)
{
Owner = KernelStatic.GetCurrentProcess();
KernelResult result = Owner.MemoryManager.BorrowCodeMemory(_pageList, address, size);
Result result = Owner.MemoryManager.BorrowCodeMemory(_pageList, address, size);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -39,10 +40,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isMapped = false;
_isOwnerMapped = false;
return KernelResult.Success;
return Result.Success;
}
public KernelResult Map(ulong address, ulong size, KMemoryPermission perm)
public Result Map(ulong address, ulong size, KMemoryPermission perm)
{
if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
@@ -58,9 +59,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KProcess process = KernelStatic.GetCurrentProcess();
KernelResult result = process.MemoryManager.MapPages(address, _pageList, MemoryState.CodeWritable, KMemoryPermission.ReadAndWrite);
Result result = process.MemoryManager.MapPages(address, _pageList, MemoryState.CodeWritable, KMemoryPermission.ReadAndWrite);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -68,10 +69,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isMapped = true;
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult MapToOwner(ulong address, ulong size, KMemoryPermission permission)
public Result MapToOwner(ulong address, ulong size, KMemoryPermission permission)
{
if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
@@ -87,9 +88,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
Debug.Assert(permission == KMemoryPermission.Read || permission == KMemoryPermission.ReadAndExecute);
KernelResult result = Owner.MemoryManager.MapPages(address, _pageList, MemoryState.CodeReadOnly, permission);
Result result = Owner.MemoryManager.MapPages(address, _pageList, MemoryState.CodeReadOnly, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -97,10 +98,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isOwnerMapped = true;
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult Unmap(ulong address, ulong size)
public Result Unmap(ulong address, ulong size)
{
if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
@@ -111,9 +112,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
KProcess process = KernelStatic.GetCurrentProcess();
KernelResult result = process.MemoryManager.UnmapPages(address, _pageList, MemoryState.CodeWritable);
Result result = process.MemoryManager.UnmapPages(address, _pageList, MemoryState.CodeWritable);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -123,10 +124,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isMapped = false;
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult UnmapFromOwner(ulong address, ulong size)
public Result UnmapFromOwner(ulong address, ulong size)
{
if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{
@@ -135,9 +136,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
lock (_lock)
{
KernelResult result = Owner.MemoryManager.UnmapPages(address, _pageList, MemoryState.CodeReadOnly);
Result result = Owner.MemoryManager.UnmapPages(address, _pageList, MemoryState.CodeReadOnly);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -147,7 +148,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isOwnerMapped = false;
}
return KernelResult.Success;
return Result.Success;
}
protected override void Destroy()
@@ -156,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong size = _pageList.GetPagesCount() * KPageTableBase.PageSize;
if (Owner.MemoryManager.UnborrowCodeMemory(_address, size, _pageList) != KernelResult.Success)
if (Owner.MemoryManager.UnborrowCodeMemory(_address, size, _pageList) != Result.Success)
{
throw new InvalidOperationException("Unexpected failure restoring transfer memory attributes.");
}

View File

@@ -1,5 +1,5 @@
using Ryujinx.Common.Collections;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
using System.Diagnostics;
namespace Ryujinx.HLE.HOS.Kernel.Memory
@@ -22,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockTree = new IntrusiveRedBlackTree<KMemoryBlock>();
}
public KernelResult Initialize(ulong addrSpaceStart, ulong addrSpaceEnd, KMemoryBlockSlabManager slabManager)
public Result Initialize(ulong addrSpaceStart, ulong addrSpaceEnd, KMemoryBlockSlabManager slabManager)
{
_slabManager = slabManager;
_addrSpaceStart = addrSpaceStart;
@@ -43,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KMemoryPermission.None,
MemoryAttribute.None));
return KernelResult.Success;
return Result.Success;
}
public void InsertBlock(

View File

@@ -1,4 +1,4 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
using System.Diagnostics;
namespace Ryujinx.HLE.HOS.Kernel.Memory
@@ -25,20 +25,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_pageHeap.UpdateUsedSize();
}
public KernelResult AllocatePages(out KPageList pageList, ulong pagesCount)
public Result AllocatePages(out KPageList pageList, ulong pagesCount)
{
if (pagesCount == 0)
{
pageList = new KPageList();
return KernelResult.Success;
return Result.Success;
}
lock (_pageHeap)
{
KernelResult result = AllocatePagesImpl(out pageList, pagesCount, false);
Result result = AllocatePagesImpl(out pageList, pagesCount, false);
if (result == KernelResult.Success)
if (result == Result.Success)
{
foreach (var node in pageList)
{
@@ -71,7 +71,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
private KernelResult AllocatePagesImpl(out KPageList pageList, ulong pagesCount, bool random)
private Result AllocatePagesImpl(out KPageList pageList, ulong pagesCount, bool random)
{
pageList = new KPageList();
@@ -95,9 +95,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
break;
}
KernelResult result = pageList.AddRange(allocatedBlock, pagesPerAlloc);
Result result = pageList.AddRange(allocatedBlock, pagesPerAlloc);
if (result != KernelResult.Success)
if (result != Result.Success)
{
FreePages(pageList);
_pageHeap.Free(allocatedBlock, pagesPerAlloc);
@@ -116,7 +116,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfMemory;
}
return KernelResult.Success;
return Result.Success;
}
private ulong AllocatePagesContiguousImpl(ulong pagesCount, ulong alignPages, bool random)

View File

@@ -1,4 +1,4 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
using System.Collections;
using System.Collections.Generic;
@@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
Nodes = new LinkedList<KPageNode>();
}
public KernelResult AddRange(ulong address, ulong pagesCount)
public Result AddRange(ulong address, ulong pagesCount)
{
if (pagesCount != 0)
{
@@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
Nodes.AddLast(new KPageNode(address, pagesCount));
}
return KernelResult.Success;
return Result.Success;
}
public ulong GetPagesCount()

View File

@@ -1,4 +1,4 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Diagnostics;
@@ -31,31 +31,31 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
/// <inheritdoc/>
protected override KernelResult MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission)
protected override Result MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission)
{
KPageList pageList = new KPageList();
GetPhysicalRegions(src, pagesCount * PageSize, pageList);
KernelResult result = Reprotect(src, pagesCount, KMemoryPermission.None);
Result result = Reprotect(src, pagesCount, KMemoryPermission.None);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = MapPages(dst, pageList, newDstPermission, false, 0);
if (result != KernelResult.Success)
if (result != Result.Success)
{
KernelResult reprotectResult = Reprotect(src, pagesCount, oldSrcPermission);
Debug.Assert(reprotectResult == KernelResult.Success);
Result reprotectResult = Reprotect(src, pagesCount, oldSrcPermission);
Debug.Assert(reprotectResult == Result.Success);
}
return result;
}
/// <inheritdoc/>
protected override KernelResult UnmapMemory(ulong dst, ulong src, ulong pagesCount, KMemoryPermission oldDstPermission, KMemoryPermission newSrcPermission)
protected override Result UnmapMemory(ulong dst, ulong src, ulong pagesCount, KMemoryPermission oldDstPermission, KMemoryPermission newSrcPermission)
{
ulong size = pagesCount * PageSize;
@@ -70,26 +70,26 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.InvalidMemRange;
}
KernelResult result = Unmap(dst, pagesCount);
Result result = Unmap(dst, pagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = Reprotect(src, pagesCount, newSrcPermission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
KernelResult mapResult = MapPages(dst, dstPageList, oldDstPermission, false, 0);
Debug.Assert(mapResult == KernelResult.Success);
Result mapResult = MapPages(dst, dstPageList, oldDstPermission, false, 0);
Debug.Assert(mapResult == Result.Success);
}
return result;
}
/// <inheritdoc/>
protected override KernelResult MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission, bool shouldFillPages, byte fillValue)
protected override Result MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission, bool shouldFillPages, byte fillValue)
{
ulong size = pagesCount * PageSize;
@@ -107,11 +107,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_cpuMemory.Fill(dstVa, size, fillValue);
}
return KernelResult.Success;
return Result.Success;
}
/// <inheritdoc/>
protected override KernelResult MapPages(ulong address, KPageList pageList, KMemoryPermission permission, bool shouldFillPages, byte fillValue)
protected override Result MapPages(ulong address, KPageList pageList, KMemoryPermission permission, bool shouldFillPages, byte fillValue)
{
using var scopedPageList = new KScopedPageList(Context.MemoryManager, pageList);
@@ -136,11 +136,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
scopedPageList.SignalSuccess();
return KernelResult.Success;
return Result.Success;
}
/// <inheritdoc/>
protected override KernelResult Unmap(ulong address, ulong pagesCount)
protected override Result Unmap(ulong address, ulong pagesCount)
{
KPageList pagesToClose = new KPageList();
@@ -159,21 +159,21 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
pagesToClose.DecrementPagesReferenceCount(Context.MemoryManager);
return KernelResult.Success;
return Result.Success;
}
/// <inheritdoc/>
protected override KernelResult Reprotect(ulong address, ulong pagesCount, KMemoryPermission permission)
protected override Result Reprotect(ulong address, ulong pagesCount, KMemoryPermission permission)
{
// TODO.
return KernelResult.Success;
return Result.Success;
}
/// <inheritdoc/>
protected override KernelResult ReprotectWithAttributes(ulong address, ulong pagesCount, KMemoryPermission permission)
protected override Result ReprotectWithAttributes(ulong address, ulong pagesCount, KMemoryPermission permission)
{
// TODO.
return KernelResult.Success;
return Result.Success;
}
/// <inheritdoc/>

View File

@@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -88,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
private static readonly int[] AddrSpaceSizes = new int[] { 32, 36, 32, 39 };
public KernelResult InitializeForProcess(
public Result InitializeForProcess(
AddressSpaceType addrSpaceType,
bool aslrEnabled,
bool aslrDisabled,
@@ -107,7 +108,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong addrSpaceBase = 0;
ulong addrSpaceSize = 1UL << AddrSpaceSizes[(int)addrSpaceType];
KernelResult result = CreateUserAddressSpace(
Result result = CreateUserAddressSpace(
addrSpaceType,
aslrEnabled,
aslrDisabled,
@@ -118,7 +119,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
size,
slabManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Context.ContextIdManager.PutId(_contextId);
}
@@ -134,7 +135,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public ulong AslrOffset;
}
private KernelResult CreateUserAddressSpace(
private Result CreateUserAddressSpace(
AddressSpaceType addrSpaceType,
bool aslrEnabled,
bool aslrDisabled,
@@ -342,7 +343,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult MapPages(ulong address, KPageList pageList, MemoryState state, KMemoryPermission permission)
public Result MapPages(ulong address, KPageList pageList, MemoryState state, KMemoryPermission permission)
{
ulong pagesCount = pageList.GetPagesCount();
@@ -365,9 +366,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
KernelResult result = MapPages(address, pageList, permission);
Result result = MapPages(address, pageList, permission);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_blockManager.InsertBlock(address, pagesCount, state, permission);
}
@@ -376,7 +377,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnmapPages(ulong address, KPageList pageList, MemoryState stateExpected)
public Result UnmapPages(ulong address, KPageList pageList, MemoryState stateExpected)
{
ulong pagesCount = pageList.GetPagesCount();
ulong size = pagesCount * PageSize;
@@ -430,9 +431,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
KernelResult result = Unmap(address, pagesCount);
Result result = Unmap(address, pagesCount);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_blockManager.InsertBlock(address, pagesCount, MemoryState.Unmapped);
}
@@ -446,19 +447,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult MapNormalMemory(long address, long size, KMemoryPermission permission)
public Result MapNormalMemory(long address, long size, KMemoryPermission permission)
{
// TODO.
return KernelResult.Success;
return Result.Success;
}
public KernelResult MapIoMemory(long address, long size, KMemoryPermission permission)
public Result MapIoMemory(long address, long size, KMemoryPermission permission)
{
// TODO.
return KernelResult.Success;
return Result.Success;
}
public KernelResult MapPages(
public Result MapPages(
ulong pagesCount,
int alignment,
ulong srcPa,
@@ -497,7 +498,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
KernelResult result;
Result result;
if (paIsValid)
{
@@ -508,7 +509,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
result = AllocateAndMapPages(address, pagesCount, permission);
}
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -516,10 +517,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, state, permission);
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult MapPages(ulong address, ulong pagesCount, MemoryState state, KMemoryPermission permission)
public Result MapPages(ulong address, ulong pagesCount, MemoryState state, KMemoryPermission permission)
{
ulong size = pagesCount * PageSize;
@@ -540,9 +541,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
KernelResult result = AllocateAndMapPages(address, pagesCount, permission);
Result result = AllocateAndMapPages(address, pagesCount, permission);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_blockManager.InsertBlock(address, pagesCount, state, permission);
}
@@ -551,13 +552,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
private KernelResult AllocateAndMapPages(ulong address, ulong pagesCount, KMemoryPermission permission)
private Result AllocateAndMapPages(ulong address, ulong pagesCount, KMemoryPermission permission)
{
KMemoryRegionManager region = GetMemoryRegionManager();
KernelResult result = region.AllocatePages(out KPageList pageList, pagesCount);
Result result = region.AllocatePages(out KPageList pageList, pagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -567,7 +568,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return MapPages(address, pageList, permission);
}
public KernelResult MapProcessCodeMemory(ulong dst, ulong src, ulong size)
public Result MapProcessCodeMemory(ulong dst, ulong src, ulong size)
{
lock (_blockManager)
{
@@ -596,12 +597,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result = MapMemory(src, dst, pagesCount, permission, KMemoryPermission.None);
Result result = MapMemory(src, dst, pagesCount, permission, KMemoryPermission.None);
_blockManager.InsertBlock(src, pagesCount, state, KMemoryPermission.None, MemoryAttribute.Borrowed);
_blockManager.InsertBlock(dst, pagesCount, MemoryState.ModCodeStatic);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -610,7 +611,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnmapProcessCodeMemory(ulong dst, ulong src, ulong size)
public Result UnmapProcessCodeMemory(ulong dst, ulong src, ulong size)
{
lock (_blockManager)
{
@@ -656,9 +657,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong pagesCount = size / PageSize;
KernelResult result = Unmap(dst, pagesCount);
Result result = Unmap(dst, pagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -673,7 +674,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(dst, pagesCount, MemoryState.Unmapped);
_blockManager.InsertBlock(src, pagesCount, MemoryState.Heap, KMemoryPermission.ReadAndWrite);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -682,7 +683,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult SetHeapSize(ulong size, out ulong address)
public Result SetHeapSize(ulong size, out ulong address)
{
address = 0;
@@ -712,7 +713,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KMemoryRegionManager region = GetMemoryRegionManager();
KernelResult result = region.AllocatePages(out KPageList pageList, pagesCount);
Result result = region.AllocatePages(out KPageList pageList, pagesCount);
using var _ = new OnScopeExit(() => pageList.DecrementPagesReferenceCount(Context.MemoryManager));
@@ -724,7 +725,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -747,7 +748,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
result = MapPages(_currentHeapAddr, pageList, KMemoryPermission.ReadAndWrite, true, (byte)_heapFillValue);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -786,9 +787,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = sizeDelta / PageSize;
KernelResult result = Unmap(freeAddr, pagesCount);
Result result = Unmap(freeAddr, pagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -803,10 +804,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
address = HeapRegionStart;
return KernelResult.Success;
return Result.Success;
}
public KernelResult SetMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
public Result SetMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
{
lock (_blockManager)
{
@@ -833,9 +834,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result = Reprotect(address, pagesCount, permission);
Result result = Reprotect(address, pagesCount, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -843,7 +844,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, oldState, permission);
}
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -865,17 +866,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return _currentHeapAddr - HeapRegionStart;
}
public KernelResult SetHeapCapacity(ulong capacity)
public Result SetHeapCapacity(ulong capacity)
{
lock (_blockManager)
{
_heapCapacity = capacity;
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult SetMemoryAttribute(
public Result SetMemoryAttribute(
ulong address,
ulong size,
MemoryAttribute attributeMask,
@@ -909,7 +910,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, state, permission, attribute);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -942,7 +943,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult Map(ulong dst, ulong src, ulong size)
public Result Map(ulong dst, ulong src, ulong size)
{
bool success;
@@ -973,9 +974,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result = MapMemory(src, dst, pagesCount, KMemoryPermission.ReadAndWrite, KMemoryPermission.ReadAndWrite);
Result result = MapMemory(src, dst, pagesCount, KMemoryPermission.ReadAndWrite, KMemoryPermission.ReadAndWrite);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -983,7 +984,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(src, pagesCount, srcState, KMemoryPermission.None, MemoryAttribute.Borrowed);
_blockManager.InsertBlock(dst, pagesCount, MemoryState.Stack, KMemoryPermission.ReadAndWrite);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -992,7 +993,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnmapForKernel(ulong address, ulong pagesCount, MemoryState stateExpected)
public Result UnmapForKernel(ulong address, ulong pagesCount, MemoryState stateExpected)
{
ulong size = pagesCount * PageSize;
@@ -1017,14 +1018,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
KernelResult result = Unmap(address, pagesCount);
Result result = Unmap(address, pagesCount);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_blockManager.InsertBlock(address, pagesCount, MemoryState.Unmapped);
}
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -1033,7 +1034,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult Unmap(ulong dst, ulong src, ulong size)
public Result Unmap(ulong dst, ulong src, ulong size)
{
bool success;
@@ -1076,9 +1077,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result = UnmapMemory(dst, src, pagesCount, dstPermission, KMemoryPermission.ReadAndWrite);
Result result = UnmapMemory(dst, src, pagesCount, dstPermission, KMemoryPermission.ReadAndWrite);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -1086,7 +1087,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(src, pagesCount, srcState, KMemoryPermission.ReadAndWrite);
_blockManager.InsertBlock(dst, pagesCount, MemoryState.Unmapped);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -1095,7 +1096,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnmapProcessMemory(ulong dst, ulong size, KPageTableBase srcPageTable, ulong src)
public Result UnmapProcessMemory(ulong dst, ulong size, KPageTableBase srcPageTable, ulong src)
{
lock (_blockManager)
{
@@ -1153,20 +1154,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result = Unmap(dst, pagesCount);
Result result = Unmap(dst, pagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
_blockManager.InsertBlock(dst, pagesCount, MemoryState.Unmapped);
return KernelResult.Success;
return Result.Success;
}
}
public KernelResult SetProcessMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
public Result SetProcessMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
{
lock (_blockManager)
{
@@ -1213,7 +1214,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = size / PageSize;
KernelResult result;
Result result;
if ((oldPermission & KMemoryPermission.Execute) != 0)
{
@@ -1224,7 +1225,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
result = Reprotect(address, pagesCount, permission);
}
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -1232,7 +1233,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, newState, permission);
}
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -1241,7 +1242,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult MapPhysicalMemory(ulong address, ulong size)
public Result MapPhysicalMemory(ulong address, ulong size)
{
ulong endAddr = address + size;
@@ -1259,7 +1260,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (mappedSize == size)
{
return KernelResult.Success;
return Result.Success;
}
ulong remainingSize = size - mappedSize;
@@ -1276,7 +1277,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KMemoryRegionManager region = GetMemoryRegionManager();
KernelResult result = region.AllocatePages(out KPageList pageList, remainingPages);
Result result = region.AllocatePages(out KPageList pageList, remainingPages);
using var _ = new OnScopeExit(() => pageList.DecrementPagesReferenceCount(Context.MemoryManager));
@@ -1285,7 +1286,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
currentProcess.ResourceLimit?.Release(LimitableResource.Memory, remainingSize);
}
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -1357,10 +1358,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryAttribute.None);
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult UnmapPhysicalMemory(ulong address, ulong size)
public Result UnmapPhysicalMemory(ulong address, ulong size)
{
ulong endAddr = address + size;
@@ -1391,7 +1392,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (heapMappedSize == 0)
{
return KernelResult.Success;
return Result.Success;
}
if (!_slabManager.CanAllocate(MaxBlocksNeededForInsertion))
@@ -1400,7 +1401,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
// Try to unmap all the heap mapped memory inside range.
KernelResult result = KernelResult.Success;
Result result = Result.Success;
foreach (KMemoryInfo info in IterateOverRange(address, endAddr))
{
@@ -1416,11 +1417,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
// The kernel would attempt to remap if this fails, but we don't because:
// - The implementation may not support remapping if memory aliasing is not supported on the platform.
// - Unmap can't ever fail here anyway.
Debug.Assert(result == KernelResult.Success);
Debug.Assert(result == Result.Success);
}
}
if (result == KernelResult.Success)
if (result == Result.Success)
{
PhysicalMemoryUsage -= heapMappedSize;
@@ -1437,7 +1438,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult CopyDataToCurrentProcess(
public Result CopyDataToCurrentProcess(
ulong dst,
ulong size,
ulong src,
@@ -1460,7 +1461,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
toServer: true);
}
public KernelResult CopyDataFromCurrentProcess(
public Result CopyDataFromCurrentProcess(
ulong dst,
ulong size,
MemoryState stateMask,
@@ -1483,7 +1484,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
toServer: false);
}
private KernelResult CopyDataFromOrToCurrentProcess(
private Result CopyDataFromOrToCurrentProcess(
ulong size,
ulong clientAddress,
ulong serverAddress,
@@ -1543,7 +1544,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
size -= copySize;
}
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -1552,7 +1553,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult MapBufferFromClientProcess(
public Result MapBufferFromClientProcess(
ulong size,
ulong src,
KPageTableBase srcPageTable,
@@ -1567,14 +1568,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
lock (_blockManager)
{
KernelResult result = srcPageTable.ReprotectClientProcess(
Result result = srcPageTable.ReprotectClientProcess(
src,
size,
permission,
state,
out int blocksNeeded);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -1590,7 +1591,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
result = MapPagesFromClientProcess(size, src, permission, state, srcPageTable, send, out ulong va);
if (result != KernelResult.Success)
if (result != Result.Success)
{
if (srcMapEndAddr > srcMapAddress)
{
@@ -1613,10 +1614,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
return KernelResult.Success;
return Result.Success;
}
private KernelResult ReprotectClientProcess(
private Result ReprotectClientProcess(
ulong address,
ulong size,
KMemoryPermission permission,
@@ -1689,8 +1690,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong blockPagesCount = blockSize / PageSize;
KernelResult reprotectResult = Reprotect(blockAddress, blockPagesCount, info.Permission);
Debug.Assert(reprotectResult == KernelResult.Success);
Result reprotectResult = Reprotect(blockAddress, blockPagesCount, info.Permission);
Debug.Assert(reprotectResult == Result.Success);
}
}
}
@@ -1699,7 +1700,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
SignalMemoryTracking(addressTruncated, endAddrRounded - addressTruncated, false);
// Reprotect the aligned pages range on the client to make them inaccessible from the client process.
KernelResult result;
Result result;
if (addressRounded < endAddrTruncated)
{
@@ -1736,7 +1737,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
result = Reprotect(blockAddress, blockPagesCount, permissionMask);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -1748,10 +1749,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
return KernelResult.Success;
return Result.Success;
}
private KernelResult MapPagesFromClientProcess(
private Result MapPagesFromClientProcess(
ulong size,
ulong address,
KMemoryPermission permission,
@@ -1877,9 +1878,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
Context.Memory.Fill(GetDramAddressFromPa(firstPageFillAddress), unusedSizeAfter, (byte)_ipcFillValue);
}
KernelResult result = MapPages(currentVa, 1, dstFirstPagePa, permission);
Result result = MapPages(currentVa, 1, dstFirstPagePa, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -1896,9 +1897,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KPageList pageList = new KPageList();
srcPageTable.GetPhysicalRegions(addressRounded, alignedSize, pageList);
KernelResult result = MapPages(currentVa, pageList, permission);
Result result = MapPages(currentVa, pageList, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -1931,9 +1932,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
Context.Memory.Fill(GetDramAddressFromPa(lastPageFillAddr), unusedSizeAfter, (byte)_ipcFillValue);
KernelResult result = MapPages(currentVa, 1, dstLastPagePa, permission);
Result result = MapPages(currentVa, 1, dstLastPagePa, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -1945,10 +1946,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
dst = va + (address - addressTruncated);
return KernelResult.Success;
return Result.Success;
}
public KernelResult UnmapNoAttributeIfStateEquals(ulong address, ulong size, MemoryState state)
public Result UnmapNoAttributeIfStateEquals(ulong address, ulong size, MemoryState state)
{
if (AddrSpaceStart > address)
{
@@ -1990,9 +1991,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong pagesCount = (endAddrRounded - addressTruncated) / PageSize;
KernelResult result = Unmap(addressTruncated, pagesCount);
Result result = Unmap(addressTruncated, pagesCount);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_blockManager.InsertBlock(addressTruncated, pagesCount, MemoryState.Unmapped);
}
@@ -2006,7 +2007,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnmapIpcRestorePermission(ulong address, ulong size, MemoryState state)
public Result UnmapIpcRestorePermission(ulong address, ulong size, MemoryState state)
{
ulong endAddr = address + size;
@@ -2019,7 +2020,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (pagesCount == 0)
{
return KernelResult.Success;
return Result.Success;
}
MemoryState stateMask;
@@ -2069,9 +2070,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong blockPagesCount = blockSize / PageSize;
KernelResult result = Reprotect(blockAddress, blockPagesCount, info.SourcePermission);
Result result = Reprotect(blockAddress, blockPagesCount, info.SourcePermission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -2080,7 +2081,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(addressRounded, pagesCount, RestoreIpcMappingPermissions);
return KernelResult.Success;
return Result.Success;
}
}
@@ -2094,7 +2095,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
block.RestoreIpcMappingPermission();
}
public KernelResult GetPagesIfStateEquals(
public Result GetPagesIfStateEquals(
ulong address,
ulong size,
MemoryState stateMask,
@@ -2128,7 +2129,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
GetPhysicalRegions(address, size, pageList);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -2137,7 +2138,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult BorrowIpcBuffer(ulong address, ulong size)
public Result BorrowIpcBuffer(ulong address, ulong size)
{
return SetAttributesAndChangePermission(
address,
@@ -2152,7 +2153,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryAttribute.Borrowed);
}
public KernelResult BorrowTransferMemory(KPageList pageList, ulong address, ulong size, KMemoryPermission permission)
public Result BorrowTransferMemory(KPageList pageList, ulong address, ulong size, KMemoryPermission permission)
{
return SetAttributesAndChangePermission(
address,
@@ -2168,7 +2169,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
pageList);
}
public KernelResult BorrowCodeMemory(KPageList pageList, ulong address, ulong size)
public Result BorrowCodeMemory(KPageList pageList, ulong address, ulong size)
{
return SetAttributesAndChangePermission(
address,
@@ -2184,7 +2185,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
pageList);
}
private KernelResult SetAttributesAndChangePermission(
private Result SetAttributesAndChangePermission(
ulong address,
ulong size,
MemoryState stateMask,
@@ -2237,9 +2238,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (newPermission != oldPermission)
{
KernelResult result = Reprotect(address, pagesCount, newPermission);
Result result = Reprotect(address, pagesCount, newPermission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -2249,7 +2250,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, oldState, newPermission, newAttribute);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -2258,7 +2259,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
public KernelResult UnborrowIpcBuffer(ulong address, ulong size)
public Result UnborrowIpcBuffer(ulong address, ulong size)
{
return ClearAttributesAndChangePermission(
address,
@@ -2273,7 +2274,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryAttribute.Borrowed);
}
public KernelResult UnborrowTransferMemory(ulong address, ulong size, KPageList pageList)
public Result UnborrowTransferMemory(ulong address, ulong size, KPageList pageList)
{
return ClearAttributesAndChangePermission(
address,
@@ -2289,7 +2290,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
pageList);
}
public KernelResult UnborrowCodeMemory(ulong address, ulong size, KPageList pageList)
public Result UnborrowCodeMemory(ulong address, ulong size, KPageList pageList)
{
return ClearAttributesAndChangePermission(
address,
@@ -2305,7 +2306,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
pageList);
}
private KernelResult ClearAttributesAndChangePermission(
private Result ClearAttributesAndChangePermission(
ulong address,
ulong size,
MemoryState stateMask,
@@ -2365,9 +2366,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (newPermission != oldPermission)
{
KernelResult result = Reprotect(address, pagesCount, newPermission);
Result result = Reprotect(address, pagesCount, newPermission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -2377,7 +2378,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockManager.InsertBlock(address, pagesCount, oldState, newPermission, newAttribute);
return KernelResult.Success;
return Result.Success;
}
else
{
@@ -2915,7 +2916,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="oldSrcPermission">Current protection of the source memory region</param>
/// <param name="newDstPermission">Desired protection for the destination memory region</param>
/// <returns>Result of the mapping operation</returns>
protected abstract KernelResult MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission);
protected abstract Result MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission);
/// <summary>
/// Unmaps a region of memory that was previously mapped with <see cref="MapMemory"/>.
@@ -2926,7 +2927,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="oldDstPermission">Current protection of the destination memory region</param>
/// <param name="newSrcPermission">Desired protection of the source memory region</param>
/// <returns>Result of the unmapping operation</returns>
protected abstract KernelResult UnmapMemory(ulong dst, ulong src, ulong pagesCount, KMemoryPermission oldDstPermission, KMemoryPermission newSrcPermission);
protected abstract Result UnmapMemory(ulong dst, ulong src, ulong pagesCount, KMemoryPermission oldDstPermission, KMemoryPermission newSrcPermission);
/// <summary>
/// Maps a region of memory into the specified physical memory region.
@@ -2938,7 +2939,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="shouldFillPages">Indicate if the pages should be filled with the <paramref name="fillValue"/> value</param>
/// <param name="fillValue">The value used to fill pages when <paramref name="shouldFillPages"/> is set to true</param>
/// <returns>Result of the mapping operation</returns>
protected abstract KernelResult MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0);
protected abstract Result MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0);
/// <summary>
/// Maps a region of memory into the specified physical memory region.
@@ -2949,7 +2950,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="shouldFillPages">Indicate if the pages should be filled with the <paramref name="fillValue"/> value</param>
/// <param name="fillValue">The value used to fill pages when <paramref name="shouldFillPages"/> is set to true</param>
/// <returns>Result of the mapping operation</returns>
protected abstract KernelResult MapPages(ulong address, KPageList pageList, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0);
protected abstract Result MapPages(ulong address, KPageList pageList, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0);
/// <summary>
/// Unmaps a region of memory that was previously mapped with one of the page mapping methods.
@@ -2957,7 +2958,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="address">Virtual address of the region to unmap</param>
/// <param name="pagesCount">Number of pages to unmap</param>
/// <returns>Result of the unmapping operation</returns>
protected abstract KernelResult Unmap(ulong address, ulong pagesCount);
protected abstract Result Unmap(ulong address, ulong pagesCount);
/// <summary>
/// Changes the permissions of a given virtual memory region.
@@ -2966,7 +2967,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="pagesCount">Number of pages to have their permissions changed</param>
/// <param name="permission">New permission</param>
/// <returns>Result of the permission change operation</returns>
protected abstract KernelResult Reprotect(ulong address, ulong pagesCount, KMemoryPermission permission);
protected abstract Result Reprotect(ulong address, ulong pagesCount, KMemoryPermission permission);
/// <summary>
/// Changes the permissions of a given virtual memory region.
@@ -2975,7 +2976,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
/// <param name="pagesCount">Number of pages to have their permissions changed</param>
/// <param name="permission">New permission</param>
/// <returns>Result of the permission change operation</returns>
protected abstract KernelResult ReprotectWithAttributes(ulong address, ulong pagesCount, KMemoryPermission permission);
protected abstract Result ReprotectWithAttributes(ulong address, ulong pagesCount, KMemoryPermission permission);
/// <summary>
/// Alerts the memory tracking that a given region has been read from or written to.

View File

@@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Kernel.Memory
{
@@ -26,7 +27,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_userPermission = userPermission;
}
public KernelResult MapIntoProcess(
public Result MapIntoProcess(
KPageTableBase memoryManager,
ulong address,
ulong size,
@@ -50,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return memoryManager.MapPages(address, _pageList, MemoryState.SharedMemory, permission);
}
public KernelResult UnmapFromProcess(KPageTableBase memoryManager, ulong address, ulong size, KProcess process)
public Result UnmapFromProcess(KPageTableBase memoryManager, ulong address, ulong size, KProcess process)
{
if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{

View File

@@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Memory
@@ -36,15 +37,15 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_isMapped = false;
}
public KernelResult Initialize(ulong address, ulong size, KMemoryPermission permission)
public Result Initialize(ulong address, ulong size, KMemoryPermission permission)
{
KProcess creator = KernelStatic.GetCurrentProcess();
_creator = creator;
KernelResult result = creator.MemoryManager.BorrowTransferMemory(_pageList, address, size, permission);
Result result = creator.MemoryManager.BorrowTransferMemory(_pageList, address, size, permission);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -60,7 +61,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return result;
}
public KernelResult MapIntoProcess(
public Result MapIntoProcess(
KPageTableBase memoryManager,
ulong address,
ulong size,
@@ -79,9 +80,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryState state = Permission == KMemoryPermission.None ? MemoryState.TransferMemoryIsolated : MemoryState.TransferMemory;
KernelResult result = memoryManager.MapPages(address, _pageList, state, KMemoryPermission.ReadAndWrite);
Result result = memoryManager.MapPages(address, _pageList, state, KMemoryPermission.ReadAndWrite);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_isMapped = true;
}
@@ -89,7 +90,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return result;
}
public KernelResult UnmapFromProcess(
public Result UnmapFromProcess(
KPageTableBase memoryManager,
ulong address,
ulong size,
@@ -102,9 +103,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryState state = Permission == KMemoryPermission.None ? MemoryState.TransferMemoryIsolated : MemoryState.TransferMemory;
KernelResult result = memoryManager.UnmapPages(address, _pageList, state);
Result result = memoryManager.UnmapPages(address, _pageList, state);
if (result == KernelResult.Success)
if (result == Result.Success)
{
_isMapped = false;
}
@@ -116,7 +117,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
if (_hasBeenInitialized)
{
if (!_isMapped && _creator.MemoryManager.UnborrowTransferMemory(Address, Size, _pageList) != KernelResult.Success)
if (!_isMapped && _creator.MemoryManager.UnborrowTransferMemory(Address, Size, _pageList) != Result.Success)
{
throw new InvalidOperationException("Unexpected failure restoring transfer memory attributes.");
}

View File

@@ -1,5 +1,6 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Process
@@ -27,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
_context = context;
}
public KernelResult Initialize(int size)
public Result Initialize(int size)
{
if ((uint)size > 1024)
{
@@ -62,10 +63,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
_nextFreeEntry = _tableHead;
return KernelResult.Success;
return Result.Success;
}
public KernelResult GenerateHandle(KAutoObject obj, out int handle)
public Result GenerateHandle(KAutoObject obj, out int handle)
{
handle = 0;
@@ -99,10 +100,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult ReserveHandle(out int handle)
public Result ReserveHandle(out int handle)
{
handle = 0;
@@ -131,7 +132,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
return KernelResult.Success;
return Result.Success;
}
public void CancelHandleReservation(int handle)

View File

@@ -5,6 +5,7 @@ using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Collections.Generic;
@@ -116,7 +117,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Debugger = new HleProcessDebugger(this);
}
public KernelResult InitializeKip(
public Result InitializeKip(
ProcessCreationInfo creationInfo,
ReadOnlySpan<int> capabilities,
KPageList pageList,
@@ -151,7 +152,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
? KernelContext.LargeMemoryBlockSlabManager
: KernelContext.SmallMemoryBlockSlabManager;
KernelResult result = MemoryManager.InitializeForProcess(
Result result = MemoryManager.InitializeForProcess(
addrSpaceType,
aslrEnabled,
!aslrEnabled,
@@ -160,7 +161,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
codeSize,
slabManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -172,14 +173,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = MemoryManager.MapPages(codeAddress, pageList, MemoryState.CodeStatic, KMemoryPermission.None);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = Capabilities.InitializeForKernel(capabilities, MemoryManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -187,7 +188,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return ParseProcessInfo(creationInfo);
}
public KernelResult Initialize(
public Result Initialize(
ProcessCreationInfo creationInfo,
ReadOnlySpan<int> capabilities,
KResourceLimit resourceLimit,
@@ -255,7 +256,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
ulong codeSize = codePagesCount * KPageTableBase.PageSize;
KernelResult result = MemoryManager.InitializeForProcess(
Result result = MemoryManager.InitializeForProcess(
addrSpaceType,
aslrEnabled,
!aslrEnabled,
@@ -264,7 +265,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
codeSize,
slabManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -284,7 +285,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
MemoryState.CodeStatic,
KMemoryPermission.None);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -293,7 +294,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = Capabilities.InitializeForUser(capabilities, MemoryManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -302,7 +303,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = ParseProcessInfo(creationInfo);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
}
@@ -310,7 +311,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return result;
}
private KernelResult ParseProcessInfo(ProcessCreationInfo creationInfo)
private Result ParseProcessInfo(ProcessCreationInfo creationInfo)
{
// Ensure that the current kernel version is equal or above to the minimum required.
uint requiredKernelVersionMajor = (uint)Capabilities.KernelReleaseVersion >> 19;
@@ -334,9 +335,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
KernelResult result = AllocateThreadLocalStorage(out ulong userExceptionContextAddress);
Result result = AllocateThreadLocalStorage(out ulong userExceptionContextAddress);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -378,14 +379,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
GenerateRandomEntropy();
return KernelResult.Success;
return Result.Success;
}
public KernelResult AllocateThreadLocalStorage(out ulong address)
public Result AllocateThreadLocalStorage(out ulong address)
{
KernelContext.CriticalSection.Enter();
KernelResult result;
Result result;
if (_freeTlsPages.Count > 0)
{
@@ -404,14 +405,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
_fullTlsPages.Add(pageInfo.PageVirtualAddress, pageInfo);
}
result = KernelResult.Success;
result = Result.Success;
}
else
{
// Otherwise, we need to create a new one.
result = AllocateTlsPage(out KTlsPageInfo pageInfo);
if (result == KernelResult.Success)
if (result == Result.Success)
{
if (!pageInfo.TryGetFreePage(out address))
{
@@ -431,7 +432,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return result;
}
private KernelResult AllocateTlsPage(out KTlsPageInfo pageInfo)
private Result AllocateTlsPage(out KTlsPageInfo pageInfo)
{
pageInfo = default;
@@ -445,7 +446,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
ulong regionPagesCount = regionSize / KPageTableBase.PageSize;
KernelResult result = MemoryManager.MapPages(
Result result = MemoryManager.MapPages(
1,
KPageTableBase.PageSize,
tlsPagePa,
@@ -456,7 +457,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
KMemoryPermission.ReadAndWrite,
out ulong tlsPageVa);
if (result != KernelResult.Success)
if (result != Result.Success)
{
KernelContext.UserSlabHeapPages.Free(tlsPagePa);
}
@@ -470,13 +471,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return result;
}
public KernelResult FreeThreadLocalStorage(ulong tlsSlotAddr)
public Result FreeThreadLocalStorage(ulong tlsSlotAddr)
{
ulong tlsPageAddr = BitUtils.AlignDown<ulong>(tlsSlotAddr, KPageTableBase.PageSize);
KernelContext.CriticalSection.Enter();
KernelResult result = KernelResult.Success;
Result result = Result.Success;
KTlsPageInfo pageInfo;
@@ -506,7 +507,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
FreeTlsPage(pageInfo);
return KernelResult.Success;
return Result.Success;
}
}
@@ -515,11 +516,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return result;
}
private KernelResult FreeTlsPage(KTlsPageInfo pageInfo)
private Result FreeTlsPage(KTlsPageInfo pageInfo)
{
KernelResult result = MemoryManager.UnmapForKernel(pageInfo.PageVirtualAddress, 1, MemoryState.ThreadLocal);
Result result = MemoryManager.UnmapForKernel(pageInfo.PageVirtualAddress, 1, MemoryState.ThreadLocal);
if (result == KernelResult.Success)
if (result == Result.Success)
{
KernelContext.UserSlabHeapPages.Free(pageInfo.PagePhysicalAddress);
}
@@ -532,7 +533,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
// TODO.
}
public KernelResult Start(int mainThreadPriority, ulong stackSize)
public Result Start(int mainThreadPriority, ulong stackSize)
{
lock (_processLock)
{
@@ -580,7 +581,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
KernelResult result;
Result result;
KThread mainThread = null;
@@ -627,7 +628,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
KMemoryPermission.ReadAndWrite,
out ulong stackBottom);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -643,7 +644,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = MemoryManager.SetHeapCapacity(heapCapacity);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -654,7 +655,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = HandleTable.Initialize(Capabilities.HandleTableSize);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -673,7 +674,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
ThreadType.User,
_customThreadStart);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -682,7 +683,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = HandleTable.GenerateHandle(mainThread, out int mainThreadHandle);
if (result != KernelResult.Success)
if (result != Result.Success)
{
CleanUpForError();
@@ -700,14 +701,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = mainThread.Start();
if (result != KernelResult.Success)
if (result != Result.Success)
{
SetState(oldState);
CleanUpForError();
}
if (result == KernelResult.Success)
if (result == Result.Success)
{
mainThread.IncrementReferenceCount();
}
@@ -729,7 +730,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
public KernelResult InitializeThread(
public Result InitializeThread(
KThread thread,
ulong entrypoint,
ulong argsPtr,
@@ -888,9 +889,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return _signaled;
}
public KernelResult Terminate()
public Result Terminate()
{
KernelResult result;
Result result;
bool shallTerminate = false;
@@ -910,7 +911,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
shallTerminate = true;
}
result = KernelResult.Success;
result = Result.Success;
}
else
{
@@ -1044,9 +1045,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
KernelContext.CriticalSection.Leave();
}
public KernelResult ClearIfNotExited()
public Result ClearIfNotExited()
{
KernelResult result;
Result result;
KernelContext.CriticalSection.Enter();
@@ -1056,7 +1057,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{
_signaled = false;
result = KernelResult.Success;
result = Result.Success;
}
else
{
@@ -1107,7 +1108,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
protected override void Destroy() => Context.Dispose();
public KernelResult SetActivity(bool pause)
public Result SetActivity(bool pause)
{
KernelContext.CriticalSection.Enter();
@@ -1154,7 +1155,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
KernelContext.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
KernelContext.CriticalSection.Leave();

View File

@@ -1,6 +1,7 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
using System.Numerics;
@@ -25,7 +26,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
IrqAccessMask = new byte[0x80];
}
public KernelResult InitializeForKernel(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
public Result InitializeForKernel(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
{
AllowedCpuCoresMask = 0xf;
AllowedThreadPriosMask = ulong.MaxValue;
@@ -35,12 +36,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return Parse(capabilities, memoryManager);
}
public KernelResult InitializeForUser(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
public Result InitializeForUser(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
{
return Parse(capabilities, memoryManager);
}
private KernelResult Parse(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
private Result Parse(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
{
int mask0 = 0;
int mask1 = 0;
@@ -51,9 +52,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (((cap + 1) & ~cap) != 0x40)
{
KernelResult result = ParseCapability(cap, ref mask0, ref mask1, memoryManager);
Result result = ParseCapability(cap, ref mask0, ref mask1, memoryManager);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -96,7 +97,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
? KMemoryPermission.Read
: KMemoryPermission.ReadAndWrite;
KernelResult result;
Result result;
if ((cap >> 31) != 0)
{
@@ -107,17 +108,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
result = memoryManager.MapIoMemory(address, size, perm);
}
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
}
}
return KernelResult.Success;
return Result.Success;
}
private KernelResult ParseCapability(int cap, ref int mask0, ref int mask1, KPageTableBase memoryManager)
private Result ParseCapability(int cap, ref int mask0, ref int mask1, KPageTableBase memoryManager)
{
int code = (cap + 1) & ~cap;
@@ -127,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
else if (code == 0)
{
return KernelResult.Success;
return Result.Success;
}
int codeMask = 1 << (32 - BitOperations.LeadingZeroCount((uint)code + 1));
@@ -300,7 +301,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
default: return KernelResult.InvalidCapability;
}
return KernelResult.Success;
return Result.Success;
}
private static ulong GetMaskFromMinMax(int min, int max)

View File

@@ -7,23 +7,25 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{
public ulong Pc => 0UL;
public ulong CntfrqEl0 { get => 0; set { } }
public ulong CntfrqEl0 { get; set; }
public ulong CntpctEl0 => 0UL;
public long TpidrEl0 { get => 0; set { } }
public long TpidrroEl0 { get => 0; set { } }
public long TpidrEl0 { get; set; }
public long TpidrroEl0 { get; set; }
public uint Pstate { get => 0; set { } }
public uint Pstate { get; set; }
public uint Fpcr { get => 0; set { } }
public uint Fpsr { get => 0; set { } }
public uint Fpcr { get; set; }
public uint Fpsr { get; set; }
public bool IsAarch32 { get => false; set { } }
public bool Running { get; private set; } = true;
public ulong GetX(int index) => 0UL;
public void SetX(int index, ulong value) { }
private readonly ulong[] _x = new ulong[32];
public ulong GetX(int index) => _x[index];
public void SetX(int index, ulong value) => _x[index] = value;
public V128 GetV(int index) => default;
public void SetV(int index, V128 value) { }

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -24,14 +25,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_arbiterThreads = new List<KThread>();
}
public KernelResult ArbitrateLock(int ownerHandle, ulong mutexAddress, int requesterHandle)
public Result ArbitrateLock(int ownerHandle, ulong mutexAddress, int requesterHandle)
{
KThread currentThread = KernelStatic.GetCurrentThread();
_context.CriticalSection.Enter();
currentThread.SignaledObj = null;
currentThread.ObjSyncResult = KernelResult.Success;
currentThread.ObjSyncResult = Result.Success;
KProcess currentProcess = KernelStatic.GetCurrentProcess();
@@ -46,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
_context.CriticalSection.Leave();
return 0;
return Result.Success;
}
KThread mutexOwner = currentProcess.HandleTable.GetObject<KThread>(ownerHandle);
@@ -78,7 +79,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return currentThread.ObjSyncResult;
}
public KernelResult ArbitrateUnlock(ulong mutexAddress)
public Result ArbitrateUnlock(ulong mutexAddress)
{
_context.CriticalSection.Enter();
@@ -86,14 +87,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
(int mutexValue, KThread newOwnerThread) = MutexUnlock(currentThread, mutexAddress);
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (!KernelTransfer.KernelToUser(mutexAddress, mutexValue))
{
result = KernelResult.InvalidMemState;
}
if (result != KernelResult.Success && newOwnerThread != null)
if (result != Result.Success && newOwnerThread != null)
{
newOwnerThread.SignaledObj = null;
newOwnerThread.ObjSyncResult = result;
@@ -104,7 +105,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return result;
}
public KernelResult WaitProcessWideKeyAtomic(ulong mutexAddress, ulong condVarAddress, int threadHandle, long timeout)
public Result WaitProcessWideKeyAtomic(ulong mutexAddress, ulong condVarAddress, int threadHandle, long timeout)
{
_context.CriticalSection.Enter();
@@ -185,7 +186,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
newOwnerThread.SignaledObj = null;
newOwnerThread.ObjSyncResult = KernelResult.Success;
newOwnerThread.ObjSyncResult = Result.Success;
newOwnerThread.ReleaseAndResume();
}
@@ -247,7 +248,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
// We now own the mutex.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.Success;
requester.ObjSyncResult = Result.Success;
requester.ReleaseAndResume();
@@ -273,7 +274,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
public KernelResult WaitForAddressIfEqual(ulong address, int value, long timeout)
public Result WaitForAddressIfEqual(ulong address, int value, long timeout)
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -344,7 +345,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return KernelResult.InvalidState;
}
public KernelResult WaitForAddressIfLessThan(ulong address, int value, bool shouldDecrement, long timeout)
public Result WaitForAddressIfLessThan(ulong address, int value, bool shouldDecrement, long timeout)
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -422,7 +423,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return KernelResult.InvalidState;
}
public KernelResult Signal(ulong address, int count)
public Result Signal(ulong address, int count)
{
_context.CriticalSection.Enter();
@@ -430,10 +431,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_context.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
public KernelResult SignalAndIncrementIfEqual(ulong address, int value, int count)
public Result SignalAndIncrementIfEqual(ulong address, int value, int count)
{
_context.CriticalSection.Enter();
@@ -467,10 +468,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_context.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
public KernelResult SignalAndModifyIfEqual(ulong address, int value, int count)
public Result SignalAndModifyIfEqual(ulong address, int value, int count)
{
_context.CriticalSection.Enter();
@@ -539,7 +540,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_context.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
private void WakeArbiterThreads(ulong address, int count)
@@ -547,7 +548,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
static void RemoveArbiterThread(KThread thread)
{
thread.SignaledObj = null;
thread.ObjSyncResult = KernelResult.Success;
thread.ObjSyncResult = Result.Success;
thread.ReleaseAndResume();

View File

@@ -1,4 +1,5 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Kernel.Threading
{
@@ -27,16 +28,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
}
public KernelResult Clear()
public Result Clear()
{
_signaled = false;
return KernelResult.Success;
return Result.Success;
}
public KernelResult ClearIfSignaled()
public Result ClearIfSignaled()
{
KernelResult result;
Result result;
KernelContext.CriticalSection.Enter();
@@ -44,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
_signaled = false;
result = KernelResult.Success;
result = Result.Success;
}
else
{

View File

@@ -1,4 +1,5 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
@@ -13,11 +14,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_context = context;
}
public KernelResult WaitFor(Span<KSynchronizationObject> syncObjs, long timeout, out int handleIndex)
public Result WaitFor(Span<KSynchronizationObject> syncObjs, long timeout, out int handleIndex)
{
handleIndex = 0;
KernelResult result = KernelResult.TimedOut;
Result result = KernelResult.TimedOut;
_context.CriticalSection.Enter();
@@ -33,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_context.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
if (timeout == 0)
@@ -122,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if ((thread.SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused)
{
thread.SignaledObj = syncObj;
thread.ObjSyncResult = KernelResult.Success;
thread.ObjSyncResult = Result.Success;
thread.Reschedule(ThreadSchedState.Running);
}

View File

@@ -3,6 +3,7 @@ using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.SupervisorCall;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
using System.Numerics;
@@ -79,7 +80,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
private ThreadSchedState _forcePauseFlags;
private ThreadSchedState _forcePausePermissionFlags;
public KernelResult ObjSyncResult { get; set; }
public Result ObjSyncResult { get; set; }
public int BasePriority { get; set; }
public int PreferredCore { get; set; }
@@ -130,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_activityOperationLock = new object();
}
public KernelResult Initialize(
public Result Initialize(
ulong entrypoint,
ulong argsPtr,
ulong stackTop,
@@ -145,8 +146,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
throw new ArgumentException($"Invalid thread type \"{type}\".");
}
ThreadContext = new KThreadContext();
PreferredCore = cpuCore;
AffinityMask |= 1UL << cpuCore;
@@ -166,7 +165,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (type == ThreadType.User)
{
if (owner.AllocateThreadLocalStorage(out _tlsAddress) != KernelResult.Success)
if (owner.AllocateThreadLocalStorage(out _tlsAddress) != Result.Success)
{
return KernelResult.OutOfMemory;
}
@@ -194,6 +193,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
Context = owner?.CreateExecutionContext() ?? new ProcessExecutionContext();
ThreadContext = new KThreadContext(Context);
Context.IsAarch32 = !is64Bits;
Context.SetX(0, argsPtr);
@@ -230,7 +231,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
KernelContext.CriticalSection.Leave();
return KernelResult.Success;
return Result.Success;
}
_forcePauseFlags |= ThreadSchedState.ProcessPauseFlag;
@@ -241,10 +242,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
return KernelResult.Success;
return Result.Success;
}
public KernelResult Start()
public Result Start()
{
if (!KernelContext.KernelInitialized)
{
@@ -260,7 +261,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
}
KernelResult result = KernelResult.ThreadTerminating;
Result result = KernelResult.ThreadTerminating;
KernelContext.CriticalSection.Enter();
@@ -287,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
StartHostThread();
result = KernelResult.Success;
result = Result.Success;
break;
}
else
@@ -465,7 +466,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return -1;
}
public KernelResult Sleep(long timeout)
public Result Sleep(long timeout)
{
KernelContext.CriticalSection.Enter();
@@ -490,7 +491,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.TimeManager.UnscheduleFutureInvocation(this);
}
return 0;
return Result.Success;
}
public void SetPriority(int priority)
@@ -534,11 +535,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
public KernelResult SetActivity(bool pause)
public Result SetActivity(bool pause)
{
lock (_activityOperationLock)
{
KernelResult result = KernelResult.Success;
Result result = Result.Success;
KernelContext.CriticalSection.Enter();
@@ -581,7 +582,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
if (result == KernelResult.Success && pause)
if (result == Result.Success && pause)
{
bool isThreadRunning = true;
@@ -628,7 +629,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
public KernelResult GetThreadContext3(out ThreadContext context)
public Result GetThreadContext3(out ThreadContext context)
{
context = default;
@@ -651,7 +652,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
}
return KernelResult.Success;
return Result.Success;
}
private static uint GetPsr(IExecutionContext context)
@@ -739,7 +740,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
}
public KernelResult SetCoreAndAffinityMask(int newCore, ulong newAffinityMask)
public Result SetCoreAndAffinityMask(int newCore, ulong newAffinityMask)
{
lock (_activityOperationLock)
{
@@ -838,7 +839,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave();
}
return KernelResult.Success;
return Result.Success;
}
}
@@ -1259,6 +1260,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (_customThreadStart != null)
{
_customThreadStart();
// Ensure that anything trying to join the HLE thread is unblocked.
Exit();
HandlePostSyscall();
}
else
{
@@ -1304,7 +1309,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
Owner?.RemoveThread(this);
if (_tlsAddress != 0 && Owner.FreeThreadLocalStorage(_tlsAddress) != KernelResult.Success)
if (_tlsAddress != 0 && Owner.FreeThreadLocalStorage(_tlsAddress) != Result.Success)
{
throw new InvalidOperationException("Unexpected failure freeing thread local storage.");
}

View File

@@ -1,11 +1,25 @@
using System.Threading;
using Ryujinx.Cpu;
using Ryujinx.Horizon.Common;
using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel.Threading
{
class KThreadContext
class KThreadContext : IThreadContext
{
private readonly IExecutionContext _context;
public bool Running => _context.Running;
public ulong TlsAddress => (ulong)_context.TpidrroEl0;
public ulong GetX(int index) => _context.GetX(index);
private int _locked;
public KThreadContext(IExecutionContext context)
{
_context = context;
}
public bool Lock()
{
return Interlocked.Exchange(ref _locked, 1) == 0;

View File

@@ -1,4 +1,5 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Kernel.Threading
{
@@ -16,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_parent.ReadableEvent.Signal();
}
public KernelResult Clear()
public Result Clear()
{
return _parent.ReadableEvent.Clear();
}

View File

@@ -1,14 +1,15 @@
using ARMeilleure.Translation.PTC;
using LibHac.Loader;
using LibHac.Ncm;
using LibHac.Util;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.Horizon.Common;
using System;
using System.Linq;
using System.Runtime.InteropServices;
@@ -20,16 +21,40 @@ namespace Ryujinx.HLE.HOS
{
public string Name;
public ulong ProgramId;
public bool AllowCodeMemoryForJit;
public readonly string TitleIdText;
public readonly string DisplayVersion;
public readonly bool DiskCacheEnabled;
public readonly bool AllowCodeMemoryForJit;
public ProgramInfo(in Npdm npdm, bool allowCodeMemoryForJit)
public ProgramInfo(in Npdm npdm, string displayVersion, bool diskCacheEnabled, bool allowCodeMemoryForJit)
{
ulong programId = npdm.Aci.Value.ProgramId.Value;
Name = StringUtils.Utf8ZToString(npdm.Meta.Value.ProgramName);
ProgramId = npdm.Aci.Value.ProgramId.Value;
ProgramId = programId;
TitleIdText = programId.ToString("x16");
DisplayVersion = displayVersion;
DiskCacheEnabled = diskCacheEnabled;
AllowCodeMemoryForJit = allowCodeMemoryForJit;
}
}
struct ProgramLoadResult
{
public static ProgramLoadResult Failed => new ProgramLoadResult(false, null, null);
public readonly bool Success;
public readonly ProcessTamperInfo TamperInfo;
public readonly IDiskCacheLoadState DiskCacheLoadState;
public ProgramLoadResult(bool success, ProcessTamperInfo tamperInfo, IDiskCacheLoadState diskCacheLoadState)
{
Success = success;
TamperInfo = tamperInfo;
DiskCacheLoadState = diskCacheLoadState;
}
}
static class ProgramLoader
{
private const bool AslrEnabled = true;
@@ -90,9 +115,9 @@ namespace Ryujinx.HLE.HOS
KMemoryRegionManager region = context.MemoryManager.MemoryRegions[(int)memoryRegion];
KernelResult result = region.AllocatePages(out KPageList pageList, (ulong)codePagesCount);
Result result = region.AllocatePages(out KPageList pageList, (ulong)codePagesCount);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
@@ -101,7 +126,14 @@ namespace Ryujinx.HLE.HOS
KProcess process = new KProcess(context);
var processContextFactory = new ArmProcessContextFactory(context.Device.System.CpuEngine, context.Device.Gpu);
var processContextFactory = new ArmProcessContextFactory(
context.Device.System.CpuEngine,
context.Device.Gpu,
string.Empty,
string.Empty,
false,
codeAddress,
codeSize);
result = process.InitializeKip(
creationInfo,
@@ -111,7 +143,7 @@ namespace Ryujinx.HLE.HOS
memoryRegion,
processContextFactory);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
@@ -120,7 +152,7 @@ namespace Ryujinx.HLE.HOS
result = LoadIntoMemory(process, kip, codeBaseAddress);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
@@ -131,7 +163,7 @@ namespace Ryujinx.HLE.HOS
result = process.Start(kip.Priority, (ulong)kip.StackSize);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process start returned error \"{result}\".");
@@ -143,9 +175,8 @@ namespace Ryujinx.HLE.HOS
return true;
}
public static bool LoadNsos(
public static ProgramLoadResult LoadNsos(
KernelContext context,
out ProcessTamperInfo tamperInfo,
MetaLoader metaData,
ProgramInfo programInfo,
byte[] arguments = null,
@@ -155,8 +186,7 @@ namespace Ryujinx.HLE.HOS
if (rc.IsFailure())
{
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
ref readonly var meta = ref npdm.Meta.Value;
@@ -211,9 +241,6 @@ namespace Ryujinx.HLE.HOS
}
}
PtcProfiler.StaticCodeStart = codeStart;
PtcProfiler.StaticCodeSize = (ulong)codeSize;
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
int personalMmHeapPagesCount = (int)(meta.SystemResourceSize / KPageTableBase.PageSize);
@@ -230,25 +257,39 @@ namespace Ryujinx.HLE.HOS
context.Device.System.LibHacHorizonManager.InitializeApplicationClient(new ProgramId(programInfo.ProgramId), in npdm);
KernelResult result;
Result result;
KResourceLimit resourceLimit = new KResourceLimit(context);
long applicationRgSize = (long)context.MemoryManager.MemoryRegions[(int)MemoryRegion.Application].Size;
result = resourceLimit.SetLimitValue(LimitableResource.Memory, applicationRgSize);
result |= resourceLimit.SetLimitValue(LimitableResource.Thread, 608);
result |= resourceLimit.SetLimitValue(LimitableResource.Event, 700);
result |= resourceLimit.SetLimitValue(LimitableResource.TransferMemory, 128);
result |= resourceLimit.SetLimitValue(LimitableResource.Session, 894);
if (result != KernelResult.Success)
if (result.IsSuccess)
{
result = resourceLimit.SetLimitValue(LimitableResource.Thread, 608);
}
if (result.IsSuccess)
{
result = resourceLimit.SetLimitValue(LimitableResource.Event, 700);
}
if (result.IsSuccess)
{
result = resourceLimit.SetLimitValue(LimitableResource.TransferMemory, 128);
}
if (result.IsSuccess)
{
result = resourceLimit.SetLimitValue(LimitableResource.Session, 894);
}
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed setting resource limit values.");
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
KProcess process = new KProcess(context, programInfo.AllowCodeMemoryForJit);
@@ -259,12 +300,17 @@ namespace Ryujinx.HLE.HOS
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed due to invalid ACID flags.");
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
var processContextFactory = new ArmProcessContextFactory(context.Device.System.CpuEngine, context.Device.Gpu);
var processContextFactory = new ArmProcessContextFactory(
context.Device.System.CpuEngine,
context.Device.Gpu,
programInfo.TitleIdText,
programInfo.DisplayVersion,
programInfo.DiskCacheEnabled,
codeStart,
codeSize);
result = process.Initialize(
creationInfo,
@@ -273,13 +319,11 @@ namespace Ryujinx.HLE.HOS
memoryRegion,
processContextFactory);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
for (int index = 0; index < executables.Length; index++)
@@ -288,13 +332,11 @@ namespace Ryujinx.HLE.HOS
result = LoadIntoMemory(process, executables[index], nsoBase[index]);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization returned error \"{result}\".");
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
}
@@ -302,13 +344,11 @@ namespace Ryujinx.HLE.HOS
result = process.Start(meta.MainThreadPriority, meta.MainThreadStackSize);
if (result != KernelResult.Success)
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process start returned error \"{result}\".");
tamperInfo = null;
return false;
return ProgramLoadResult.Failed;
}
context.Processes.TryAdd(process.Pid, process);
@@ -316,24 +356,29 @@ namespace Ryujinx.HLE.HOS
// Keep the build ids because the tamper machine uses them to know which process to associate a
// tamper to and also keep the starting address of each executable inside a process because some
// memory modifications are relative to this address.
tamperInfo = new ProcessTamperInfo(process, buildIds, nsoBase, process.MemoryManager.HeapRegionStart,
process.MemoryManager.AliasRegionStart, process.MemoryManager.CodeRegionStart);
ProcessTamperInfo tamperInfo = new ProcessTamperInfo(
process,
buildIds,
nsoBase,
process.MemoryManager.HeapRegionStart,
process.MemoryManager.AliasRegionStart,
process.MemoryManager.CodeRegionStart);
return true;
return new ProgramLoadResult(true, tamperInfo, processContextFactory.DiskCacheLoadState);
}
private static KernelResult LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress)
private static Result LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress)
{
ulong textStart = baseAddress + (ulong)image.TextOffset;
ulong roStart = baseAddress + (ulong)image.RoOffset;
ulong dataStart = baseAddress + (ulong)image.DataOffset;
ulong bssStart = baseAddress + (ulong)image.BssOffset;
ulong textStart = baseAddress + image.TextOffset;
ulong roStart = baseAddress + image.RoOffset;
ulong dataStart = baseAddress + image.DataOffset;
ulong bssStart = baseAddress + image.BssOffset;
ulong end = dataStart + (ulong)image.Data.Length;
if (image.BssSize != 0)
{
end = bssStart + (ulong)image.BssSize;
end = bssStart + image.BssSize;
}
process.CpuMemory.Write(textStart, image.Text);
@@ -342,11 +387,11 @@ namespace Ryujinx.HLE.HOS
process.CpuMemory.Fill(bssStart, image.BssSize, 0);
KernelResult SetProcessMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
Result SetProcessMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
{
if (size == 0)
{
return KernelResult.Success;
return Result.Success;
}
size = BitUtils.AlignUp<ulong>(size, KPageTableBase.PageSize);
@@ -354,16 +399,16 @@ namespace Ryujinx.HLE.HOS
return process.MemoryManager.SetProcessMemoryPermission(address, size, permission);
}
KernelResult result = SetProcessMemoryPermission(textStart, (ulong)image.Text.Length, KMemoryPermission.ReadAndExecute);
Result result = SetProcessMemoryPermission(textStart, (ulong)image.Text.Length, KMemoryPermission.ReadAndExecute);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = SetProcessMemoryPermission(roStart, (ulong)image.Ro.Length, KMemoryPermission.Read);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}

View File

@@ -1,6 +1,6 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Account.Acc
@@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
// GetSystemEvent() -> handle<copy>
public ResultCode GetSystemEvent(ServiceCtx context)
{
if (context.Process.HandleTable.GenerateHandle(AsyncExecution.SystemEvent.ReadableEvent, out int _systemEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(AsyncExecution.SystemEvent.ReadableEvent, out int _systemEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -2,8 +2,8 @@
using Ryujinx.HLE.HOS.Applets;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.LibraryAppletCreator
@@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib
{
if (_stateChangedEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_stateChangedEvent.ReadableEvent, out _stateChangedEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_stateChangedEvent.ReadableEvent, out _stateChangedEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -178,7 +178,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib
{
if (_normalOutDataEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_normalOutDataEvent.ReadableEvent, out _normalOutDataEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_normalOutDataEvent.ReadableEvent, out _normalOutDataEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -195,7 +195,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Lib
{
if (_interactiveOutDataEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_interactiveOutDataEvent.ReadableEvent, out _interactiveOutDataEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_interactiveOutDataEvent.ReadableEvent, out _interactiveOutDataEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,10 +1,10 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Settings.Types;
using Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
@@ -38,7 +38,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
if (_messageEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(messageEvent.ReadableEvent, out _messageEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(messageEvent.ReadableEvent, out _messageEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -211,7 +211,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
// NOTE: Original service calls IOperationModeManager::GetDefaultDisplayResolutionChangeEvent of omm service.
if (_displayResolutionChangedEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(context.Device.System.DisplayResolutionChangeEvent.ReadableEvent, out _displayResolutionChangedEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.DisplayResolutionChangeEvent.ReadableEvent, out _displayResolutionChangedEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
@@ -66,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
return ResultCode.BufferAlreadyAcquired;
}
if (context.Process.HandleTable.GenerateHandle(_transferMem, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_transferMem, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -89,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
return ResultCode.BufferAlreadyAcquired;
}
if (context.Process.HandleTable.GenerateHandle(_transferMem, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_transferMem, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
@@ -32,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
{
if (_channelEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_channelEvent.ReadableEvent, out _channelEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_channelEvent.ReadableEvent, out _channelEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy.Types;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
@@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
if (_libraryAppletLaunchableEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_libraryAppletLaunchableEvent.ReadableEvent, out _libraryAppletLaunchableEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_libraryAppletLaunchableEvent.ReadableEvent, out _libraryAppletLaunchableEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -378,7 +378,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
_accumulatedSuspendedTickChangedEvent.ReadableEvent.Signal();
if (context.Process.HandleTable.GenerateHandle(_accumulatedSuspendedTickChangedEvent.ReadableEvent, out _accumulatedSuspendedTickChangedEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_accumulatedSuspendedTickChangedEvent.ReadableEvent, out _accumulatedSuspendedTickChangedEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,4 +1,3 @@
using LibHac;
using LibHac.Account;
using LibHac.Common;
using LibHac.Fs;
@@ -9,13 +8,13 @@ using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Am.AppletAE.Storage;
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
using Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.Horizon.Common;
using System;
using System.Numerics;
using System.Threading;
@@ -43,7 +42,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
private int _jitLoaded;
private HorizonClient _horizon;
private LibHac.HorizonClient _horizon;
public IApplicationFunctions(Horizon system)
{
@@ -136,8 +135,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
"No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
}
HorizonClient hos = context.Device.System.LibHacHorizonManager.AmClient;
Result result = hos.Fs.EnsureApplicationSaveData(out long requiredSize, applicationId, in control, in userId);
LibHac.HorizonClient hos = context.Device.System.LibHacHorizonManager.AmClient;
LibHac.Result result = hos.Fs.EnsureApplicationSaveData(out long requiredSize, applicationId, in control, in userId);
context.ResponseData.Write(requiredSize);
@@ -185,7 +184,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
// SetTerminateResult(u32)
public ResultCode SetTerminateResult(ServiceCtx context)
{
Result result = new Result(context.RequestData.ReadUInt32());
LibHac.Result result = new LibHac.Result(context.RequestData.ReadUInt32());
Logger.Info?.Print(LogClass.ServiceAm, $"Result = 0x{result.Value:x8} ({result.ToStringWithName()}).");
@@ -256,7 +255,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
BlitStruct<ApplicationControlProperty> controlHolder = context.Device.Application.ControlData;
Result result = _horizon.Fs.CreateApplicationCacheStorage(out long requiredSize,
LibHac.Result result = _horizon.Fs.CreateApplicationCacheStorage(out long requiredSize,
out CacheStorageTargetMedia storageTarget, applicationId, in controlHolder.Value, index, saveSize,
journalSize);
@@ -584,7 +583,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
{
if (_gpuErrorDetectedSystemEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_gpuErrorDetectedSystemEvent.ReadableEvent, out _gpuErrorDetectedSystemEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_gpuErrorDetectedSystemEvent.ReadableEvent, out _gpuErrorDetectedSystemEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -605,7 +604,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
{
if (_friendInvitationStorageChannelEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_friendInvitationStorageChannelEvent.ReadableEvent, out _friendInvitationStorageChannelEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_friendInvitationStorageChannelEvent.ReadableEvent, out _friendInvitationStorageChannelEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -636,7 +635,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
{
if (_notificationStorageChannelEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_notificationStorageChannelEvent.ReadableEvent, out _notificationStorageChannelEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_notificationStorageChannelEvent.ReadableEvent, out _notificationStorageChannelEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -653,7 +652,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
{
if (_healthWarningDisappearedSystemEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_healthWarningDisappearedSystemEvent.ReadableEvent, out _healthWarningDisappearedSystemEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_healthWarningDisappearedSystemEvent.ReadableEvent, out _healthWarningDisappearedSystemEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.Audio.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Runtime.InteropServices;
@@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn
{
KEvent bufferEvent = _impl.RegisterBufferEvent();
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.Audio.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Runtime.InteropServices;
@@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut
{
KEvent bufferEvent = _impl.RegisterBufferEvent();
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
using System.Text;
@@ -115,7 +115,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
{
KEvent deviceSystemEvent = _impl.QueryAudioDeviceSystemEvent();
if (context.Process.HandleTable.GenerateHandle(deviceSystemEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(deviceSystemEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -230,7 +230,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
{
KEvent deviceInputEvent = _impl.QueryAudioDeviceInputEvent();
if (context.Process.HandleTable.GenerateHandle(deviceInputEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(deviceInputEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -248,7 +248,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
{
KEvent deviceOutputEvent = _impl.QueryAudioDeviceOutputEvent();
if (context.Process.HandleTable.GenerateHandle(deviceOutputEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(deviceOutputEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
using System.Buffers;
@@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
if (result == ResultCode.Success)
{
if (context.Process.HandleTable.GenerateHandle(systemEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(systemEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,9 +1,9 @@
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator.Types;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
@@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
if (_eventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_event.ReadableEvent, out _eventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_event.ReadableEvent, out _eventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Bluetooth.BluetoothDriver;
using Ryujinx.HLE.HOS.Services.Settings;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Bluetooth
@@ -30,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.InitializeBleDebugEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleDebugEvent.ReadableEvent, out BluetoothEventManager.InitializeBleDebugEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleDebugEvent.ReadableEvent, out BluetoothEventManager.InitializeBleDebugEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.UnknownBleDebugEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleDebugEvent.ReadableEvent, out BluetoothEventManager.UnknownBleDebugEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleDebugEvent.ReadableEvent, out BluetoothEventManager.UnknownBleDebugEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -50,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.RegisterBleDebugEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleDebugEvent.ReadableEvent, out BluetoothEventManager.RegisterBleDebugEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleDebugEvent.ReadableEvent, out BluetoothEventManager.RegisterBleDebugEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -66,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.InitializeBleEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleEvent.ReadableEvent, out BluetoothEventManager.InitializeBleEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleEvent.ReadableEvent, out BluetoothEventManager.InitializeBleEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -76,7 +76,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.UnknownBleEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleEvent.ReadableEvent, out BluetoothEventManager.UnknownBleEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleEvent.ReadableEvent, out BluetoothEventManager.UnknownBleEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -86,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth
{
BluetoothEventManager.RegisterBleEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleEvent.ReadableEvent, out BluetoothEventManager.RegisterBleEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleEvent.ReadableEvent, out BluetoothEventManager.RegisterBleEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
{
@@ -25,7 +25,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
// AcquireBleScanEvent() -> (byte<1>, handle<copy>)
public ResultCode AcquireBleScanEvent(ServiceCtx context)
{
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (_bleScanEventHandle == 0)
{
@@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
result = context.Process.HandleTable.GenerateHandle(_bleScanEvent.ReadableEvent, out _bleScanEventHandle);
if (result != KernelResult.Success)
if (result != Result.Success)
{
// NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
@@ -42,7 +42,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleScanEventHandle);
context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
context.ResponseData.Write(result == Result.Success ? 1 : 0);
return ResultCode.Success;
}
@@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
// AcquireBleConnectionEvent() -> (byte<1>, handle<copy>)
public ResultCode AcquireBleConnectionEvent(ServiceCtx context)
{
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (_bleConnectionEventHandle == 0)
{
@@ -59,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
result = context.Process.HandleTable.GenerateHandle(_bleConnectionEvent.ReadableEvent, out _bleConnectionEventHandle);
if (result != KernelResult.Success)
if (result != Result.Success)
{
// NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
@@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleConnectionEventHandle);
context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
context.ResponseData.Write(result == Result.Success ? 1 : 0);
return ResultCode.Success;
}
@@ -77,7 +77,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
// AcquireBleServiceDiscoveryEvent() -> (byte<1>, handle<copy>)
public ResultCode AcquireBleServiceDiscoveryEvent(ServiceCtx context)
{
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (_bleServiceDiscoveryEventHandle == 0)
{
@@ -85,7 +85,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
result = context.Process.HandleTable.GenerateHandle(_bleServiceDiscoveryEvent.ReadableEvent, out _bleServiceDiscoveryEventHandle);
if (result != KernelResult.Success)
if (result != Result.Success)
{
// NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
@@ -94,7 +94,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleServiceDiscoveryEventHandle);
context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
context.ResponseData.Write(result == Result.Success ? 1 : 0);
return ResultCode.Success;
}
@@ -103,7 +103,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
// AcquireBleMtuConfigEvent() -> (byte<1>, handle<copy>)
public ResultCode AcquireBleMtuConfigEvent(ServiceCtx context)
{
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (_bleMtuConfigEventHandle == 0)
{
@@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
result = context.Process.HandleTable.GenerateHandle(_bleMtuConfigEvent.ReadableEvent, out _bleMtuConfigEventHandle);
if (result != KernelResult.Success)
if (result != Result.Success)
{
// NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
@@ -120,7 +120,7 @@ namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleMtuConfigEventHandle);
context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
context.ResponseData.Write(result == Result.Success ? 1 : 0);
return ResultCode.Success;
}

View File

@@ -4,12 +4,11 @@ using Ryujinx.Common.Logging;
using Ryujinx.Common.Memory;
using Ryujinx.Common.Utilities;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService;
using Ryujinx.Horizon.Common;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
@@ -33,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
_completionEvent = new KEvent(context.Device.System.KernelContext);
}
if (context.Process.HandleTable.GenerateHandle(_completionEvent.ReadableEvent, out int completionEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_completionEvent.ReadableEvent, out int completionEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,9 +1,9 @@
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
@@ -43,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
{
if (_notificationEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_notificationEvent.ReadableEvent, out _notificationEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_notificationEvent.ReadableEvent, out _notificationEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,6 +1,6 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Hid.HidServer
@@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.HidServer
{
if (_hidSharedMemHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_hidSharedMem, out _hidSharedMemHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_hidSharedMem, out _hidSharedMemHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,11 +1,11 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
using Ryujinx.HLE.HOS.Services.Hid.Types;
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@@ -170,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
long xpadId = context.RequestData.ReadInt64();
if (context.Process.HandleTable.GenerateHandle(_xpadIdEvent.ReadableEvent, out _xpadIdEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_xpadIdEvent.ReadableEvent, out _xpadIdEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -761,7 +761,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
long npadStyleSet = context.RequestData.ReadInt64();
KEvent evnt = context.Device.Hid.Npads.GetStyleSetUpdateEvent(npadId);
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -1597,7 +1597,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
int palmaConnectionHandle = context.RequestData.ReadInt32();
if (context.Process.HandleTable.GenerateHandle(_palmaOperationCompleteEvent.ReadableEvent, out int handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_palmaOperationCompleteEvent.ReadableEvent, out int handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,9 +1,9 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
using Ryujinx.HLE.HOS.Services.Hid.Irs.Types;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Hid.Irs
@@ -50,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Irs
if (_irsensorSharedMemoryHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,6 +1,6 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Ldn.Types;
using Ryujinx.Horizon.Common;
using System;
using System.Net;
@@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
{
if (_stateChangeEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_networkInterface.StateChangeEvent.ReadableEvent, out _stateChangeEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_networkInterface.StateChangeEvent.ReadableEvent, out _stateChangeEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -2,11 +2,11 @@
using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
using Ryujinx.Horizon.Common;
using System;
using System.Buffers.Binary;
using System.Globalization;
@@ -851,7 +851,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
context.Device.System.NfpDevices[i].ActivateEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].ActivateEvent.ReadableEvent, out int activateEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].ActivateEvent.ReadableEvent, out int activateEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -877,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
context.Device.System.NfpDevices[i].DeactivateEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].DeactivateEvent.ReadableEvent, out int deactivateEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].DeactivateEvent.ReadableEvent, out int deactivateEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -960,7 +960,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
_availabilityChangeEvent = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(_availabilityChangeEvent.ReadableEvent, out int availabilityChangeEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_availabilityChangeEvent.ReadableEvent, out int availabilityChangeEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
@@ -66,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
if (_event0Handle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_event0.ReadableEvent, out _event0Handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_event0.ReadableEvent, out _event0Handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -74,7 +74,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
if (_event1Handle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_event1.ReadableEvent, out _event1Handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_event1.ReadableEvent, out _event1Handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,8 +1,8 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Nim.ShopServiceAccessServerInterface.ShopServiceAccessServer.ShopServiceAccessor;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Nim.ShopServiceAccessServerInterface.ShopServiceAccessServer
@@ -26,7 +26,7 @@ namespace Ryujinx.HLE.HOS.Services.Nim.ShopServiceAccessServerInterface.ShopServ
if (_eventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_event.ReadableEvent, out _eventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_event.ReadableEvent, out _eventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService
@@ -43,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService
// GetFinishNotificationEvent() -> handle<copy>
public ResultCode GetFinishNotificationEvent(ServiceCtx context)
{
if (context.Process.HandleTable.GenerateHandle(_finishNotificationEvent.ReadableEvent, out int finishNotificationEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_finishNotificationEvent.ReadableEvent, out int finishNotificationEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
using System.Collections.Generic;
@@ -327,7 +327,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
{
if (_addOnContentListChangedEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_addOnContentListChangedEvent.ReadableEvent, out _addOnContentListChangedEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_addOnContentListChangedEvent.ReadableEvent, out _addOnContentListChangedEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
@@ -38,7 +38,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// GetPurchasedEventReadableHandle() -> handle<copy, event>
public ResultCode GetPurchasedEventReadableHandle(ServiceCtx context)
{
if (context.Process.HandleTable.GenerateHandle(_purchasedEvent.ReadableEvent, out int purchasedEventReadableHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_purchasedEvent.ReadableEvent, out int purchasedEventReadableHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,6 +1,6 @@
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
@@ -27,7 +27,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
{
KEvent evnt = new KEvent(context.Device.System.KernelContext);
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -2,9 +2,9 @@ using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu;
using Ryujinx.Graphics.Gpu.Synchronization;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Nv.Types;
using Ryujinx.Horizon.Common;
using System;
using System.Threading;
@@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
Event = new KEvent(system.KernelContext);
if (KernelStatic.GetCurrentProcess().HandleTable.GenerateHandle(Event.ReadableEvent, out EventHandle) != KernelResult.Success)
if (KernelStatic.GetCurrentProcess().HandleTable.GenerateHandle(Event.ReadableEvent, out EventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Diagnostics;
@@ -99,7 +99,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu
if (targetEvent != null)
{
if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != KernelResult.Success)
if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Pcv.Clkrst.ClkrstManager;
using Ryujinx.HLE.HOS.Services.Pcv.Types;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst
@@ -34,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst
{
if (_moduleStateTableEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _moduleStateTableEventHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _moduleStateTableEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Services.Pm
{
@@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Pm
KProcess process = KernelStatic.GetProcessByPid(pid);
if (context.Process.HandleTable.GenerateHandle(process, out int processHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(process, out int processHandle) != Result.Success)
{
throw new System.Exception("Out of handles!");
}

View File

@@ -1,7 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
namespace Ryujinx.HLE.HOS.Services.Ptm.Psm
{
@@ -22,11 +22,11 @@ namespace Ryujinx.HLE.HOS.Services.Ptm.Psm
{
if (_stateChangeEventHandle == -1)
{
KernelResult resultCode = context.Process.HandleTable.GenerateHandle(_stateChangeEvent.ReadableEvent, out _stateChangeEventHandle);
Result resultCode = context.Process.HandleTable.GenerateHandle(_stateChangeEvent.ReadableEvent, out _stateChangeEventHandle);
if (resultCode != KernelResult.Success)
if (resultCode != Result.Success)
{
return (ResultCode)resultCode;
return (ResultCode)resultCode.ErrorCode;
}
}

View File

@@ -1,10 +1,10 @@
using LibHac.Tools.FsSystem;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.Horizon.Common;
using Ryujinx.Memory;
using System;
using System.Collections.Generic;
@@ -217,7 +217,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
if (info.BssSize > 0)
{
KernelResult bssMappingResult = memMgr.MapProcessCodeMemory(nroMappedAddress + info.NroSize, info.BssAddress, info.BssSize);
Result bssMappingResult = memMgr.MapProcessCodeMemory(nroMappedAddress + info.NroSize, info.BssAddress, info.BssSize);
if (bssMappingResult == KernelResult.InvalidMemState)
{
@@ -226,12 +226,12 @@ namespace Ryujinx.HLE.HOS.Services.Ro
continue;
}
else if (bssMappingResult != KernelResult.Success)
else if (bssMappingResult != Result.Success)
{
memMgr.UnmapProcessCodeMemory(nroMappedAddress + info.NroSize, info.BssAddress, info.BssSize);
memMgr.UnmapProcessCodeMemory(nroMappedAddress, info.NroAddress, info.NroSize);
return (ResultCode)bssMappingResult;
return (ResultCode)bssMappingResult.ErrorCode;
}
}
@@ -286,15 +286,15 @@ namespace Ryujinx.HLE.HOS.Services.Ro
}
}
KernelResult result = memMgr.MapProcessCodeMemory(targetAddress, baseAddress, size);
Result result = memMgr.MapProcessCodeMemory(targetAddress, baseAddress, size);
if (result == KernelResult.InvalidMemState)
{
continue;
}
else if (result != KernelResult.Success)
else if (result != Result.Success)
{
return (ResultCode)result;
return (ResultCode)result.ErrorCode;
}
if (!CanAddGuardRegionsInProcess(process, targetAddress, size))
@@ -313,11 +313,11 @@ namespace Ryujinx.HLE.HOS.Services.Ro
return ResultCode.Success;
}
private KernelResult SetNroMemoryPermissions(KProcess process, IExecutable relocatableObject, ulong baseAddress)
private Result SetNroMemoryPermissions(KProcess process, IExecutable relocatableObject, ulong baseAddress)
{
ulong textStart = baseAddress + (ulong)relocatableObject.TextOffset;
ulong roStart = baseAddress + (ulong)relocatableObject.RoOffset;
ulong dataStart = baseAddress + (ulong)relocatableObject.DataOffset;
ulong textStart = baseAddress + relocatableObject.TextOffset;
ulong roStart = baseAddress + relocatableObject.RoOffset;
ulong dataStart = baseAddress + relocatableObject.DataOffset;
ulong bssStart = dataStart + (ulong)relocatableObject.Data.Length;
@@ -329,18 +329,18 @@ namespace Ryujinx.HLE.HOS.Services.Ro
MemoryHelper.FillWithZeros(process.CpuMemory, bssStart, (int)(bssEnd - bssStart));
KernelResult result;
Result result;
result = process.MemoryManager.SetProcessMemoryPermission(textStart, roStart - textStart, KMemoryPermission.ReadAndExecute);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
result = process.MemoryManager.SetProcessMemoryPermission(roStart, dataStart - roStart, KMemoryPermission.Read);
if (result != KernelResult.Success)
if (result != Result.Success)
{
return result;
}
@@ -385,7 +385,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
ulong dataSize = (ulong)info.Executable.Data.Length;
ulong bssSize = (ulong)info.Executable.BssSize;
KernelResult result = KernelResult.Success;
Result result = Result.Success;
if (info.Executable.BssSize != 0)
{
@@ -395,14 +395,14 @@ namespace Ryujinx.HLE.HOS.Services.Ro
bssSize);
}
if (result == KernelResult.Success)
if (result == Result.Success)
{
result = _owner.MemoryManager.UnmapProcessCodeMemory(
info.NroMappedAddress + textSize + roSize,
info.Executable.SourceAddress + textSize + roSize,
dataSize);
if (result == KernelResult.Success)
if (result == Result.Success)
{
result = _owner.MemoryManager.UnmapProcessCodeMemory(
info.NroMappedAddress,
@@ -411,7 +411,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
}
}
return (ResultCode)result;
return (ResultCode)result.ErrorCode;
}
private ResultCode IsInitialized(ulong pid)
@@ -452,7 +452,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
if (result == ResultCode.Success)
{
result = (ResultCode)SetNroMemoryPermissions(_owner, info.Executable, nroMappedAddress);
result = (ResultCode)SetNroMemoryPermissions(_owner, info.Executable, nroMappedAddress).ErrorCode;
if (result == ResultCode.Success)
{

View File

@@ -1,6 +1,6 @@
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Sdb.Pl.Types;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
@@ -67,7 +67,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
if (_fontSharedMemHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out _fontSharedMemHandle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out _fontSharedMemHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}

Some files were not shown because too many files have changed in this diff Show More