2018-02-05 00:08:20 +01:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
using ChocolArm64.State;
|
2018-02-20 21:09:23 +01:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-20 21:09:23 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Svc
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcSetHeapSize(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
uint Size = (uint)ThreadState.X1;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Memory.Manager.SetHeapSize(Size, (int)MemoryType.Heap);
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
|
|
|
ThreadState.X1 = (ulong)Memory.Manager.HeapAddr;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcSetMemoryAttribute(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
long Position = (long)ThreadState.X0;
|
|
|
|
long Size = (long)ThreadState.X1;
|
|
|
|
int State0 = (int)ThreadState.X2;
|
|
|
|
int State1 = (int)ThreadState.X3;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-26 02:53:01 +01:00
|
|
|
if ((State0 == 0 && State1 == 0) ||
|
|
|
|
(State0 == 8 && State1 == 0))
|
|
|
|
{
|
|
|
|
Memory.Manager.ClearAttrBit(Position, Size, 3);
|
|
|
|
}
|
|
|
|
else if (State0 == 8 && State1 == 8)
|
|
|
|
{
|
|
|
|
Memory.Manager.SetAttrBit(Position, Size, 3);
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcMapMemory(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
long Dst = (long)ThreadState.X0;
|
|
|
|
long Src = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Memory.Manager.MapMirror(Src, Dst, Size, (int)MemoryType.MappedMemory);
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcQueryMemory(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
long InfoPtr = (long)ThreadState.X0;
|
|
|
|
long Position = (long)ThreadState.X2;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
AMemoryMapInfo MapInfo = Memory.Manager.GetMapInfo(Position);
|
|
|
|
|
|
|
|
MemoryInfo Info = new MemoryInfo(MapInfo);
|
|
|
|
|
|
|
|
Memory.WriteInt64(InfoPtr + 0x00, Info.BaseAddress);
|
|
|
|
Memory.WriteInt64(InfoPtr + 0x08, Info.Size);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x10, Info.MemType);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x14, Info.MemAttr);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x18, Info.MemPerm);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x1c, Info.IpcRefCount);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x20, Info.DeviceRefCount);
|
|
|
|
Memory.WriteInt32(InfoPtr + 0x24, Info.Padding);
|
|
|
|
|
|
|
|
//TODO: X1.
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
|
|
|
ThreadState.X1 = 0;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcMapSharedMemory(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
int Handle = (int)ThreadState.X0;
|
|
|
|
long Src = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
|
|
|
int Perm = (int)ThreadState.X3;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-17 22:36:08 +01:00
|
|
|
HSharedMem SharedMem = Ns.Os.Handles.GetData<HSharedMem>(Handle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-17 22:36:08 +01:00
|
|
|
if (SharedMem != null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-17 22:36:08 +01:00
|
|
|
SharedMem.AddVirtualPosition(Src);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-17 22:36:08 +01:00
|
|
|
Memory.Manager.MapPhys(Src, Size, (int)MemoryType.SharedMemory, (AMemoryPerm)Perm);
|
2018-02-10 01:13:18 +01:00
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Error codes.
|
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcUnmapSharedMemory(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
int Handle = (int)ThreadState.X0;
|
|
|
|
long Position = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
HSharedMem HndData = Ns.Os.Handles.GetData<HSharedMem>(Handle);
|
|
|
|
|
|
|
|
if (HndData != null)
|
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Error codes.
|
|
|
|
}
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
private void SvcCreateTransferMemory(AThreadState ThreadState)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 20:28:07 +01:00
|
|
|
long Position = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
|
|
|
int Perm = (int)ThreadState.X3;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
AMemoryMapInfo MapInfo = Memory.Manager.GetMapInfo(Position);
|
|
|
|
|
|
|
|
Memory.Manager.Reprotect(Position, Size, (AMemoryPerm)Perm);
|
|
|
|
|
2018-02-07 17:44:48 +01:00
|
|
|
HTransferMem HndData = new HTransferMem(Memory, MapInfo.Perm, Position, Size);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
int Handle = Ns.Os.Handles.GenerateId(HndData);
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
ThreadState.X1 = (ulong)Handle;
|
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|