private static int MapBuffer(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvHostChannelMapBuffer Args = MemoryHelper.Read <NvHostChannelMapBuffer>(Context.Memory, InputPosition); NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm; for (int Index = 0; Index < Args.NumEntries; Index++) { int Handle = Context.Memory.ReadInt32(InputPosition + 0xc + Index * 8); NvMapHandle Map = NvMapIoctl.GetNvMap(Context, Handle); if (Map == null) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Handle:x8}!"); return(NvResult.InvalidInput); } lock (Map) { if (Map.DmaMapAddress == 0) { Map.DmaMapAddress = Vmm.MapLow(Map.Address, Map.Size); } Context.Memory.WriteInt32(OutputPosition + 0xc + 4 + Index * 8, (int)Map.DmaMapAddress); } } return(NvResult.Success); }
private static int MapBuffer(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvHostChannelMapBuffer args = MemoryHelper.Read <NvHostChannelMapBuffer>(context.Memory, inputPosition); NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm; for (int index = 0; index < args.NumEntries; index++) { int handle = context.Memory.ReadInt32(inputPosition + 0xc + index * 8); NvMapHandle map = NvMapIoctl.GetNvMap(context, handle); if (map == null) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{handle:x8}!"); return(NvResult.InvalidInput); } lock (map) { if (map.DmaMapAddress == 0) { map.DmaMapAddress = vmm.MapLow(map.Address, map.Size); } context.Memory.WriteInt32(outputPosition + 0xc + 4 + index * 8, (int)map.DmaMapAddress); } } return(NvResult.Success); }
private NvInternalResult MapCommandBuffer(Span <byte> arguments) { int headerSize = Unsafe.SizeOf <MapCommandBufferArguments>(); MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast <byte, MapCommandBufferArguments>(arguments)[0]; Span <CommandBufferHandle> commandBufferEntries = MemoryMarshal.Cast <byte, CommandBufferHandle>(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(Owner).Vmm; foreach (ref CommandBufferHandle commandBufferEntry in commandBufferEntries) { NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(Owner, commandBufferEntry.MapHandle); if (map == null) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{commandBufferEntry.MapHandle:x8}!"); return(NvInternalResult.InvalidInput); } lock (map) { if (map.DmaMapAddress == 0) { map.DmaMapAddress = vmm.MapLow(map.Address, map.Size); } commandBufferEntry.MapAddress = (int)map.DmaMapAddress; } } return(NvInternalResult.Success); }