Esempio n. 1
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);

            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.Device.Log.PrintWarning(LogClass.ServiceNv,
                                                    $"Failed to free offset 0x{Args.Offset:x16} size 0x{Size:x16}!");

                    Result = NvResult.InvalidInput;
                }
            }

            return(Result);
        }
Esempio n. 2
0
        private static int FreeSpace(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);

            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
                {
                    Logger.PrintWarning(LogClass.ServiceNv,
                                        $"Failed to free offset 0x{args.Offset:x16} size 0x{size:x16}!");

                    result = NvResult.InvalidInput;
                }
            }

            return(result);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }