public virtual int sceHeapDeleteHeap(TPointer heapAddr) { HeapInfo heapInfo = heapMap.Remove(heapAddr.Address); if (heapInfo == null) { return(SceKernelErrors.ERROR_INVALID_ID); } heapInfo.delete(); return(0); }
public virtual int sceHeapIsAllocatedHeapMemory(TPointer heapAddr, TPointer memAddr) { if (!heapMap.ContainsKey(heapAddr.Address)) { return(SceKernelErrors.ERROR_INVALID_ID); } HeapInfo heapInfo = heapMap[heapAddr.Address]; if (heapInfo.allocatedMemoryChunks.ContainsKey(memAddr.Address)) { return(1); } return(0); }
public virtual int sceHeapAllocHeapMemory(TPointer heapAddr, int memSize) { // Try to allocate memory from the heap and return it's address. HeapInfo heapInfo = heapMap[heapAddr.Address]; if (heapInfo == null) { return(0); } int allocatedAddr = heapInfo.alloc(memSize, defaultAllocAlignment); if (log.TraceEnabled) { log.trace(string.Format("sceHeapAllocHeapMemory returns 0x{0:X8}, after allocation: {1}", allocatedAddr, heapInfo)); } return(allocatedAddr); }
public virtual int sceHeapFreeHeapMemory(TPointer heapAddr, TPointer memAddr) { // Try to free memory back to the heap. HeapInfo heapInfo = heapMap[heapAddr.Address]; if (heapInfo == null) { return(SceKernelErrors.ERROR_INVALID_ID); } if (!heapInfo.free(memAddr.Address)) { return(SceKernelErrors.ERROR_INVALID_POINTER); } if (log.TraceEnabled) { log.trace(string.Format("sceHeapFreeHeapMemory after free: {0}", heapInfo)); } return(0); }
public virtual int sceHeapCreateHeap(PspString name, int heapSize, int attr, TPointer paramAddr) { if (paramAddr.NotNull) { Console.WriteLine(string.Format("sceHeapCreateHeap unknown option at {0}", paramAddr)); } int memType = PSP_SMEM_Low; if ((attr & PSP_HEAP_ATTR_ADDR_HIGH) == PSP_HEAP_ATTR_ADDR_HIGH) { memType = PSP_SMEM_High; } // Allocate a virtual heap memory space and return it's address. SysMemInfo info = null; int alignment = 4; int totalHeapSize = (heapSize + (alignment - 1)) & (~(alignment - 1)); int partitionId = SysMemUserForUser.USER_PARTITION_ID; int maxFreeSize = Modules.SysMemUserForUserModule.maxFreeMemSize(partitionId); if (totalHeapSize <= maxFreeSize) { info = Modules.SysMemUserForUserModule.malloc(partitionId, name.String, memType, totalHeapSize, 0); } else { Console.WriteLine(string.Format("sceHeapCreateHeap not enough free mem (want={0:D}, free={1:D}, diff={2:D})", totalHeapSize, maxFreeSize, totalHeapSize - maxFreeSize)); } if (info == null) { return(0); // Returns NULL on error. } HeapInfo heapInfo = new HeapInfo(info); heapMap[info.addr] = heapInfo; return(info.addr); }
public virtual int sceHeapAllocHeapMemoryWithOption(TPointer heapAddr, int memSize, TPointer32 paramAddr) { int alignment = defaultAllocAlignment; if (paramAddr.NotNull) { int paramSize = paramAddr.getValue(0); if (paramSize == 8) { alignment = paramAddr.getValue(4); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceHeapAllocHeapMemoryWithOption options: struct size={0:D}, alignment=0x{1:X}", paramSize, alignment)); } } else { Console.WriteLine(string.Format("sceHeapAllocHeapMemoryWithOption option at {0}(size={1:D})", paramAddr, paramSize)); } } // Try to allocate memory from the heap and return it's address. HeapInfo heapInfo = heapMap[heapAddr.Address]; if (heapInfo == null) { return(0); } int allocatedAddr = heapInfo.alloc(memSize, alignment); if (log.TraceEnabled) { log.trace(string.Format("sceHeapAllocHeapMemoryWithOption returns 0x{0:X8}, after allocation: {1}", allocatedAddr, heapInfo)); } return(allocatedAddr); }
public Heap(HeapInfo info) { Info = info; BaseAddress = ID = info.HeapID; }
public Heap(int snapshotID, UInt32 id) { BaseAddress = ID = id; Info = new HeapInfo(snapshotID, id); }