コード例 #1
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);

            NvGpuVmm Vmm = GetVmm(Context);

            ulong Size = (ulong)Args.Pages *
                         (ulong)Args.PageSize;

            if ((Args.Flags & FlagFixedOffset) != 0)
            {
                Args.Offset = Vmm.Reserve(Args.Offset, (long)Size, 1);
            }
            else
            {
                Args.Offset = Vmm.Reserve((long)Size, 1);
            }

            int Result = NvResult.Success;

            if (Args.Offset < 0)
            {
                Args.Offset = 0;

                Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"No memory to allocate size {Size:x16}!");

                Result = NvResult.OutOfMemory;
            }

            AMemoryHelper.Write(Context.Memory, OutputPosition, Args);

            return(Result);
        }