0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Core/OsHle/Svc/SvcMemory.cs

121 lines
3.8 KiB
C#
Raw Normal View History

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