public static bool DecrementMapRefCount(KProcess process, int handle) { NvMapHandle map = GetMapFromHandle(process, handle, false); if (map == null) { return(false); } if (map.DecrementRefCount() <= 0) { DeleteMapWithHandle(process, handle); Logger.Info?.Print(LogClass.ServiceNv, $"Deleted map {handle}!"); return(true); } else { return(false); } }
private static int GetId(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvMapGetId args = MemoryHelper.Read <NvMapGetId>(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); } args.Id = args.Handle; MemoryHelper.Write(context.Memory, outputPosition, args); return(NvResult.Success); }
private static int Free(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvMapFree args = MemoryHelper.Read <NvMapFree>(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 (map.DecrementRefCount() <= 0) { DeleteNvMap(context, args.Handle); Logger.PrintInfo(LogClass.ServiceNv, $"Deleted map {args.Handle}!"); args.Address = map.Address; args.Flags = 0; } else { args.Address = 0; args.Flags = FlagNotFreedYet; } args.Size = map.Size; MemoryHelper.Write(context.Memory, outputPosition, args); return(NvResult.Success); }
private static int Param(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvMapParam args = MemoryHelper.Read <NvMapParam>(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); } switch ((NvMapHandleParam)args.Param) { case NvMapHandleParam.Size: args.Result = map.Size; break; case NvMapHandleParam.Align: args.Result = map.Align; break; case NvMapHandleParam.Heap: args.Result = 0x40000000; break; case NvMapHandleParam.Kind: args.Result = map.Kind; break; case NvMapHandleParam.Compr: args.Result = 0; break; // Note: Base is not supported and returns an error. // Any other value also returns an error. default: return(NvResult.InvalidInput); } MemoryHelper.Write(context.Memory, outputPosition, args); return(NvResult.Success); }
private int CreateHandleFromMap(NvMapHandle map) { IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary()); return(dict.Add(map)); }