public virtual void addAllocatedMemory(SysMemInfo sysMemInfo) { if (sysMemInfo != null) { allocatedMemory.Add(sysMemInfo); } }
public override void start() { infos = new Dictionary <int, sceAudiocodec.AudiocodecInfo>(); edramInfo = null; base.start(); }
public virtual int sceUmdActivate(int mode, PspString drive) { umdActivated = true; Modules.IoFileMgrForUserModule.registerUmdIso(); // Notify the callback. // The callback will be executed at the next sceXXXXCB() syscall. int notifyArg = NotificationArg; Modules.ThreadManForUserModule.hleKernelNotifyCallback(SceKernelThreadInfo.THREAD_CALLBACK_UMD, notifyArg); checkWaitingThreads(); // int arg[] = { 1 }; // sceIoAssign(drive, "umd0:", "isofs0:", 1, &arg, 4); int sceIoAssign = NIDMapper.Instance.getAddressByName("sceIoAssign"); if (sceIoAssign != 0) { SysMemInfo memInfo = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceUmdActivate", SysMemUserForUser.PSP_SMEM_Low, 32, 0); int argAddr = memInfo.addr; int umdAddr = memInfo.addr + 4; int isofsAddr = memInfo.addr + 10; Memory mem = Memory.Instance; Utilities.writeStringZ(mem, umdAddr, "umd0:"); Utilities.writeStringZ(mem, isofsAddr, "isofs0:"); mem.write32(argAddr, 1); SceKernelThreadInfo thread = Modules.ThreadManForUserModule.CurrentThread; Modules.ThreadManForUserModule.executeCallback(thread, sceIoAssign, null, false, drive.Address, umdAddr, isofsAddr, 1, argAddr, 4); } return(0); }
public virtual int sceVideocodecDelete() { if (videocodecDecoderThread != null) { videocodecDecoderThread.exit(); videocodecDecoderThread = null; } if (videoCodec != null) { videoCodec = null; } if (memoryInfo != null) { Modules.SysMemUserForUserModule.free(memoryInfo); memoryInfo = null; } if (edramInfo != null) { Modules.SysMemUserForUserModule.free(edramInfo); edramInfo = null; } Modules.ThreadManForUserModule.hleKernelDelayThread(videocodecDeleteDelay, false); return(0); }
public virtual int SysMemUserForUser_FE707FDF(PspString name, int type, int size, TPointer paramsAddr) { if (paramsAddr.NotNull) { int Length = paramsAddr.getValue32(); if (Length != 4) { Console.WriteLine(string.Format("SysMemUserForUser_FE707FDF: unknown parameters with Length={0:D}", Length)); } } if (type < PSP_SMEM_Low || type > PSP_SMEM_High) { return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE); } // Always allocate memory in user area (partitionid == 2). SysMemInfo info = malloc(SysMemUserForUser.USER_PARTITION_ID, name.String, type, size, 0); if (info == null) { return(SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK); } return(info.uid); }
public HeapInfo(SysMemInfo sysMemInfo) { this.sysMemInfo = sysMemInfo; MemoryChunk memoryChunk = new MemoryChunk(sysMemInfo.addr, sysMemInfo.size); freeMemoryChunks = new MemoryChunkList(memoryChunk); allocatedMemoryChunks = new Dictionary <int, MemoryChunk>(); allocType = sysMemInfo.type; }
public virtual void sceMeFree(int addr) { SysMemInfo info = allocated.Remove(addr); if (info != null) { Modules.SysMemUserForUserModule.free(info); } }
private void installIoFunctions(pspIoDrvFuncs controllerFuncs, pspIoDrvFuncs storageFuncs, pspIoDrvFuncs partitionFuncs) { const int sizeIoFunctionStub = 12; const int numberIoFunctions = 15; SysMemInfo memInfo = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceMSstor-IoFunctions", SysMemUserForUser.PSP_SMEM_Low, sizeIoFunctionStub * numberIoFunctions, 0); int addr = memInfo.addr; controllerFuncs.ioInit = addr; addr += sizeIoFunctionStub; controllerFuncs.ioDevctl = addr; addr += sizeIoFunctionStub; installHLESyscall(controllerFuncs.ioInit, this, "hleMSstorControllerIoInit"); installHLESyscall(controllerFuncs.ioDevctl, this, "hleMSstorControllerIoDevctl"); storageFuncs.ioInit = addr; addr += sizeIoFunctionStub; storageFuncs.ioDevctl = addr; addr += sizeIoFunctionStub; storageFuncs.ioOpen = addr; addr += sizeIoFunctionStub; storageFuncs.ioIoctl = addr; addr += sizeIoFunctionStub; storageFuncs.ioClose = addr; addr += sizeIoFunctionStub; installHLESyscall(storageFuncs.ioInit, this, "hleMSstorStorageIoInit"); installHLESyscall(storageFuncs.ioDevctl, this, "hleMSstorStorageIoDevctl"); installHLESyscall(storageFuncs.ioOpen, this, "hleMSstorStorageIoOpen"); installHLESyscall(storageFuncs.ioIoctl, this, "hleMSstorStorageIoIoctl"); installHLESyscall(storageFuncs.ioClose, this, "hleMSstorStorageIoClose"); partitionFuncs.ioInit = addr; addr += sizeIoFunctionStub; partitionFuncs.ioDevctl = addr; addr += sizeIoFunctionStub; partitionFuncs.ioOpen = addr; addr += sizeIoFunctionStub; partitionFuncs.ioClose = addr; addr += sizeIoFunctionStub; partitionFuncs.ioIoctl = addr; addr += sizeIoFunctionStub; partitionFuncs.ioLseek = addr; addr += sizeIoFunctionStub; partitionFuncs.ioRead = addr; addr += sizeIoFunctionStub; partitionFuncs.ioWrite = addr; addr += sizeIoFunctionStub; installHLESyscall(partitionFuncs.ioInit, this, "hleMSstorPartitionIoInit"); installHLESyscall(partitionFuncs.ioDevctl, this, "hleMSstorPartitionIoDevctl"); installHLESyscall(partitionFuncs.ioOpen, this, "hleMSstorPartitionIoOpen"); installHLESyscall(partitionFuncs.ioClose, this, "hleMSstorPartitionIoClose"); installHLESyscall(partitionFuncs.ioIoctl, this, "hleMSstorPartitionIoIoctl"); installHLESyscall(partitionFuncs.ioLseek, this, "hleMSstorPartitionIoLseek"); installHLESyscall(partitionFuncs.ioRead, this, "hleMSstorPartitionIoRead"); installHLESyscall(partitionFuncs.ioWrite, this, "hleMSstorPartitionIoWrite"); }
public virtual int sceNetFreeInternal(int memory) { SysMemInfo info = allocatedMemory.Remove(memory); if (info != null) { Modules.SysMemUserForUserModule.free(info); } return(0); }
public virtual int sceNetMallocInternal(int size) { SysMemInfo info = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.USER_PARTITION_ID, "sceNetMallocInternal", SysMemUserForUser.PSP_SMEM_Low, size, 0); if (info == null) { return(0); } allocatedMemory[info.addr] = info; return(info.addr); }
public virtual int sceAudiocodecGetEDRAM(TPointer workArea, int codecType) { int neededMem = workArea.getValue32(16); edramInfo = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceAudiocodec-EDRAM", SysMemUserForUser.PSP_SMEM_LowAligned, neededMem, 0x40); if (edramInfo == null) { return(-1); } workArea.setValue32(12, edramInfo.addr); return(0); }
public virtual int sceMeMalloc(int size) { SysMemInfo info = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceMeCalloc", SysMemUserForUser.PSP_SMEM_Low, size, 0); if (info.addr == 0) { return(0); } allocated[info.addr] = info; return(info.addr); }
public virtual int sceVideocodecReleaseEDRAM(TPointer buffer) { buffer.setValue32(20, 0); buffer.setValue32(92, 0); if (edramInfo != null) { Modules.SysMemUserForUserModule.free(edramInfo); edramInfo = null; } return(0); }
public virtual int sceKernelGetBlockHeadAddr(int uid) { SceUidManager.checkUidPurpose(uid, "SysMem", true); SysMemInfo info = blockList[uid]; if (info == null) { Console.WriteLine(string.Format("sceKernelGetBlockHeadAddr unknown uid=0x{0:X}", uid)); return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_CHUNK_ID); } return(info.addr); }
public virtual int SysMemUserForUser_50F61D8A(int uid) { SysMemInfo info = blockList.Remove(uid); if (info == null) { Console.WriteLine("SysMemUserForUser_50F61D8A(uid=0x" + uid.ToString("x") + ") unknown uid"); return(SceKernelErrors.ERROR_KERNEL_UNKNOWN_UID); } free(info); return(0); }
public virtual int SysMemUserForUser_DB83A952(int uid, TPointer32 addr) { SysMemInfo info = blockList[uid]; if (info == null) { Console.WriteLine(string.Format("SysMemUserForUser_DB83A952 uid=0x{0:X}, addr={1}: unknown uid", uid, addr)); return(SceKernelErrors.ERROR_KERNEL_UNKNOWN_UID); } addr.setValue(info.addr); return(0); }
public virtual int scePaf_0FCDFA1E(int size) { SysMemInfo sysMemInfo = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.USER_PARTITION_ID, "scePaf_0FCDFA1E", SysMemUserForUser.PSP_SMEM_Low, size, 0); if (sysMemInfo == null) { return(0); } int addr = sysMemInfo.addr; allocated[addr] = sysMemInfo; return(addr); }
public virtual SysMemInfo separateMemoryBlock(SysMemInfo info, int size) { int newAddr = info.addr + size; int newSize = info.size - size; int newAllocatedSize = info.allocatedSize - size; // Create a new memory block SysMemInfo newSysMemInfo = new SysMemInfo(info.partitionid, info.name, info.type, newSize, newAllocatedSize, newAddr); // Resize the previous memory block info.size -= newSize; info.allocatedSize -= newAllocatedSize; return(newSysMemInfo); }
public virtual int sceNpMatching2DestroyContext(int ctxId) { if (dataBuffer != null) { Modules.SysMemUserForUserModule.free(dataBuffer); dataBuffer = null; } if (!SceUidManager.releaseId(ctxId, idContextPurpose)) { return(-1); } return(0); }
public virtual int sceMeCalloc(int num, int size) { SysMemInfo info = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceMeCalloc", SysMemUserForUser.PSP_SMEM_Low, num * size, 0); if (info.addr == 0) { return(0); } Memory mem = Memory.Instance; mem.memset(info.addr, (sbyte)0, info.size); allocated[info.addr] = info; return(info.addr); }
public virtual int sceKernelFreePartitionMemory(int uid) { SceUidManager.checkUidPurpose(uid, "SysMem", true); SysMemInfo info = blockList.Remove(uid); if (info == null) { Console.WriteLine(string.Format("sceKernelFreePartitionMemory unknown uid=0x{0:X}", uid)); return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_CHUNK_ID); } free(info); return(0); }
private SceKernelVplInfo(string name, int partitionid, int attr, int size, int memType) { this.name = name; this.attr = attr; // Strange, the PSP is allocating a size of 0x1000 when requesting a size lower than 0x30... if (size <= 0x30) { size = 0x1000; } poolSize = size - vplHeaderSize; // 32 bytes overhead per VPL freeSize = poolSize; dataBlockMap = new Dictionary <int, int>(); uid = SceUidManager.getNewUid("ThreadMan-Vpl"); threadWaitingList = ThreadWaitingList.createThreadWaitingList(SceKernelThreadInfo.PSP_WAIT_VPL, uid, attr, VplManager.PSP_VPL_ATTR_PRIORITY); this.partitionid = partitionid; // Reserve psp memory int totalVplSize = Utilities.alignUp(size, vplAddrAlignment); // 8-byte align sysMemInfo = Modules.SysMemUserForUserModule.malloc(partitionid, string.Format("ThreadMan-Vpl-0x{0:x}-{1}", uid, name), memType, totalVplSize, 0); if (sysMemInfo == null) { throw new Exception("SceKernelVplInfo: not enough free mem"); } int addr = sysMemInfo.addr; // 24 byte header, probably not necessary to mimick this Memory mem = Memory.Instance; mem.write32(addr, addr - 1); mem.write32(addr + 4, size - 8); mem.write32(addr + 8, 0); // based on number of allocations mem.write32(addr + 12, addr + size - 16); mem.write32(addr + 16, 0); // based on allocations/fragmentation mem.write32(addr + 20, 0); // based on created size? magic? allocAddress = addr; MemoryChunk initialMemoryChunk = new MemoryChunk(addr + vplHeaderSize, totalVplSize - vplHeaderSize); freeMemoryChunks = new MemoryChunkList(initialMemoryChunk); }
private void notifyRoomMessageCallback(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null || !context.Started || defaultRoomMessageCallbackFunction == 0) { return; } pspBaseCallback roomMessageCallback = Modules.ThreadManForUserModule.hleKernelCreateCallback(defaultRoomMessageCallbackFunction, 8); if (Modules.ThreadManForUserModule.hleKernelRegisterCallback(THREAD_CALLBACK_USER_DEFINED, roomMessageCallback)) { if (dataBuffer == null) { dataBuffer = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceNpMatching2-DataBuffer", SysMemUserForUser.PSP_SMEM_Low, 128, 0); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2.notifyRoomMessageCallback allocated dataBuffer {0}", dataBuffer)); } } Memory mem = Emulator.Memory; mem.memset(dataBuffer.addr, (sbyte)0, dataBuffer.size); long roomId = 0x123456789ABCDEF0L; int srcMemberId = 0x1111; int @event = 0x2101; // 0x2101, 0x2102 int data = dataBuffer.addr; string dummyString = "Hello, world!"; int stringData = data + 24; mem.write32(data + 12, stringData); mem.write32(data + 16, dummyString.Length); mem.write32(data + 20, 1); // Seems to be a flag having value 0 or 1 Utilities.writeStringZ(mem, stringData, dummyString); roomMessageCallback.setArgument(0, ctxId); roomMessageCallback.setArgument(2, (int)roomId); roomMessageCallback.setArgument(3, (int)((long)((ulong)roomId >> 32))); roomMessageCallback.setArgument(4, srcMemberId); roomMessageCallback.setArgument(5, @event); roomMessageCallback.setArgument(6, data); roomMessageCallback.setArgument(7, defaultRoomMessageCallbackArgument); Modules.ThreadManForUserModule.hleKernelNotifyCallback(THREAD_CALLBACK_USER_DEFINED, roomMessageCallback); } }
public virtual int sceVideocodecGetEDRAM(TPointer buffer, int type) { int size = (buffer.getValue32(24) + 63) | 0x3F; edramInfo = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceVideocodecEDRAM", SysMemUserForUser.PSP_SMEM_Low, size, 0); if (edramInfo == null) { return(-1); } int addrEDRAM = edramInfo.addr & EDRAM_MEMORY_MASK; buffer.setValue32(20, alignUp(addrEDRAM, 63)); buffer.setValue32(92, addrEDRAM); return(0); }
public virtual void free(SysMemInfo info) { if (info != null) { info.free(); free(info.partitionid, info.addr, info.allocatedSize); //if (log.DebugEnabled) { Console.WriteLine(string.Format("free {0}", info.ToString())); if (log.TraceEnabled) { log.trace("Free list after free: " + DebugFreeMem); log.trace("Allocated blocks after free:\n" + DebugAllocatedMem + "\n"); } } } }
public virtual int sceKernelQueryMemoryInfo(int address, TPointer32 partitionId, TPointer32 memoryBlockId) { int result = SceKernelErrors.ERROR_KERNEL_ILLEGAL_ADDR; foreach (int?key in blockList.Keys) { SysMemInfo info = blockList[key]; if (info != null && info.addr <= address && address < info.addr + info.size) { partitionId.setValue(info.partitionid); memoryBlockId.setValue(info.uid); result = 0; break; } } return(result); }
public virtual int sceKernelAllocPartitionMemory(int partitionid, string name, int type, int size, int addr) { addr &= Memory.addressMask; if (type < PSP_SMEM_Low || type > PSP_SMEM_HighAligned) { return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE); } SysMemInfo info = malloc(partitionid, name, type, size, addr); if (info == null) { return(SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK); } return(info.uid); }
public virtual bool resizeMemoryBlock(SysMemInfo info, int leftShift, int rightShift) { if (rightShift < 0) { int sizeToFree = -rightShift; free(info.partitionid, info.addr + info.allocatedSize - sizeToFree, sizeToFree); info.allocatedSize -= sizeToFree; info.size -= sizeToFree; } else if (rightShift > 0) { int sizeToExtend = rightShift; int extendAddr = alloc(info.partitionid, info.addr + info.allocatedSize, sizeToExtend); if (extendAddr == 0) { return(false); } info.allocatedSize += sizeToExtend; info.size += sizeToExtend; } if (leftShift < 0) { int sizeToFree = -leftShift; free(info.partitionid, info.addr, sizeToFree); info.addr += sizeToFree; info.size -= sizeToFree; info.allocatedSize -= sizeToFree; } else if (leftShift > 0) { int sizeToExtend = leftShift; int extendAddr = alloc(info.partitionid, info.addr - sizeToExtend, sizeToExtend); if (extendAddr == 0) { return(false); } info.addr -= sizeToExtend; info.allocatedSize += sizeToExtend; info.size += sizeToExtend; } return(true); }
public virtual int sceAudiocodecReleaseEDRAM(TPointer workArea) { if (edramInfo == null) { return(SceKernelErrors.ERROR_CODEC_AUDIO_EDRAM_NOT_ALLOCATED); } Modules.SysMemUserForUserModule.free(edramInfo); edramInfo = null; AudiocodecInfo info = infos.Remove(workArea.Address); if (info != null) { info.release(); info.CodecInitialized = false; } 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); }