private static int FreeSpace(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvGpuASAllocSpace Args = AMemoryHelper.Read <NvGpuASAllocSpace>(Context.Memory, InputPosition); NvGpuASCtx ASCtx = GetASCtx(Context); int Result = NvResult.Success; lock (ASCtx) { ulong Size = (ulong)Args.Pages * (ulong)Args.PageSize; if (ASCtx.RemoveReservation(Args.Offset)) { ASCtx.Vmm.Free(Args.Offset, (long)Size); } else { Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Failed to free offset 0x{Args.Offset:x16} size 0x{Size:x16}!"); Result = NvResult.InvalidInput; } } return(Result); }
private static int FreeSpace(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvGpuASAllocSpace Args = AMemoryHelper.Read <NvGpuASAllocSpace>(Context.Memory, InputPosition); NvGpuVmm Vmm = GetVmm(Context); ulong Size = (ulong)Args.Pages * (ulong)Args.PageSize; Vmm.Free(Args.Offset, (long)Size); return(NvResult.Success); }
private static int AllocSpace(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvGpuASAllocSpace Args = AMemoryHelper.Read <NvGpuASAllocSpace>(Context.Memory, InputPosition); NvGpuASCtx ASCtx = GetASCtx(Context); ulong Size = (ulong)Args.Pages * (ulong)Args.PageSize; int Result = NvResult.Success; lock (ASCtx) { //Note: When the fixed offset flag is not set, //the Offset field holds the alignment size instead. if ((Args.Flags & FlagFixedOffset) != 0) { Args.Offset = ASCtx.Vmm.ReserveFixed(Args.Offset, (long)Size); } else { Args.Offset = ASCtx.Vmm.Reserve((long)Size, Args.Offset); } if (Args.Offset < 0) { Args.Offset = 0; Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {Size:x16}!"); Result = NvResult.OutOfMemory; } else { ASCtx.AddReservation(Args.Offset, (long)Size); } } AMemoryHelper.Write(Context.Memory, OutputPosition, Args); return(Result); }
private static int AllocSpace(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvGpuASAllocSpace Args = AMemoryHelper.Read <NvGpuASAllocSpace>(Context.Memory, InputPosition); NvGpuVmm Vmm = GetVmm(Context); ulong Size = (ulong)Args.Pages * (ulong)Args.PageSize; if ((Args.Flags & FlagFixedOffset) != 0) { Args.Offset = Vmm.Reserve(Args.Offset, (long)Size, 1); } else { Args.Offset = Vmm.Reserve((long)Size, 1); } int Result = NvResult.Success; if (Args.Offset < 0) { Args.Offset = 0; Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"No memory to allocate size {Size:x16}!"); Result = NvResult.OutOfMemory; } AMemoryHelper.Write(Context.Memory, OutputPosition, Args); return(Result); }