From 6d1929f2bfa73f611a14379e86efd1ad9026de66 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 5 Aug 2018 16:52:23 -0300 Subject: [PATCH] Fix address space reserve alignment --- Ryujinx.HLE/Gpu/Memory/NvGpuVmm.cs | 6 +-- .../OsHle/Services/Nv/NvGpuAS/NvGpuASIoctl.cs | 45 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Ryujinx.HLE/Gpu/Memory/NvGpuVmm.cs b/Ryujinx.HLE/Gpu/Memory/NvGpuVmm.cs index 8ced6a48f9..84dc739a15 100644 --- a/Ryujinx.HLE/Gpu/Memory/NvGpuVmm.cs +++ b/Ryujinx.HLE/Gpu/Memory/NvGpuVmm.cs @@ -64,7 +64,7 @@ namespace Ryujinx.HLE.Gpu.Memory { if (GetPte(VA + Offset) != PteReserved) { - return Map(PA, Size); + return -1; } } @@ -115,7 +115,7 @@ namespace Ryujinx.HLE.Gpu.Memory return false; } - public long Reserve(long VA, long Size, long Align) + public long ReserveFixed(long VA, long Size) { lock (PageTable) { @@ -123,7 +123,7 @@ namespace Ryujinx.HLE.Gpu.Memory { if (IsPageInUse(VA + Offset)) { - return Reserve(Size, Align); + return -1; } } diff --git a/Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASIoctl.cs b/Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASIoctl.cs index fcc478a417..d92fd4cddf 100644 --- a/Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASIoctl.cs +++ b/Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASIoctl.cs @@ -29,7 +29,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS case 0x4106: return MapBufferEx (Context); case 0x4108: return GetVaRegions(Context); case 0x4109: return InitializeEx(Context); - case 0x4114: return Remap (Context); + case 0x4114: return Remap (Context, Cmd); } throw new NotImplementedException(Cmd.ToString("x8")); @@ -59,11 +59,11 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS if ((Args.Flags & FlagFixedOffset) != 0) { - Args.Offset = Vmm.Reserve(Args.Offset, (long)Size, 1); + Args.Offset = Vmm.ReserveFixed(Args.Offset, (long)Size); } else { - Args.Offset = Vmm.Reserve((long)Size, 1); + Args.Offset = Vmm.Reserve((long)Size, Args.Offset); } int Result = NvResult.Success; @@ -206,27 +206,38 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS return NvResult.Success; } - private static int Remap(ServiceCtx Context) + private static int Remap(ServiceCtx Context, int Cmd) { + int Count = ((Cmd >> 16) & 0xff) / 0x14; + long InputPosition = Context.Request.GetBufferType0x21().Position; - NvGpuASRemap Args = AMemoryHelper.Read(Context.Memory, InputPosition); - - NvGpuVmm Vmm = GetVmm(Context); - - NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle); - - if (Map == null) + for (int Index = 0; Index < Count; Index++, InputPosition += 0x14) { - Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!"); + NvGpuASRemap Args = AMemoryHelper.Read(Context.Memory, InputPosition); - return NvResult.InvalidInput; + NvGpuVmm Vmm = GetVmm(Context); + + NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle); + + if (Map == null) + { + Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!"); + + return NvResult.InvalidInput; + } + + long Result = Vmm.Map(Map.Address, (long)(uint)Args.Offset << 16, + (long)(uint)Args.Pages << 16); + + if (Result < 0) + { + Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Page 0x{Args.Offset:x16} size 0x{Args.Pages:x16} not allocated!"); + + return NvResult.InvalidInput; + } } - //FIXME: This is most likely wrong... - Vmm.Map(Map.Address, (long)(uint)Args.Offset << 16, - (long)(uint)Args.Pages << 16); - return NvResult.Success; }