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.Device.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 = MemoryHelper.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; Logger.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {size:x16}!"); result = NvResult.OutOfMemory; } else { asCtx.AddReservation(args.Offset, (long)size); } } MemoryHelper.Write(context.Memory, outputPosition, args); return(result); }