1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-14 08:26:40 +00:00
Ryujinx/Ryujinx.Core/OsHle/Svc/SvcMemory.cs

173 lines
5.2 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
using static Ryujinx.Core.OsHle.ErrorCode;
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
long Position = MemoryRegions.HeapRegionAddress;
if (Size > CurrentHeapSize)
{
Memory.Manager.Map(Position, Size, (int)MemoryType.Heap, AMemoryPerm.RW);
}
else
{
Memory.Manager.Unmap(Position + Size, (long)CurrentHeapSize - Size);
}
CurrentHeapSize = Size;
2018-02-04 23:08:20 +00:00
ThreadState.X0 = 0;
ThreadState.X1 = (ulong)Position;
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
2018-02-26 01:53:01 +00: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 23:08:20 +00:00
ThreadState.X0 = 0;
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
AMemoryMapInfo SrcInfo = Memory.Manager.GetMapInfo(Src);
Memory.Manager.Map(Dst, Size, (int)MemoryType.MappedMemory, SrcInfo.Perm);
Memory.Manager.Reprotect(Src, Size, AMemoryPerm.None);
Memory.Manager.SetAttrBit(Src, Size, 0);
ThreadState.X0 = 0;
}
private void SvcUnmapMemory(AThreadState ThreadState)
{
long Dst = (long)ThreadState.X0;
long Src = (long)ThreadState.X1;
long Size = (long)ThreadState.X2;
AMemoryMapInfo DstInfo = Memory.Manager.GetMapInfo(Dst);
Memory.Manager.Unmap(Dst, Size, (int)MemoryType.MappedMemory);
Memory.Manager.Reprotect(Src, Size, DstInfo.Perm);
Memory.Manager.ClearAttrBit(Src, Size, 0);
2018-02-04 23:08:20 +00:00
ThreadState.X0 = 0;
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
Position &= uint.MaxValue;
2018-02-04 23:08:20 +00:00
AMemoryMapInfo MapInfo = Memory.Manager.GetMapInfo(Position);
if (MapInfo == null)
{
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidMemRange);
2018-02-04 23:08:20 +00:00
return;
}
2018-02-04 23:08:20 +00:00
Memory.WriteInt64(InfoPtr + 0x00, MapInfo.Position);
Memory.WriteInt64(InfoPtr + 0x08, MapInfo.Size);
Memory.WriteInt32(InfoPtr + 0x10, MapInfo.Type);
Memory.WriteInt32(InfoPtr + 0x14, MapInfo.Attr);
Memory.WriteInt32(InfoPtr + 0x18, (int)MapInfo.Perm);
Memory.WriteInt32(InfoPtr + 0x1c, 0);
Memory.WriteInt32(InfoPtr + 0x20, 0);
Memory.WriteInt32(InfoPtr + 0x24, 0);
2018-02-04 23:08:20 +00:00
//TODO: X1.
ThreadState.X0 = 0;
2018-02-18 19:28:07 +00:00
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
{
AMemoryHelper.FillWithZeros(Memory, Src, (int)Size);
SharedMem.AddVirtualPosition(Src);
2018-02-04 23:08:20 +00:00
Memory.Manager.Map(Src, Size, (int)MemoryType.SharedMemory, (AMemoryPerm)Perm);
2018-02-10 00:13:18 +00:00
ThreadState.X0 = 0;
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)
{
ThreadState.X0 = 0;
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 = 0;
2018-02-04 23:08:20 +00:00
}
}
}