Adjust naming conventions and general refactoring in HLE Project (#490)

* Rename enum fields

* Naming conventions

* Remove unneeded ".this"

* Remove unneeded semicolons

* Remove unused Usings

* Don't use var

* Remove unneeded enum underlying types

* Explicitly label class visibility

* Remove unneeded @ prefixes

* Remove unneeded commas

* Remove unneeded if expressions

* Method doesn't use unsafe code

* Remove unneeded casts

* Initialized objects don't need an empty constructor

* Remove settings from DotSettings

* Revert "Explicitly label class visibility"

This reverts commit ad5eb5787cc5b27a4631cd46ef5f551c4ae95e51.

* Small changes

* Revert external enum renaming

* Changes from feedback

* Remove unneeded property setters
This commit is contained in:
Alex Barney 2018-12-04 14:23:37 -06:00 committed by gdkchan
parent c86aacde76
commit 85dbb9559a
299 changed files with 12268 additions and 12276 deletions

View file

@ -11,290 +11,290 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvMap
{
private const int FlagNotFreedYet = 1;
private static ConcurrentDictionary<KProcess, IdDictionary> Maps;
private static ConcurrentDictionary<KProcess, IdDictionary> _maps;
static NvMapIoctl()
{
Maps = new ConcurrentDictionary<KProcess, IdDictionary>();
_maps = new ConcurrentDictionary<KProcess, IdDictionary>();
}
public static int ProcessIoctl(ServiceCtx Context, int Cmd)
public static int ProcessIoctl(ServiceCtx context, int cmd)
{
switch (Cmd & 0xffff)
switch (cmd & 0xffff)
{
case 0x0101: return Create(Context);
case 0x0103: return FromId(Context);
case 0x0104: return Alloc (Context);
case 0x0105: return Free (Context);
case 0x0109: return Param (Context);
case 0x010e: return GetId (Context);
case 0x0101: return Create(context);
case 0x0103: return FromId(context);
case 0x0104: return Alloc (context);
case 0x0105: return Free (context);
case 0x0109: return Param (context);
case 0x010e: return GetId (context);
}
Logger.PrintWarning(LogClass.ServiceNv, $"Unsupported Ioctl command 0x{Cmd:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Unsupported Ioctl command 0x{cmd:x8}!");
return NvResult.NotSupported;
}
private static int Create(ServiceCtx Context)
private static int Create(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapCreate Args = MemoryHelper.Read<NvMapCreate>(Context.Memory, InputPosition);
NvMapCreate args = MemoryHelper.Read<NvMapCreate>(context.Memory, inputPosition);
if (Args.Size == 0)
if (args.Size == 0)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid size 0x{Args.Size:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid size 0x{args.Size:x8}!");
return NvResult.InvalidInput;
}
int Size = IntUtils.AlignUp(Args.Size, NvGpuVmm.PageSize);
int size = IntUtils.AlignUp(args.Size, NvGpuVmm.PageSize);
Args.Handle = AddNvMap(Context, new NvMapHandle(Size));
args.Handle = AddNvMap(context, new NvMapHandle(size));
Logger.PrintInfo(LogClass.ServiceNv, $"Created map {Args.Handle} with size 0x{Size:x8}!");
Logger.PrintInfo(LogClass.ServiceNv, $"Created map {args.Handle} with size 0x{size:x8}!");
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
private static int FromId(ServiceCtx Context)
private static int FromId(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapFromId Args = MemoryHelper.Read<NvMapFromId>(Context.Memory, InputPosition);
NvMapFromId args = MemoryHelper.Read<NvMapFromId>(context.Memory, inputPosition);
NvMapHandle Map = GetNvMap(Context, Args.Id);
NvMapHandle map = GetNvMap(context, args.Id);
if (Map == null)
if (map == null)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!");
return NvResult.InvalidInput;
}
Map.IncrementRefCount();
map.IncrementRefCount();
Args.Handle = Args.Id;
args.Handle = args.Id;
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
private static int Alloc(ServiceCtx Context)
private static int Alloc(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapAlloc Args = MemoryHelper.Read<NvMapAlloc>(Context.Memory, InputPosition);
NvMapAlloc args = MemoryHelper.Read<NvMapAlloc>(context.Memory, inputPosition);
NvMapHandle Map = GetNvMap(Context, Args.Handle);
NvMapHandle map = GetNvMap(context, args.Handle);
if (Map == null)
if (map == null)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!");
return NvResult.InvalidInput;
}
if ((Args.Align & (Args.Align - 1)) != 0)
if ((args.Align & (args.Align - 1)) != 0)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid alignment 0x{Args.Align:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid alignment 0x{args.Align:x8}!");
return NvResult.InvalidInput;
}
if ((uint)Args.Align < NvGpuVmm.PageSize)
if ((uint)args.Align < NvGpuVmm.PageSize)
{
Args.Align = NvGpuVmm.PageSize;
args.Align = NvGpuVmm.PageSize;
}
int Result = NvResult.Success;
int result = NvResult.Success;
if (!Map.Allocated)
if (!map.Allocated)
{
Map.Allocated = true;
map.Allocated = true;
Map.Align = Args.Align;
Map.Kind = (byte)Args.Kind;
map.Align = args.Align;
map.Kind = (byte)args.Kind;
int Size = IntUtils.AlignUp(Map.Size, NvGpuVmm.PageSize);
int size = IntUtils.AlignUp(map.Size, NvGpuVmm.PageSize);
long Address = Args.Address;
long address = args.Address;
if (Address == 0)
if (address == 0)
{
//When the address is zero, we need to allocate
//our own backing memory for the NvMap.
//TODO: Is this allocation inside the transfer memory?
Result = NvResult.OutOfMemory;
result = NvResult.OutOfMemory;
}
if (Result == NvResult.Success)
if (result == NvResult.Success)
{
Map.Size = Size;
Map.Address = Address;
map.Size = size;
map.Address = address;
}
}
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return Result;
return result;
}
private static int Free(ServiceCtx Context)
private static int Free(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapFree Args = MemoryHelper.Read<NvMapFree>(Context.Memory, InputPosition);
NvMapFree args = MemoryHelper.Read<NvMapFree>(context.Memory, inputPosition);
NvMapHandle Map = GetNvMap(Context, Args.Handle);
NvMapHandle map = GetNvMap(context, args.Handle);
if (Map == null)
if (map == null)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!");
return NvResult.InvalidInput;
}
if (Map.DecrementRefCount() <= 0)
if (map.DecrementRefCount() <= 0)
{
DeleteNvMap(Context, Args.Handle);
DeleteNvMap(context, args.Handle);
Logger.PrintInfo(LogClass.ServiceNv, $"Deleted map {Args.Handle}!");
Logger.PrintInfo(LogClass.ServiceNv, $"Deleted map {args.Handle}!");
Args.Address = Map.Address;
Args.Flags = 0;
args.Address = map.Address;
args.Flags = 0;
}
else
{
Args.Address = 0;
Args.Flags = FlagNotFreedYet;
args.Address = 0;
args.Flags = FlagNotFreedYet;
}
Args.Size = Map.Size;
args.Size = map.Size;
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
private static int Param(ServiceCtx Context)
private static int Param(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapParam Args = MemoryHelper.Read<NvMapParam>(Context.Memory, InputPosition);
NvMapParam args = MemoryHelper.Read<NvMapParam>(context.Memory, inputPosition);
NvMapHandle Map = GetNvMap(Context, Args.Handle);
NvMapHandle map = GetNvMap(context, args.Handle);
if (Map == null)
if (map == null)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!");
return NvResult.InvalidInput;
}
switch ((NvMapHandleParam)Args.Param)
switch ((NvMapHandleParam)args.Param)
{
case NvMapHandleParam.Size: Args.Result = Map.Size; break;
case NvMapHandleParam.Align: Args.Result = Map.Align; break;
case NvMapHandleParam.Heap: Args.Result = 0x40000000; break;
case NvMapHandleParam.Kind: Args.Result = Map.Kind; break;
case NvMapHandleParam.Compr: Args.Result = 0; break;
case NvMapHandleParam.Size: args.Result = map.Size; break;
case NvMapHandleParam.Align: args.Result = map.Align; break;
case NvMapHandleParam.Heap: args.Result = 0x40000000; break;
case NvMapHandleParam.Kind: args.Result = map.Kind; break;
case NvMapHandleParam.Compr: args.Result = 0; break;
//Note: Base is not supported and returns an error.
//Any other value also returns an error.
default: return NvResult.InvalidInput;
}
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
private static int GetId(ServiceCtx Context)
private static int GetId(ServiceCtx context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
NvMapGetId Args = MemoryHelper.Read<NvMapGetId>(Context.Memory, InputPosition);
NvMapGetId args = MemoryHelper.Read<NvMapGetId>(context.Memory, inputPosition);
NvMapHandle Map = GetNvMap(Context, Args.Handle);
NvMapHandle map = GetNvMap(context, args.Handle);
if (Map == null)
if (map == null)
{
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!");
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!");
return NvResult.InvalidInput;
}
Args.Id = Args.Handle;
args.Id = args.Handle;
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
private static int AddNvMap(ServiceCtx Context, NvMapHandle Map)
private static int AddNvMap(ServiceCtx context, NvMapHandle map)
{
IdDictionary Dict = Maps.GetOrAdd(Context.Process, (Key) =>
IdDictionary dict = _maps.GetOrAdd(context.Process, (key) =>
{
IdDictionary NewDict = new IdDictionary();
IdDictionary newDict = new IdDictionary();
NewDict.Add(0, new NvMapHandle());
newDict.Add(0, new NvMapHandle());
return NewDict;
return newDict;
});
return Dict.Add(Map);
return dict.Add(map);
}
private static bool DeleteNvMap(ServiceCtx Context, int Handle)
private static bool DeleteNvMap(ServiceCtx context, int handle)
{
if (Maps.TryGetValue(Context.Process, out IdDictionary Dict))
if (_maps.TryGetValue(context.Process, out IdDictionary dict))
{
return Dict.Delete(Handle) != null;
return dict.Delete(handle) != null;
}
return false;
}
public static void InitializeNvMap(ServiceCtx Context)
public static void InitializeNvMap(ServiceCtx context)
{
IdDictionary Dict = Maps.GetOrAdd(Context.Process, (Key) =>new IdDictionary());
IdDictionary dict = _maps.GetOrAdd(context.Process, (key) =>new IdDictionary());
Dict.Add(0, new NvMapHandle());
dict.Add(0, new NvMapHandle());
}
public static NvMapHandle GetNvMapWithFb(ServiceCtx Context, int Handle)
public static NvMapHandle GetNvMapWithFb(ServiceCtx context, int handle)
{
if (Maps.TryGetValue(Context.Process, out IdDictionary Dict))
if (_maps.TryGetValue(context.Process, out IdDictionary dict))
{
return Dict.GetData<NvMapHandle>(Handle);
return dict.GetData<NvMapHandle>(handle);
}
return null;
}
public static NvMapHandle GetNvMap(ServiceCtx Context, int Handle)
public static NvMapHandle GetNvMap(ServiceCtx context, int handle)
{
if (Handle != 0 && Maps.TryGetValue(Context.Process, out IdDictionary Dict))
if (handle != 0 && _maps.TryGetValue(context.Process, out IdDictionary dict))
{
return Dict.GetData<NvMapHandle>(Handle);
return dict.GetData<NvMapHandle>(handle);
}
return null;
}
public static void UnloadProcess(KProcess Process)
public static void UnloadProcess(KProcess process)
{
Maps.TryRemove(Process, out _);
_maps.TryRemove(process, out _);
}
}
}