public virtual int sceGeSetCallback(TPointer cbdata_addr) { pspGeCallbackData cbdata = new pspGeCallbackData(); cbdata.read(cbdata_addr); // The cbid returned has a value in the range [0..15]. int cbid = SceUidManager.getNewId(geCallbackPurpose, 0, 15); if (cbid == SceUidManager.INVALID_ID) { Console.WriteLine(string.Format("sceGeSetCallback no more callback ID available")); return(SceKernelErrors.ERROR_OUT_OF_MEMORY); } //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceGeSetCallback signalFunc=0x{0:X8}, signalArg=0x{1:X8}, finishFunc=0x{2:X8}, finishArg=0x{3:X8}, result cbid=0x{4:X}", cbdata.signalFunction, cbdata.signalArgument, cbdata.finishFunction, cbdata.finishArgument, cbid)); } ThreadManForUser threadMan = Modules.ThreadManForUserModule; SceKernelCallbackInfo callbackSignal = threadMan.hleKernelCreateCallback("GeCallbackSignal", cbdata.signalFunction, cbdata.signalArgument); SceKernelCallbackInfo callbackFinish = threadMan.hleKernelCreateCallback("GeCallbackFinish", cbdata.finishFunction, cbdata.finishArgument); signalCallbacks[cbid] = callbackSignal; finishCallbacks[cbid] = callbackFinish; return(cbid); }
public virtual int sceNetResolverDelete(int rid) { RIDs.Remove(rid); SceUidManager.releaseUid(rid, uidPurpose); return(0); }
public SceModule(bool isFlashModule) { this.isFlashModule = isFlashModule; modid = SceUidManager.getNewUid("SceModule"); sceModuleAddressOffset -= (size + 256) & ~255; address = sceModuleAddressOffset; // Link SceModule structs together if (previousModule != null) { previousModule.next = address; } previousModule = this; // Internal context fileFormat = Loader.FORMAT_UNKNOWN; //textsection = new int[2]; initsection = new int[2]; finisection = new int[2]; stubtextsection = new int[2]; unresolvedImports = new LinkedList <DeferredStub>(); importFixupAttempts = 0; resolvedImports = new LinkedList <DeferredStub>(); allocatedMemory = new LinkedList <SysMemInfo>(); }
public virtual int sceNpMatching2CreateContext(TPointer communicationId, TPointer passPhrase, TPointer16 ctxId, int unknown) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2CreateContext communicationId={0}, passPhrase={1}", Utilities.getMemoryDump(communicationId.Address, 12), Utilities.getMemoryDump(passPhrase.Address, 128))); } // Returning a ctxId in range [1..7] int uid = SceUidManager.getNewId(idContextPurpose, 1, 7); if (uid == SceUidManager.INVALID_ID) { return(-1); } contextMap[uid] = new MatchingContext(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2CreateContext returning 0x{0:X}", uid)); } ctxId.Value = uid; return(0); }
public virtual int sceNetApctlAddHandler(TPointer handler, int handlerArg) { int uid = SceUidManager.getNewUid(uidPurpose); ApctlHandler apctlHandler = new ApctlHandler(this, uid, handler.Address, handlerArg); apctlHandlers[uid] = apctlHandler; return(uid); }
public virtual int sceNetResolverCreate(TPointer32 pRid, TPointer buffer, int bufferLength) { int newID = SceUidManager.getNewUid(uidPurpose); ResolverID newRID = new ResolverID(newID, true); RIDs[newID] = newRID; pRid.setValue(newRID.ID); return(0); }
public virtual void initNewPsp(bool fromSyscall) { moduleLoaded = false; HLEModuleManager.Instance.stopModules(); NIDMapper.Instance.unloadAll(); RuntimeContext.reset(); if (!fromSyscall) { // Do not reset the profiler if we have been called from sceKernelLoadExec Profiler.reset(); GEProfiler.reset(); // Do not reset the clock if we have been called from sceKernelLoadExec Clock.reset(); } Processor.reset(); Scheduler.reset(); Memory mem = Memory.Instance; if (!fromSyscall) { // Clear all memory, including VRAM. mem.Initialise(); } else { // Clear all memory excepted VRAM. // E.g. screen is not cleared when executing syscall sceKernelLoadExec(). mem.memset(MemoryMap.START_SCRATCHPAD, (sbyte)0, MemoryMap.SIZE_SCRATCHPAD); mem.memset(MemoryMap.START_RAM, (sbyte)0, MemoryMap.SIZE_RAM); } Battery.initialize(); Wlan.initialize(); SceModule.ResetAllocator(); SceUidManager.reset(); HLEUidObjectMapping.reset(); ProOnlineNetworkAdapter.init(); if (State.fileLogger != null) { State.fileLogger.resetLogging(); } MemorySections.Instance.reset(); HLEModuleManager.Instance.init(); Managers.reset(); Modules.SysMemUserForUserModule.start(); Modules.SysMemUserForUserModule.FirmwareVersion = firmwareVersion; Modules.ThreadManForUserModule.start(); }
public SysMemInfo(int partitionid, string name, int type, int size, int allocatedSize, int addr) { this.partitionid = partitionid; this.name = name; this.type = type; this.size = size; this.allocatedSize = allocatedSize; this.addr = addr; uid = SceUidManager.getNewUid("SysMem"); blockList[uid] = this; }
public virtual int sceNetApctlDelHandler(int handlerId) { if (!apctlHandlers.ContainsKey(handlerId)) { Console.WriteLine(string.Format("sceNetApctlDelHandler unknown handlerId=0x{0:X}", handlerId)); return(-1); } SceUidManager.releaseUid(handlerId, uidPurpose); apctlHandlers.Remove(handlerId); 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 sceNpMatching2DestroyContext(int ctxId) { if (dataBuffer != null) { Modules.SysMemUserForUserModule.free(dataBuffer); dataBuffer = null; } if (!SceUidManager.releaseId(ctxId, idContextPurpose)) { return(-1); } return(0); }
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); }
public virtual int sceGeUnsetCallback(int cbid) { ThreadManForUser threadMan = Modules.ThreadManForUserModule; SceKernelCallbackInfo callbackSignal = signalCallbacks.Remove(cbid); SceKernelCallbackInfo callbackFinish = finishCallbacks.Remove(cbid); if (callbackSignal != null) { threadMan.hleKernelDeleteCallback(callbackSignal.Uid); } if (callbackFinish != null) { threadMan.hleKernelDeleteCallback(callbackFinish.Uid); } SceUidManager.releaseId(cbid, geCallbackPurpose); return(0); }
public SceKernelThreadInfo(string name, int entry_addr, int initPriority, int stackSize, int attr, int mpidStack) { if (stackSize < 512) { // 512 byte min. (required for interrupts) stackSize = 512; } else { // 256 byte size alignment. stackSize = (stackSize + 0xFF) & ~0xFF; } if (mpidStack == 0) { mpidStack = SysMemUserForUser.USER_PARTITION_ID; } this.name = name; this.entry_addr = entry_addr; this.initPriority = initPriority; this.stackSize = stackSize; this.attr = attr; uid = SceUidManager.getNewUid("ThreadMan-thread"); // Setup the stack. int stackMemoryType = (attr & PSP_THREAD_ATTR_LOW_MEM_STACK) != 0 ? SysMemUserForUser.PSP_SMEM_Low : SysMemUserForUser.PSP_SMEM_High; stackSysMemInfo = Modules.SysMemUserForUserModule.malloc(mpidStack, string.Format("ThreadMan-Stack-0x{0:x}-{1}", uid, name), stackMemoryType, stackSize, 0); if (stackSysMemInfo == null) { stackAddr = 0; } else { stackAddr = stackSysMemInfo.addr; } // Inherit gpReg. gpReg_addr = Emulator.Processor.cpu._gp; // Inherit context. cpuContext = new CpuState(Emulator.Processor.cpu); wait = new ThreadWaitInfo(); reset(); }
/// <summary> /// do not instantiate unless there is enough free mem. /// use the static helper function tryCreateFpl. /// </summary> private SceKernelFplInfo(string name, int partitionid, int attr, int blockSize, int numBlocks, int memType, int memAlign) { this.name = name; this.attr = attr; this.blockSize = blockSize; this.numBlocks = numBlocks; freeBlocks = numBlocks; uid = SceUidManager.getNewUid("ThreadMan-Fpl"); this.partitionid = partitionid; blockAddress = new int[numBlocks]; blockAllocated = new bool[numBlocks]; for (int i = 0; i < numBlocks; i++) { blockAllocated[i] = false; } // Reserve psp memory int alignedBlockSize = memAlign == 0 ? blockSize : Utilities.alignUp(blockSize, memAlign - 1); int totalFplSize = alignedBlockSize * numBlocks; sysMemInfo = Modules.SysMemUserForUserModule.malloc(partitionid, string.Format("ThreadMan-Fpl-0x{0:x}-{1}", uid, name), memType, totalFplSize, 0); if (sysMemInfo == null) { throw new Exception("SceKernelFplInfo: not enough free mem"); } // Initialise the block addresses for (int i = 0; i < numBlocks; i++) { blockAddress[i] = sysMemInfo.addr + alignedBlockSize * i; } threadWaitingList = ThreadWaitingList.createThreadWaitingList(SceKernelThreadInfo.PSP_WAIT_FPL, uid, attr, FplManager.PSP_FPL_ATTR_PRIORITY); }