public int sceKernelAllocPartitionMemory(MemoryPartitions PartitionId, string Name, HleMemoryManager.BlockTypeEnum Type, int Size, /* void* */uint Address) { if ((int)PartitionId <= 0 || (int)PartitionId == 7 || (int)PartitionId >= 10) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_ARGUMENT)); if (Size <= 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK)); //Console.Error.WriteLineColored(ConsoleColor.Yellow, "sceKernelAllocPartitionMemory: {0}, {1}, {2}, {3}, {4}", PartitionId, MemoryManager.GetPartition(PartitionId).MaxFreeSize, Name, Type, Size); if (Name == null) throw (new SceKernelException(SceKernelErrors.ERROR_ERROR)); MemoryPartition MemoryPartition; int Alignment = 1; switch (Type) { case HleMemoryManager.BlockTypeEnum.HighAligned: case HleMemoryManager.BlockTypeEnum.LowAligned: Alignment = (int)Address; break; } if ((Alignment == 0) || !MathUtils.IsPowerOfTwo((uint)Alignment)) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_ALIGNMENT_SIZE)); } try { switch (Type) { case HleMemoryManager.BlockTypeEnum.Low: case HleMemoryManager.BlockTypeEnum.LowAligned: MemoryPartition = MemoryManager.GetPartition(PartitionId).Allocate(Size, MemoryPartition.Anchor.Low, Alignment: Alignment, Name: Name ); break; case HleMemoryManager.BlockTypeEnum.High: case HleMemoryManager.BlockTypeEnum.HighAligned: MemoryPartition = MemoryManager.GetPartition(PartitionId).Allocate(Size, MemoryPartition.Anchor.High, Alignment: Alignment, Name: Name); break; case HleMemoryManager.BlockTypeEnum.Address: if (Address == 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK)); MemoryPartition = MemoryManager.GetPartition(PartitionId).Allocate(Size, MemoryPartition.Anchor.Low, Position: Address, Alignment: Alignment, Name: Name); break; default: Console.Error.WriteLineColored(ConsoleColor.Red, "Not Implemented sceKernelAllocPartitionMemory with Type='" + Type + "'"); throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE)); } } catch (MemoryPartitionNoMemoryException MemoryPartitionNoMemoryException) { //Console.Error.WriteLine(InvalidOperationException); Console.Error.WriteLine(MemoryPartitionNoMemoryException); throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_NO_MEMORY)); } //Console.Error.WriteLineColored(ConsoleColor.Cyan, " sceKernelAllocPartitionMemory: {0}", MemoryPartition); return (int)MemoryManager.MemoryPartitionsUid.Create(MemoryPartition); //return MemoryPartition; }
public PoolId sceKernelCreateFpl(string Name, HleMemoryManager.Partitions PartitionId, int Attributes, int BlockSize, int NumberOfBlocks, void* Options) { if (Options != null) throw(new NotImplementedException()); var FixedPool = new FixedPool() { MemoryManager = HleState.MemoryManager, Name = Name, PartitionId = PartitionId, Attributes = Attributes, BlockSize = BlockSize, NumberOfBlocks = NumberOfBlocks, }; FixedPool.Init(); return FixedPoolList.Create(FixedPool); }
public int sceKernelAllocPartitionMemory(HleMemoryManager.Partitions PartitionId, string Name, HleMemoryManager.BlockTypeEnum Type, int Size, /* void* */uint Address) { MemoryPartition MemoryPartition; int Alignment = 1; switch (Type) { case HleMemoryManager.BlockTypeEnum.HighAligned: case HleMemoryManager.BlockTypeEnum.LowAligned: Alignment = (int)Address; break; } if (Type == HleMemoryManager.BlockTypeEnum.Low || Type == HleMemoryManager.BlockTypeEnum.LowAligned) { try { MemoryPartition = MemoryManager.GetPartition(PartitionId).Allocate( Size, MemoryPartition.Anchor.Low, Alignment: Alignment, Name: Name ); } catch (InvalidOperationException InvalidOperationException) { //Console.Error.WriteLine(InvalidOperationException); Console.Error.WriteLine(InvalidOperationException.Message); throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_NO_MEMORY)); } } else { //throw (new NotImplementedException()); Console.WriteLine("Not Implemented sceKernelAllocPartitionMemory with Type='" + Type + "'"); throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE)); //return SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE; } return (int)MemoryManager.MemoryPartitionsUid.Create(MemoryPartition); /* throw(new NotImplementedException()); const uint ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE = 0x800200d8; const uint ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK = 0x800200d9; try { MemorySegment memorySegment; Logger.log(Logger.Level.INFO, "SysMemUserForUser", "sceKernelAllocPartitionMemory(%d:'%s':%s:%d,0x%08X)", PartitionId, Name, std.conv.to!string(Type), Size, Address); //Logger.log(Logger.Level.INFO, "SysMemUserForUser", "sceKernelAllocPartitionMemory(%d:'%s':%d:%d)", partitionid, name, (type), size); int alignment = 1; if ((Type == PspSysMemBlockTypes.PSP_SMEM_Low_Aligned) || (Type == PspSysMemBlockTypes.PSP_SMEM_High_Aligned)) { alignment = Address; } switch (Type) { default: return ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE; case PspSysMemBlockTypes.PSP_SMEM_Low_Aligned: case PspSysMemBlockTypes.PSP_SMEM_Low : memorySegment = pspMemorySegment[PartitionId].allocByLow (Size, dupStr(Name), 0, alignment); break; case PspSysMemBlockTypes.PSP_SMEM_High_Aligned: case PspSysMemBlockTypes.PSP_SMEM_High: memorySegment = pspMemorySegment[PartitionId].allocByHigh(Size, dupStr(Name), alignment); break; case PspSysMemBlockTypes.PSP_SMEM_Addr: memorySegment = pspMemorySegment[PartitionId].allocByAddr(Address, Size, dupStr(Name)); break; } if (memorySegment is null) return ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK; SceUID sceUid = uniqueIdFactory.add(memorySegment); Logger.log(Logger.Level.INFO, "SysMemUserForUser", "sceKernelAllocPartitionMemory(%d:'%s':%s:%d) :: (%d) -> %s", PartitionId, Name, std.conv.to!string(Type), Size, sceUid, memorySegment.block); //Logger.log(Logger.Level.INFO, "SysMemUserForUser", "sceKernelAllocPartitionMemory(%d:'%s':%d:%d) :: (%d) -> %s", partitionid, name, (type), size, sceUid, memorySegment.block); return sceUid; } catch (Exception Exception) { //logError("ERROR: %s", o); return ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK; } */ }
public MsgPipeId sceKernelCreateMsgPipe(string Name, HleMemoryManager.Partitions PartitionId, MsgPipeAttributes Attributes, int Size, void* Options) { if (Options != null) throw(new NotImplementedException()); var MsgPipe = new MsgPipe() { Name = Name, PartitionId = PartitionId, Size = Size, Attributes = Attributes, }; MsgPipe.Init(ThreadManager, MemoryManager.Memory, MemoryManager); return MessagePipeList.Create(MsgPipe); }
public void Init(HleThreadManager ThreadManager, PspMemory PspMemory, HleMemoryManager MemoryManager) { var BlockType = Attributes.HasFlag(MsgPipeAttributes.UseHighAddress) ? MemoryPartition.Anchor.High : MemoryPartition.Anchor.Low ; this.ThreadManager = ThreadManager; this.PspMemory = PspMemory; this.PoolPartition = MemoryManager.GetPartition(PartitionId).Allocate( Size, BlockType, Alignment: 16, Name: "<MsgPipe> : " + Name ); }
public VariablePoolId sceKernelCreateVpl(string Name, HleMemoryManager.Partitions PartitionId, VplAttributeEnum Attribute, int Size, void* Options) { var VariablePool = new VariablePool(this) { PartitionId= PartitionId, Info = new SceKernelVplInfo() { Attribute = Attribute, PoolSize = Size, FreeSize = Size, } }; VariablePool.Init(); var VariablePoolId = VariablePoolList.Create(VariablePool); return VariablePoolId; }
public PoolId sceKernelCreateFpl(string Name, HleMemoryManager.Partitions PartitionId, FplAttributes Attributes, int BlockSize, int NumberOfBlocks, FplOptionsStruct* Options) { var FixedPool = new FixedPool(this) { MemoryManager = MemoryManager, Name = Name, PartitionId = PartitionId, Attributes = Attributes, BlockSize = BlockSize, NumberOfBlocks = NumberOfBlocks, }; if (Options != null) FixedPool.Options = *Options; FixedPool.Init(); return FixedPoolList.Create(FixedPool); }
public VariablePoolId sceKernelCreateVpl(string Name, HleMemoryManager.Partitions PartitionId, VplAttribute Attribute, int Size, void* Options) { var VariablePool = new VariablePool() { Info = new SceKernelVplInfo() { Attribute = Attribute, FreeSize = Size, } }; /* if (Attribute.HasFlag(VplAttribute.PSP_VPL_ATTR_ADDR_HIGH)) { HleState.MemoryManager.GetPartition(PartitionId).Allocate(Size) } else { } */ VariablePool.Init(); return VariablePoolList.Create(VariablePool); /* throw(new NotImplementedException()); const PSP_VPL_ATTR_MASK = 0x41FF; // Anything outside this mask is an illegal attr. const PSP_VPL_ATTR_ADDR_HIGH = 0x4000; // Create the vpl in high memory. const PSP_VPL_ATTR_EXT = 0x8000; // Extend the vpl memory area (exact purpose is unknown). //new MemorySegment logWarning("sceKernelCreateVpl('%s', %d, %d, %d)", name, part, attr, size); VariablePool variablePool; if (attr & PSP_VPL_ATTR_ADDR_HIGH) { variablePool = new VariablePool(hleEmulatorState.moduleManager.get!SysMemUserForUser()._allocateMemorySegmentHigh(part, dupStr(name), size)); } else { variablePool = new VariablePool(hleEmulatorState.moduleManager.get!SysMemUserForUser()._allocateMemorySegmentLow(part, dupStr(name), size)); } logWarning("%s", variablePool); return uniqueIdFactory.add(variablePool); */ }