Example #1
0
        private static int UnmapBuffer(ServiceCtx Context)
        {
            long InputPosition = Context.Request.GetBufferType0x21().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)
                    {
                        Vmm.Free(Map.DmaMapAddress, Map.Size);

                        Map.DmaMapAddress = 0;
                    }
                }
            }

            return(NvResult.Success);
        }
Example #2
0
        private static int UnmapBuffer(ServiceCtx context)
        {
            long inputPosition = context.Request.GetBufferType0x21().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)
                    {
                        vmm.Free(map.DmaMapAddress, map.Size);

                        map.DmaMapAddress = 0;
                    }
                }
            }

            return(NvResult.Success);
        }
Example #3
0
        private NvInternalResult UnmapCommandBuffer(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)
                    {
                        vmm.Free(map.DmaMapAddress, map.Size);

                        map.DmaMapAddress = 0;
                    }
                }
            }

            return(NvInternalResult.Success);
        }
Example #4
0
        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);
        }