2018-02-04 15:08:20 -08:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
using ChocolArm64.State;
|
2018-02-20 12:09:23 -08:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-02-20 12:09:23 -08:00
|
|
|
namespace Ryujinx.Core.OsHle.Svc
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcSetHeapSize(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
uint Size = (uint)ThreadState.X1;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
Memory.Manager.SetHeapSize(Size, (int)MemoryType.Heap);
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
|
|
|
ThreadState.X1 = (ulong)Memory.Manager.HeapAddr;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcSetMemoryAttribute(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
long Position = (long)ThreadState.X0;
|
|
|
|
long Size = (long)ThreadState.X1;
|
|
|
|
int State0 = (int)ThreadState.X2;
|
|
|
|
int State1 = (int)ThreadState.X3;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-02-25 17:53:01 -08: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-04 15:08:20 -08:00
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcMapMemory(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
long Dst = (long)ThreadState.X0;
|
|
|
|
long Src = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
Memory.Manager.MapMirror(Src, Dst, Size, (int)MemoryType.MappedMemory);
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcQueryMemory(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
long InfoPtr = (long)ThreadState.X0;
|
|
|
|
long Position = (long)ThreadState.X2;
|
2018-02-04 15:08:20 -08: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 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
|
|
|
ThreadState.X1 = 0;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcMapSharedMemory(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
int Handle = (int)ThreadState.X0;
|
|
|
|
long Src = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
|
|
|
int Perm = (int)ThreadState.X3;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-02-17 13:36:08 -08:00
|
|
|
HSharedMem SharedMem = Ns.Os.Handles.GetData<HSharedMem>(Handle);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-02-17 13:36:08 -08:00
|
|
|
if (SharedMem != null)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-17 13:36:08 -08:00
|
|
|
SharedMem.AddVirtualPosition(Src);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-02-17 13:36:08 -08:00
|
|
|
Memory.Manager.MapPhys(Src, Size, (int)MemoryType.SharedMemory, (AMemoryPerm)Perm);
|
2018-02-09 16:13:18 -08:00
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Error codes.
|
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcUnmapSharedMemory(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
int Handle = (int)ThreadState.X0;
|
|
|
|
long Position = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
HSharedMem HndData = Ns.Os.Handles.GetData<HSharedMem>(Handle);
|
|
|
|
|
|
|
|
if (HndData != null)
|
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Error codes.
|
|
|
|
}
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
private void SvcCreateTransferMemory(AThreadState ThreadState)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-02-18 11:28:07 -08:00
|
|
|
long Position = (long)ThreadState.X1;
|
|
|
|
long Size = (long)ThreadState.X2;
|
|
|
|
int Perm = (int)ThreadState.X3;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
AMemoryMapInfo MapInfo = Memory.Manager.GetMapInfo(Position);
|
|
|
|
|
|
|
|
Memory.Manager.Reprotect(Position, Size, (AMemoryPerm)Perm);
|
|
|
|
|
2018-02-07 08:44:48 -08:00
|
|
|
HTransferMem HndData = new HTransferMem(Memory, MapInfo.Perm, Position, Size);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
int Handle = Ns.Os.Handles.GenerateId(HndData);
|
|
|
|
|
2018-02-18 11:28:07 -08:00
|
|
|
ThreadState.X1 = (ulong)Handle;
|
|
|
|
ThreadState.X0 = (int)SvcResult.Success;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|