private static int Alloc(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvMapAlloc args = MemoryHelper.Read <NvMapAlloc>(context.Memory, inputPosition); NvMapHandle map = GetNvMap(context, args.Handle); if (map == null) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{args.Handle:x8}!"); return(NvResult.InvalidInput); } if ((args.Align & (args.Align - 1)) != 0) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid alignment 0x{args.Align:x8}!"); return(NvResult.InvalidInput); } if ((uint)args.Align < NvGpuVmm.PageSize) { args.Align = NvGpuVmm.PageSize; } int result = NvResult.Success; if (!map.Allocated) { map.Allocated = true; map.Align = args.Align; map.Kind = (byte)args.Kind; int size = IntUtils.AlignUp(map.Size, NvGpuVmm.PageSize); long address = args.Address; 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; } if (result == NvResult.Success) { map.Size = size; map.Address = address; } } MemoryHelper.Write(context.Memory, outputPosition, args); return(result); }
private static int Alloc(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvMapAlloc Args = MemoryHelper.Read <NvMapAlloc>(Context.Memory, InputPosition); NvMapHandle Map = GetNvMap(Context, Args.Handle); if (Map == null) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!"); return(NvResult.InvalidInput); } if ((Args.Align & (Args.Align - 1)) != 0) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid alignment 0x{Args.Align:x8}!"); return(NvResult.InvalidInput); } if ((uint)Args.Align < NvGpuVmm.PageSize) { Args.Align = NvGpuVmm.PageSize; } int Result = NvResult.Success; if (!Map.Allocated) { Map.Allocated = true; Map.Align = Args.Align; Map.Kind = (byte)Args.Kind; int Size = IntUtils.AlignUp(Map.Size, NvGpuVmm.PageSize); long Address = Args.Address; 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; } if (Result == NvResult.Success) { Map.Size = Size; Map.Address = Address; } } MemoryHelper.Write(Context.Memory, OutputPosition, Args); return(Result); }