2019-01-18 23:26:39 +01:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 23:15:45 +01:00
|
|
|
using Ryujinx.Horizon.Common;
|
2019-01-18 23:26:39 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
|
|
|
{
|
|
|
|
class KServerSession : KSynchronizationObject
|
|
|
|
{
|
|
|
|
private static readonly MemoryState[] IpcMemoryStates = new MemoryState[]
|
|
|
|
{
|
|
|
|
MemoryState.IpcBuffer3,
|
|
|
|
MemoryState.IpcBuffer0,
|
|
|
|
MemoryState.IpcBuffer1,
|
|
|
|
(MemoryState)0xfffce5d4 //This is invalid, shouldn't be accessed.
|
|
|
|
};
|
|
|
|
|
2022-12-05 14:47:39 +01:00
|
|
|
private readonly struct Message
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
public ulong Address { get; }
|
|
|
|
public ulong Size { get; }
|
|
|
|
public bool IsCustom { get; }
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
public Message(KThread thread, ulong customCmdBuffAddress, ulong customCmdBuffSize)
|
|
|
|
{
|
|
|
|
IsCustom = customCmdBuffAddress != 0;
|
|
|
|
|
|
|
|
if (IsCustom)
|
|
|
|
{
|
|
|
|
Address = customCmdBuffAddress;
|
|
|
|
Size = customCmdBuffSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
Address = thread.TlsAddress;
|
|
|
|
Size = 0x100;
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Message(KSessionRequest request) : this(
|
|
|
|
request.ClientThread,
|
|
|
|
request.CustomCmdBuffAddr,
|
|
|
|
request.CustomCmdBuffSize) { }
|
|
|
|
}
|
|
|
|
|
2022-12-05 14:47:39 +01:00
|
|
|
private readonly struct MessageHeader
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
public uint Word0 { get; }
|
|
|
|
public uint Word1 { get; }
|
|
|
|
public uint Word2 { get; }
|
|
|
|
|
|
|
|
public uint PointerBuffersCount { get; }
|
|
|
|
public uint SendBuffersCount { get; }
|
|
|
|
public uint ReceiveBuffersCount { get; }
|
|
|
|
public uint ExchangeBuffersCount { get; }
|
|
|
|
|
|
|
|
public uint RawDataSizeInWords { get; }
|
|
|
|
|
|
|
|
public uint ReceiveListType { get; }
|
|
|
|
|
|
|
|
public uint MessageSizeInWords { get; }
|
|
|
|
public uint ReceiveListOffsetInWords { get; }
|
|
|
|
public uint ReceiveListOffset { get; }
|
|
|
|
|
|
|
|
public bool HasHandles { get; }
|
|
|
|
|
|
|
|
public bool HasPid { get; }
|
|
|
|
|
|
|
|
public uint CopyHandlesCount { get; }
|
|
|
|
public uint MoveHandlesCount { get; }
|
|
|
|
|
|
|
|
public MessageHeader(uint word0, uint word1, uint word2)
|
|
|
|
{
|
|
|
|
Word0 = word0;
|
|
|
|
Word1 = word1;
|
|
|
|
Word2 = word2;
|
|
|
|
|
|
|
|
HasHandles = word1 >> 31 != 0;
|
|
|
|
|
|
|
|
uint handleDescSizeInWords = 0;
|
|
|
|
|
|
|
|
if (HasHandles)
|
|
|
|
{
|
|
|
|
uint pidSize = (word2 & 1) * 8;
|
|
|
|
|
|
|
|
HasPid = pidSize != 0;
|
|
|
|
|
|
|
|
CopyHandlesCount = (word2 >> 1) & 0xf;
|
|
|
|
MoveHandlesCount = (word2 >> 5) & 0xf;
|
|
|
|
|
|
|
|
handleDescSizeInWords = (pidSize + CopyHandlesCount * 4 + MoveHandlesCount * 4) / 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HasPid = false;
|
|
|
|
|
|
|
|
CopyHandlesCount = 0;
|
|
|
|
MoveHandlesCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerBuffersCount = (word0 >> 16) & 0xf;
|
|
|
|
SendBuffersCount = (word0 >> 20) & 0xf;
|
|
|
|
ReceiveBuffersCount = (word0 >> 24) & 0xf;
|
|
|
|
ExchangeBuffersCount = word0 >> 28;
|
|
|
|
|
|
|
|
uint pointerDescSizeInWords = PointerBuffersCount * 2;
|
|
|
|
uint sendDescSizeInWords = SendBuffersCount * 3;
|
|
|
|
uint receiveDescSizeInWords = ReceiveBuffersCount * 3;
|
|
|
|
uint exchangeDescSizeInWords = ExchangeBuffersCount * 3;
|
|
|
|
|
|
|
|
RawDataSizeInWords = word1 & 0x3ff;
|
|
|
|
|
|
|
|
ReceiveListType = (word1 >> 10) & 0xf;
|
|
|
|
|
|
|
|
ReceiveListOffsetInWords = (word1 >> 20) & 0x7ff;
|
|
|
|
|
|
|
|
uint paddingSizeInWords = HasHandles ? 3u : 2u;
|
|
|
|
|
|
|
|
MessageSizeInWords = pointerDescSizeInWords +
|
|
|
|
sendDescSizeInWords +
|
|
|
|
receiveDescSizeInWords +
|
|
|
|
exchangeDescSizeInWords +
|
|
|
|
RawDataSizeInWords +
|
|
|
|
paddingSizeInWords +
|
|
|
|
handleDescSizeInWords;
|
|
|
|
|
|
|
|
if (ReceiveListOffsetInWords == 0)
|
|
|
|
{
|
|
|
|
ReceiveListOffsetInWords = MessageSizeInWords;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReceiveListOffset = ReceiveListOffsetInWords * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct PointerBufferDesc
|
|
|
|
{
|
|
|
|
public uint ReceiveIndex { get; }
|
|
|
|
|
|
|
|
public uint BufferSize { get; }
|
|
|
|
public ulong BufferAddress { get; set; }
|
|
|
|
|
|
|
|
public PointerBufferDesc(ulong dword)
|
|
|
|
{
|
|
|
|
ReceiveIndex = (uint)dword & 0xf;
|
|
|
|
BufferSize = (uint)dword >> 16;
|
|
|
|
|
|
|
|
BufferAddress = (dword >> 2) & 0x70;
|
|
|
|
BufferAddress |= (dword >> 12) & 0xf;
|
|
|
|
|
|
|
|
BufferAddress = (BufferAddress << 32) | (dword >> 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ulong Pack()
|
|
|
|
{
|
|
|
|
ulong dword = (ReceiveIndex & 0xf) | ((BufferSize & 0xffff) << 16);
|
|
|
|
|
|
|
|
dword |= BufferAddress << 32;
|
|
|
|
dword |= (BufferAddress >> 20) & 0xf000;
|
|
|
|
dword |= (BufferAddress >> 30) & 0xffc0;
|
|
|
|
|
|
|
|
return dword;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private KSession _parent;
|
|
|
|
|
|
|
|
private LinkedList<KSessionRequest> _requests;
|
|
|
|
|
|
|
|
private KSessionRequest _activeRequest;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
public KServerSession(KernelContext context, KSession parent) : base(context)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
_parent = parent;
|
|
|
|
|
|
|
|
_requests = new LinkedList<KSessionRequest>();
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
public Result EnqueueRequest(KSessionRequest request)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
if (_parent.ClientSession.State != ChannelState.Open)
|
|
|
|
{
|
|
|
|
return KernelResult.PortRemoteClosed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request.AsyncEvent == null)
|
|
|
|
{
|
|
|
|
if (request.ClientThread.ShallBeTerminated ||
|
|
|
|
request.ClientThread.SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
return KernelResult.ThreadTerminating;
|
|
|
|
}
|
|
|
|
|
|
|
|
request.ClientThread.Reschedule(ThreadSchedState.Paused);
|
|
|
|
}
|
|
|
|
|
|
|
|
_requests.AddLast(request);
|
|
|
|
|
|
|
|
if (_requests.Count == 1)
|
|
|
|
{
|
|
|
|
Signal();
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
return Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
public Result Receive(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2020-12-09 23:20:05 +01:00
|
|
|
KThread serverThread = KernelStatic.GetCurrentThread();
|
2019-01-18 23:26:39 +01:00
|
|
|
KProcess serverProcess = serverThread.Owner;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (_parent.ClientSession.State != ChannelState.Open)
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return KernelResult.PortRemoteClosed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_activeRequest != null || !DequeueRequest(out KSessionRequest request))
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return KernelResult.NotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request.ClientThread == null)
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return KernelResult.PortRemoteClosed;
|
|
|
|
}
|
|
|
|
|
|
|
|
KThread clientThread = request.ClientThread;
|
|
|
|
KProcess clientProcess = clientThread.Owner;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
_activeRequest = request;
|
|
|
|
|
|
|
|
request.ServerProcess = serverProcess;
|
|
|
|
|
|
|
|
Message clientMsg = new Message(request);
|
|
|
|
Message serverMsg = new Message(serverThread, customCmdBuffAddr, customCmdBuffSize);
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg);
|
2019-01-18 23:26:39 +01:00
|
|
|
MessageHeader serverHeader = GetServerMessageHeader(serverMsg);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
Result serverResult = KernelResult.NotFound;
|
|
|
|
Result clientResult = Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
void CleanUpForError()
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
if (request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager) == Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
request.BufferDescriptorTable.RestoreClientBuffers(clientProcess.MemoryManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseAllHandles(serverMsg, clientHeader, serverProcess);
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
_activeRequest = null;
|
|
|
|
|
|
|
|
if (_requests.Count != 0)
|
|
|
|
{
|
|
|
|
Signal();
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
WakeClientThread(request, clientResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clientHeader.ReceiveListType < 2 &&
|
|
|
|
clientHeader.ReceiveListOffset > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
else if (clientHeader.ReceiveListType == 2 &&
|
|
|
|
clientHeader.ReceiveListOffset + 8 > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
else if (clientHeader.ReceiveListType > 2 &&
|
|
|
|
clientHeader.ReceiveListType * 8 - 0x10 + clientHeader.ReceiveListOffset > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clientHeader.ReceiveListOffsetInWords < clientHeader.MessageSizeInWords)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clientHeader.MessageSizeInWords * 4 > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.CmdBufferTooSmall;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong[] receiveList = GetReceiveList(
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
serverProcess,
|
2019-01-18 23:26:39 +01:00
|
|
|
serverMsg,
|
|
|
|
serverHeader.ReceiveListType,
|
|
|
|
serverHeader.ReceiveListOffset);
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + 0, clientHeader.Word0);
|
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + 4, clientHeader.Word1);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
uint offset;
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy handles.
|
2019-01-18 23:26:39 +01:00
|
|
|
if (clientHeader.HasHandles)
|
|
|
|
{
|
|
|
|
if (clientHeader.MoveHandlesCount != 0)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + 8, clientHeader.Word2);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset = 3;
|
|
|
|
|
|
|
|
if (clientHeader.HasPid)
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, clientProcess.Pid);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < clientHeader.CopyHandlesCount; index++)
|
|
|
|
{
|
|
|
|
int newHandle = 0;
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
int handle = clientProcess.CpuMemory.Read<int>(clientMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult == Result.Success && handle != 0)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
clientResult = GetCopyObjectHandle(clientThread, serverProcess, handle, out newHandle);
|
|
|
|
}
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, newHandle);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < clientHeader.MoveHandlesCount; index++)
|
|
|
|
{
|
|
|
|
int newHandle = 0;
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
int handle = clientProcess.CpuMemory.Read<int>(clientMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (handle != 0)
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult == Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
clientResult = GetMoveObjectHandle(clientProcess, serverProcess, handle, out newHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clientProcess.HandleTable.CloseHandle(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, newHandle);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = 2;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy pointer/receive list buffers.
|
2019-01-18 23:26:39 +01:00
|
|
|
uint recvListDstOffset = 0;
|
|
|
|
|
|
|
|
for (int index = 0; index < clientHeader.PointerBuffersCount; index++)
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong pointerDesc = clientProcess.CpuMemory.Read<ulong>(clientMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc);
|
|
|
|
|
|
|
|
if (descriptor.BufferSize != 0)
|
|
|
|
{
|
|
|
|
clientResult = GetReceiveListAddress(
|
|
|
|
descriptor,
|
|
|
|
serverMsg,
|
|
|
|
serverHeader.ReceiveListType,
|
|
|
|
clientHeader.MessageSizeInWords,
|
|
|
|
receiveList,
|
|
|
|
ref recvListDstOffset,
|
|
|
|
out ulong recvListBufferAddress);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
clientResult = clientProcess.MemoryManager.CopyDataToCurrentProcess(
|
|
|
|
recvListBufferAddress,
|
|
|
|
descriptor.BufferSize,
|
|
|
|
descriptor.BufferAddress,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
MemoryState.IsPoolAllocated,
|
2020-12-02 00:23:43 +01:00
|
|
|
KMemoryPermission.Read,
|
2019-01-18 23:26:39 +01:00
|
|
|
MemoryAttribute.Uncached,
|
|
|
|
MemoryAttribute.None);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
descriptor.BufferAddress = recvListBufferAddress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
descriptor.BufferAddress = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, descriptor.Pack());
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy send, receive and exchange buffers.
|
2019-01-18 23:26:39 +01:00
|
|
|
uint totalBuffersCount =
|
|
|
|
clientHeader.SendBuffersCount +
|
|
|
|
clientHeader.ReceiveBuffersCount +
|
|
|
|
clientHeader.ExchangeBuffersCount;
|
|
|
|
|
|
|
|
for (int index = 0; index < totalBuffersCount; index++)
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong clientDescAddress = clientMsg.Address + offset * 4;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
uint descWord0 = clientProcess.CpuMemory.Read<uint>(clientDescAddress + 0);
|
|
|
|
uint descWord1 = clientProcess.CpuMemory.Read<uint>(clientDescAddress + 4);
|
|
|
|
uint descWord2 = clientProcess.CpuMemory.Read<uint>(clientDescAddress + 8);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
bool isSendDesc = index < clientHeader.SendBuffersCount;
|
|
|
|
bool isExchangeDesc = index >= clientHeader.SendBuffersCount + clientHeader.ReceiveBuffersCount;
|
|
|
|
|
|
|
|
bool notReceiveDesc = isSendDesc || isExchangeDesc;
|
|
|
|
bool isReceiveDesc = !notReceiveDesc;
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
KMemoryPermission permission = index >= clientHeader.SendBuffersCount
|
|
|
|
? KMemoryPermission.ReadAndWrite
|
|
|
|
: KMemoryPermission.Read;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
uint sizeHigh4 = (descWord2 >> 24) & 0xf;
|
|
|
|
|
|
|
|
ulong bufferSize = descWord0 | (ulong)sizeHigh4 << 32;
|
|
|
|
|
|
|
|
ulong dstAddress = 0;
|
|
|
|
|
|
|
|
if (bufferSize != 0)
|
|
|
|
{
|
|
|
|
ulong bufferAddress;
|
|
|
|
|
|
|
|
bufferAddress = descWord2 >> 28;
|
|
|
|
bufferAddress |= ((descWord2 >> 2) & 7) << 4;
|
|
|
|
|
|
|
|
bufferAddress = (bufferAddress << 32) | descWord1;
|
|
|
|
|
|
|
|
MemoryState state = IpcMemoryStates[(descWord2 + 1) & 3];
|
|
|
|
|
|
|
|
clientResult = serverProcess.MemoryManager.MapBufferFromClientProcess(
|
|
|
|
bufferSize,
|
|
|
|
bufferAddress,
|
|
|
|
clientProcess.MemoryManager,
|
|
|
|
permission,
|
|
|
|
state,
|
|
|
|
notReceiveDesc,
|
|
|
|
out dstAddress);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSendDesc)
|
|
|
|
{
|
|
|
|
clientResult = request.BufferDescriptorTable.AddSendBuffer(bufferAddress, dstAddress, bufferSize, state);
|
|
|
|
}
|
|
|
|
else if (isReceiveDesc)
|
|
|
|
{
|
|
|
|
clientResult = request.BufferDescriptorTable.AddReceiveBuffer(bufferAddress, dstAddress, bufferSize, state);
|
|
|
|
}
|
|
|
|
else /* if (isExchangeDesc) */
|
|
|
|
{
|
|
|
|
clientResult = request.BufferDescriptorTable.AddExchangeBuffer(bufferAddress, dstAddress, bufferSize, state);
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
descWord1 = (uint)dstAddress;
|
|
|
|
|
|
|
|
descWord2 &= 3;
|
|
|
|
|
|
|
|
descWord2 |= sizeHigh4 << 24;
|
|
|
|
|
|
|
|
descWord2 |= (uint)(dstAddress >> 34) & 0x3ffffffc;
|
|
|
|
descWord2 |= (uint)(dstAddress >> 4) & 0xf0000000;
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
ulong serverDescAddress = serverMsg.Address + offset * 4;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
serverProcess.CpuMemory.Write(serverDescAddress + 0, descWord0);
|
|
|
|
serverProcess.CpuMemory.Write(serverDescAddress + 4, descWord1);
|
|
|
|
serverProcess.CpuMemory.Write(serverDescAddress + 8, descWord2);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 3;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy raw data.
|
2019-01-18 23:26:39 +01:00
|
|
|
if (clientHeader.RawDataSizeInWords != 0)
|
|
|
|
{
|
|
|
|
ulong copySrc = clientMsg.Address + offset * 4;
|
|
|
|
ulong copyDst = serverMsg.Address + offset * 4;
|
|
|
|
|
|
|
|
ulong copySize = clientHeader.RawDataSizeInWords * 4;
|
|
|
|
|
|
|
|
if (serverMsg.IsCustom || clientMsg.IsCustom)
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
KMemoryPermission permission = clientMsg.IsCustom
|
|
|
|
? KMemoryPermission.None
|
|
|
|
: KMemoryPermission.Read;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
clientResult = clientProcess.MemoryManager.CopyDataToCurrentProcess(
|
|
|
|
copyDst,
|
|
|
|
copySize,
|
|
|
|
copySrc,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
permission,
|
|
|
|
MemoryAttribute.Uncached,
|
|
|
|
MemoryAttribute.None);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
return Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
public Result Reply(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2020-12-09 23:20:05 +01:00
|
|
|
KThread serverThread = KernelStatic.GetCurrentThread();
|
2019-01-18 23:26:39 +01:00
|
|
|
KProcess serverProcess = serverThread.Owner;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (_activeRequest == null)
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return KernelResult.InvalidState;
|
|
|
|
}
|
|
|
|
|
|
|
|
KSessionRequest request = _activeRequest;
|
|
|
|
|
|
|
|
_activeRequest = null;
|
|
|
|
|
|
|
|
if (_requests.Count != 0)
|
|
|
|
{
|
|
|
|
Signal();
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
KThread clientThread = request.ClientThread;
|
|
|
|
KProcess clientProcess = clientThread.Owner;
|
|
|
|
|
|
|
|
Message clientMsg = new Message(request);
|
|
|
|
Message serverMsg = new Message(serverThread, customCmdBuffAddr, customCmdBuffSize);
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
MessageHeader clientHeader = GetClientMessageHeader(clientProcess, clientMsg);
|
2019-01-18 23:26:39 +01:00
|
|
|
MessageHeader serverHeader = GetServerMessageHeader(serverMsg);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
Result clientResult = Result.Success;
|
|
|
|
Result serverResult = Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
void CleanUpForError()
|
|
|
|
{
|
|
|
|
CloseAllHandles(clientMsg, serverHeader, clientProcess);
|
|
|
|
|
2020-07-17 06:19:07 +02:00
|
|
|
FinishRequest(request, clientResult);
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clientHeader.ReceiveListType < 2 &&
|
|
|
|
clientHeader.ReceiveListOffset > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
else if (clientHeader.ReceiveListType == 2 &&
|
|
|
|
clientHeader.ReceiveListOffset + 8 > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
else if (clientHeader.ReceiveListType > 2 &&
|
|
|
|
clientHeader.ReceiveListType * 8 - 0x10 + clientHeader.ReceiveListOffset > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clientHeader.ReceiveListOffsetInWords < clientHeader.MessageSizeInWords)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serverHeader.MessageSizeInWords * 4 > clientMsg.Size)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.CmdBufferTooSmall;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serverHeader.SendBuffersCount != 0 ||
|
|
|
|
serverHeader.ReceiveBuffersCount != 0 ||
|
|
|
|
serverHeader.ExchangeBuffersCount != 0)
|
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return KernelResult.InvalidCombination;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Read receive list.
|
2019-01-18 23:26:39 +01:00
|
|
|
ulong[] receiveList = GetReceiveList(
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess,
|
2019-01-18 23:26:39 +01:00
|
|
|
clientMsg,
|
|
|
|
clientHeader.ReceiveListType,
|
|
|
|
clientHeader.ReceiveListOffset);
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy receive and exchange buffers.
|
2019-01-18 23:26:39 +01:00
|
|
|
clientResult = request.BufferDescriptorTable.CopyBuffersToClient(clientProcess.MemoryManager);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy header.
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + 0, serverHeader.Word0);
|
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + 4, serverHeader.Word1);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy handles.
|
2019-01-18 23:26:39 +01:00
|
|
|
uint offset;
|
|
|
|
|
|
|
|
if (serverHeader.HasHandles)
|
|
|
|
{
|
|
|
|
offset = 3;
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + 8, serverHeader.Word2);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (serverHeader.HasPid)
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + offset * 4, serverProcess.Pid);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < serverHeader.CopyHandlesCount; index++)
|
|
|
|
{
|
|
|
|
int newHandle = 0;
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
int handle = serverProcess.CpuMemory.Read<int>(serverMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (handle != 0)
|
|
|
|
{
|
|
|
|
GetCopyObjectHandle(serverThread, clientProcess, handle, out newHandle);
|
|
|
|
}
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + offset * 4, newHandle);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < serverHeader.MoveHandlesCount; index++)
|
|
|
|
{
|
|
|
|
int newHandle = 0;
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
int handle = serverProcess.CpuMemory.Read<int>(serverMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (handle != 0)
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult == Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
clientResult = GetMoveObjectHandle(serverProcess, clientProcess, handle, out newHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
serverProcess.HandleTable.CloseHandle(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(clientMsg.Address + offset * 4, newHandle);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = 2;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy pointer/receive list buffers.
|
2019-01-18 23:26:39 +01:00
|
|
|
uint recvListDstOffset = 0;
|
|
|
|
|
|
|
|
for (int index = 0; index < serverHeader.PointerBuffersCount; index++)
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
ulong pointerDesc = serverProcess.CpuMemory.Read<ulong>(serverMsg.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc);
|
|
|
|
|
2020-07-17 06:19:07 +02:00
|
|
|
ulong recvListBufferAddress = 0;
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
if (descriptor.BufferSize != 0)
|
|
|
|
{
|
|
|
|
clientResult = GetReceiveListAddress(
|
|
|
|
descriptor,
|
|
|
|
clientMsg,
|
|
|
|
clientHeader.ReceiveListType,
|
|
|
|
serverHeader.MessageSizeInWords,
|
|
|
|
receiveList,
|
2020-07-17 06:19:07 +02:00
|
|
|
ref recvListDstOffset,
|
|
|
|
out recvListBufferAddress);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
clientResult = clientProcess.MemoryManager.CopyDataFromCurrentProcess(
|
|
|
|
recvListBufferAddress,
|
|
|
|
descriptor.BufferSize,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
MemoryState.IsPoolAllocated,
|
2020-12-02 00:23:43 +01:00
|
|
|
KMemoryPermission.Read,
|
2019-01-18 23:26:39 +01:00
|
|
|
MemoryAttribute.Uncached,
|
|
|
|
MemoryAttribute.None,
|
|
|
|
descriptor.BufferAddress);
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (clientResult != Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
CleanUpForError();
|
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong dstDescAddress = clientMsg.Address + offset * 4;
|
2020-07-17 06:19:07 +02:00
|
|
|
|
|
|
|
ulong clientPointerDesc =
|
|
|
|
(recvListBufferAddress << 32) |
|
|
|
|
((recvListBufferAddress >> 20) & 0xf000) |
|
|
|
|
((recvListBufferAddress >> 30) & 0xffc0);
|
|
|
|
|
|
|
|
clientPointerDesc |= pointerDesc & 0xffff000f;
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(dstDescAddress + 0, clientPointerDesc);
|
2020-07-17 06:19:07 +02:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Set send, receive and exchange buffer descriptors to zero.
|
2019-01-18 23:26:39 +01:00
|
|
|
uint totalBuffersCount =
|
|
|
|
serverHeader.SendBuffersCount +
|
|
|
|
serverHeader.ReceiveBuffersCount +
|
|
|
|
serverHeader.ExchangeBuffersCount;
|
|
|
|
|
|
|
|
for (int index = 0; index < totalBuffersCount; index++)
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong dstDescAddress = clientMsg.Address + offset * 4;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(dstDescAddress + 0, 0);
|
|
|
|
clientProcess.CpuMemory.Write(dstDescAddress + 4, 0);
|
|
|
|
clientProcess.CpuMemory.Write(dstDescAddress + 8, 0);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 3;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Copy raw data.
|
2019-01-18 23:26:39 +01:00
|
|
|
if (serverHeader.RawDataSizeInWords != 0)
|
|
|
|
{
|
|
|
|
ulong copyDst = clientMsg.Address + offset * 4;
|
|
|
|
ulong copySrc = serverMsg.Address + offset * 4;
|
|
|
|
|
|
|
|
ulong copySize = serverHeader.RawDataSizeInWords * 4;
|
|
|
|
|
|
|
|
if (serverMsg.IsCustom || clientMsg.IsCustom)
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
KMemoryPermission permission = clientMsg.IsCustom
|
|
|
|
? KMemoryPermission.None
|
|
|
|
: KMemoryPermission.Read;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
clientResult = clientProcess.MemoryManager.CopyDataFromCurrentProcess(
|
|
|
|
copyDst,
|
|
|
|
copySize,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
MemoryState.IsPoolAllocated,
|
|
|
|
permission,
|
|
|
|
MemoryAttribute.Uncached,
|
|
|
|
MemoryAttribute.None,
|
|
|
|
copySrc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write(copyDst, serverProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Unmap buffers from server.
|
2020-07-17 06:19:07 +02:00
|
|
|
FinishRequest(request, clientResult);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return serverResult;
|
|
|
|
}
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
private MessageHeader GetClientMessageHeader(KProcess clientProcess, Message clientMsg)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
uint word0 = clientProcess.CpuMemory.Read<uint>(clientMsg.Address + 0);
|
|
|
|
uint word1 = clientProcess.CpuMemory.Read<uint>(clientMsg.Address + 4);
|
|
|
|
uint word2 = clientProcess.CpuMemory.Read<uint>(clientMsg.Address + 8);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return new MessageHeader(word0, word1, word2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private MessageHeader GetServerMessageHeader(Message serverMsg)
|
|
|
|
{
|
2020-12-09 23:20:05 +01:00
|
|
|
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
uint word0 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 0);
|
|
|
|
uint word1 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 4);
|
|
|
|
uint word2 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 8);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return new MessageHeader(word0, word1, word2);
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private Result GetCopyObjectHandle(KThread srcThread, KProcess dstProcess, int srcHandle, out int dstHandle)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
dstHandle = 0;
|
|
|
|
|
|
|
|
KProcess srcProcess = srcThread.Owner;
|
|
|
|
|
|
|
|
KAutoObject obj;
|
|
|
|
|
|
|
|
if (srcHandle == KHandleTable.SelfProcessHandle)
|
|
|
|
{
|
|
|
|
obj = srcProcess;
|
|
|
|
}
|
|
|
|
else if (srcHandle == KHandleTable.SelfThreadHandle)
|
|
|
|
{
|
|
|
|
obj = srcThread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obj = srcProcess.HandleTable.GetObject<KAutoObject>(srcHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj != null)
|
|
|
|
{
|
|
|
|
return dstProcess.HandleTable.GenerateHandle(obj, out dstHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return KernelResult.InvalidHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private Result GetMoveObjectHandle(KProcess srcProcess, KProcess dstProcess, int srcHandle, out int dstHandle)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
dstHandle = 0;
|
|
|
|
|
|
|
|
KAutoObject obj = srcProcess.HandleTable.GetObject<KAutoObject>(srcHandle);
|
|
|
|
|
|
|
|
if (obj != null)
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
Result result = dstProcess.HandleTable.GenerateHandle(obj, out dstHandle);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
srcProcess.HandleTable.CloseHandle(srcHandle);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return KernelResult.InvalidHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
private ulong[] GetReceiveList(KProcess ownerProcess, Message message, uint recvListType, uint recvListOffset)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
int recvListSize = 0;
|
|
|
|
|
|
|
|
if (recvListType >= 3)
|
|
|
|
{
|
|
|
|
recvListSize = (int)recvListType - 2;
|
|
|
|
}
|
|
|
|
else if (recvListType == 2)
|
|
|
|
{
|
|
|
|
recvListSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong[] receiveList = new ulong[recvListSize];
|
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong recvListAddress = message.Address + recvListOffset;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
for (int index = 0; index < recvListSize; index++)
|
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
receiveList[index] = ownerProcess.CpuMemory.Read<ulong>(recvListAddress + (ulong)index * 8);
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return receiveList;
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private Result GetReceiveListAddress(
|
2019-01-18 23:26:39 +01:00
|
|
|
PointerBufferDesc descriptor,
|
|
|
|
Message message,
|
|
|
|
uint recvListType,
|
|
|
|
uint messageSizeInWords,
|
|
|
|
ulong[] receiveList,
|
|
|
|
ref uint dstOffset,
|
|
|
|
out ulong address)
|
|
|
|
{
|
|
|
|
ulong recvListBufferAddress = address = 0;
|
|
|
|
|
|
|
|
if (recvListType == 0)
|
|
|
|
{
|
|
|
|
return KernelResult.OutOfResource;
|
|
|
|
}
|
|
|
|
else if (recvListType == 1 || recvListType == 2)
|
|
|
|
{
|
|
|
|
ulong recvListBaseAddr;
|
|
|
|
ulong recvListEndAddr;
|
|
|
|
|
|
|
|
if (recvListType == 1)
|
|
|
|
{
|
|
|
|
recvListBaseAddr = message.Address + messageSizeInWords * 4;
|
|
|
|
recvListEndAddr = message.Address + message.Size;
|
|
|
|
}
|
|
|
|
else /* if (recvListType == 2) */
|
|
|
|
{
|
|
|
|
ulong packed = receiveList[0];
|
|
|
|
|
|
|
|
recvListBaseAddr = packed & 0x7fffffffff;
|
|
|
|
|
|
|
|
uint size = (uint)(packed >> 48);
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
return KernelResult.OutOfResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
recvListEndAddr = recvListBaseAddr + size;
|
|
|
|
}
|
|
|
|
|
2022-12-26 15:11:05 +01:00
|
|
|
recvListBufferAddress = BitUtils.AlignUp<ulong>(recvListBaseAddr + dstOffset, 0x10);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
ulong endAddress = recvListBufferAddress + descriptor.BufferSize;
|
|
|
|
|
|
|
|
dstOffset = (uint)endAddress - (uint)recvListBaseAddr;
|
|
|
|
|
|
|
|
if (recvListBufferAddress + descriptor.BufferSize <= recvListBufferAddress ||
|
|
|
|
recvListBufferAddress + descriptor.BufferSize > recvListEndAddr)
|
|
|
|
{
|
|
|
|
return KernelResult.OutOfResource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* if (recvListType > 2) */
|
|
|
|
{
|
|
|
|
if (descriptor.ReceiveIndex >= receiveList.Length)
|
|
|
|
{
|
|
|
|
return KernelResult.OutOfResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong packed = receiveList[descriptor.ReceiveIndex];
|
|
|
|
|
|
|
|
recvListBufferAddress = packed & 0x7fffffffff;
|
|
|
|
|
|
|
|
uint size = (uint)(packed >> 48);
|
|
|
|
|
|
|
|
if (recvListBufferAddress == 0 || size == 0 || size < descriptor.BufferSize)
|
|
|
|
{
|
|
|
|
return KernelResult.OutOfResource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
address = recvListBufferAddress;
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
return Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void CloseAllHandles(Message message, MessageHeader header, KProcess process)
|
|
|
|
{
|
|
|
|
if (header.HasHandles)
|
|
|
|
{
|
|
|
|
uint totalHandeslCount = header.CopyHandlesCount + header.MoveHandlesCount;
|
|
|
|
|
|
|
|
uint offset = 3;
|
|
|
|
|
|
|
|
if (header.HasPid)
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
process.CpuMemory.Write(message.Address + offset * 4, 0L);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < totalHandeslCount; index++)
|
|
|
|
{
|
2020-05-04 00:54:50 +02:00
|
|
|
int handle = process.CpuMemory.Read<int>(message.Address + offset * 4);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (handle != 0)
|
|
|
|
{
|
|
|
|
process.HandleTable.CloseHandle(handle);
|
|
|
|
|
2020-05-04 00:54:50 +02:00
|
|
|
process.CpuMemory.Write(message.Address + offset * 4, 0);
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsSignaled()
|
|
|
|
{
|
|
|
|
if (_parent.ClientSession.State != ChannelState.Open)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _requests.Count != 0 && _activeRequest == null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
_parent.DisconnectServer();
|
|
|
|
|
|
|
|
CancelAllRequestsServerDisconnected();
|
|
|
|
|
|
|
|
_parent.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CancelAllRequestsServerDisconnected()
|
|
|
|
{
|
|
|
|
foreach (KSessionRequest request in IterateWithRemovalOfAllRequests())
|
|
|
|
{
|
2020-07-17 06:19:07 +02:00
|
|
|
FinishRequest(request, KernelResult.PortRemoteClosed);
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CancelAllRequestsClientDisconnected()
|
|
|
|
{
|
|
|
|
foreach (KSessionRequest request in IterateWithRemovalOfAllRequests())
|
|
|
|
{
|
|
|
|
if (request.ClientThread.ShallBeTerminated ||
|
|
|
|
request.ClientThread.SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Client sessions can only be disconnected on async requests (because
|
|
|
|
// the client would be otherwise blocked waiting for the response), so
|
|
|
|
// we only need to handle the async case here.
|
2019-01-18 23:26:39 +01:00
|
|
|
if (request.AsyncEvent != null)
|
|
|
|
{
|
|
|
|
SendResultToAsyncRequestClient(request, KernelResult.PortRemoteClosed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WakeServerThreads(KernelResult.PortRemoteClosed);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<KSessionRequest> IterateWithRemovalOfAllRequests()
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (_activeRequest != null)
|
|
|
|
{
|
|
|
|
KSessionRequest request = _activeRequest;
|
|
|
|
|
|
|
|
_activeRequest = null;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
yield return request;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (DequeueRequest(out KSessionRequest request))
|
|
|
|
{
|
|
|
|
yield return request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool DequeueRequest(out KSessionRequest request)
|
|
|
|
{
|
|
|
|
request = null;
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
bool hasRequest = _requests.First != null;
|
|
|
|
|
|
|
|
if (hasRequest)
|
|
|
|
{
|
|
|
|
request = _requests.First.Value;
|
|
|
|
|
|
|
|
_requests.RemoveFirst();
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
return hasRequest;
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private void FinishRequest(KSessionRequest request, Result result)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
KProcess clientProcess = request.ClientThread.Owner;
|
|
|
|
KProcess serverProcess = request.ServerProcess;
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
Result unmapResult = Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (serverProcess != null)
|
|
|
|
{
|
|
|
|
unmapResult = request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager);
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (unmapResult == Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
request.BufferDescriptorTable.RestoreClientBuffers(clientProcess.MemoryManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
WakeClientThread(request, result);
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private void WakeClientThread(KSessionRequest request, Result result)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Wait client thread waiting for a response for the given request.
|
2019-01-18 23:26:39 +01:00
|
|
|
if (request.AsyncEvent != null)
|
|
|
|
{
|
|
|
|
SendResultToAsyncRequestClient(request, result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
WakeAndSetResult(request.ClientThread, result);
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private void SendResultToAsyncRequestClient(KSessionRequest request, Result result)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
KProcess clientProcess = request.ClientThread.Owner;
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (result != Result.Success)
|
2020-07-17 06:19:07 +02:00
|
|
|
{
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
ulong address = request.CustomCmdBuffAddr;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
POWER - Performance Optimizations With Extensive Ramifications (#2286)
* Refactoring of KMemoryManager class
* Replace some trivial uses of DRAM address with VA
* Get rid of GetDramAddressFromVa
* Abstracting more operations on derived page table class
* Run auto-format on KPageTableBase
* Managed to make TryConvertVaToPa private, few uses remains now
* Implement guest physical pages ref counting, remove manual freeing
* Make DoMmuOperation private and call new abstract methods only from the base class
* Pass pages count rather than size on Map/UnmapMemory
* Change memory managers to take host pointers
* Fix a guest memory leak and simplify KPageTable
* Expose new methods for host range query and mapping
* Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists
* Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking)
* Add a SharedMemoryStorage class, will be useful for host mapping
* Sayonara AddVaRangeToPageList, you served us well
* Start to implement host memory mapping (WIP)
* Support memory tracking through host exception handling
* Fix some access violations from HLE service guest memory access and CPU
* Fix memory tracking
* Fix mapping list bugs, including a race and a error adding mapping ranges
* Simple page table for memory tracking
* Simple "volatile" region handle mode
* Update UBOs directly (experimental, rough)
* Fix the overlap check
* Only set non-modified buffers as volatile
* Fix some memory tracking issues
* Fix possible race in MapBufferFromClientProcess (block list updates were not locked)
* Write uniform update to memory immediately, only defer the buffer set.
* Fix some memory tracking issues
* Pass correct pages count on shared memory unmap
* Armeilleure Signal Handler v1 + Unix changes
Unix currently behaves like windows, rather than remapping physical
* Actually check if the host platform is unix
* Fix decommit on linux.
* Implement windows 10 placeholder shared memory, fix a buffer issue.
* Make PTC version something that will never match with master
* Remove testing variable for block count
* Add reference count for memory manager, fix dispose
Can still deadlock with OpenAL
* Add address validation, use page table for mapped check, add docs
Might clean up the page table traversing routines.
* Implement batched mapping/tracking.
* Move documentation, fix tests.
* Cleanup uniform buffer update stuff.
* Remove unnecessary assignment.
* Add unsafe host mapped memory switch
On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work.
* Remove C# exception handlers
They have issues due to current .NET limitations, so the meilleure one fully replaces them for now.
* Fix MapPhysicalMemory on the software MemoryManager.
* Null check for GetHostAddress, docs
* Add configuration for setting memory manager mode (not in UI yet)
* Add config to UI
* Fix type mismatch on Unix signal handler code emit
* Fix 6GB DRAM mode.
The size can be greater than `uint.MaxValue` when the DRAM is >4GB.
* Address some feedback.
* More detailed error if backing memory cannot be mapped.
* SetLastError on all OS functions for consistency
* Force pages dirty with UBO update instead of setting them directly.
Seems to be much faster across a few games. Need retesting.
* Rebase, configuration rework, fix mem tracking regression
* Fix race in FreePages
* Set memory managers null after decrementing ref count
* Remove readonly keyword, as this is now modified.
* Use a local variable for the signal handler rather than a register.
* Fix bug with buffer resize, and index/uniform buffer binding.
Should fix flickering in games.
* Add InvalidAccessHandler to MemoryTracking
Doesn't do anything yet
* Call invalid access handler on unmapped read/write.
Same rules as the regular memory manager.
* Make unsafe mapped memory its own MemoryManagerType
* Move FlushUboDirty into UpdateState.
* Buffer dirty cache, rather than ubo cache
Much cleaner, may be reusable for Inline2Memory updates.
* This doesn't return anything anymore.
* Add sigaction remove methods, correct a few function signatures.
* Return empty list of physical regions for size 0.
* Also on AddressSpaceManager
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-24 22:52:44 +02:00
|
|
|
clientProcess.CpuMemory.Write<ulong>(address, 0);
|
2023-01-04 23:15:45 +01:00
|
|
|
clientProcess.CpuMemory.Write(address + 8, result.ErrorCode);
|
2020-07-17 06:19:07 +02:00
|
|
|
}
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2020-07-17 06:19:07 +02:00
|
|
|
clientProcess.MemoryManager.UnborrowIpcBuffer(request.CustomCmdBuffAddr, request.CustomCmdBuffSize);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
request.AsyncEvent.Signal();
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private void WakeServerThreads(Result result)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Wake all server threads waiting for requests.
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
foreach (KThread thread in WaitingThreads)
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
WakeAndSetResult(thread, result, this);
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
private void WakeAndSetResult(KThread thread, Result result, KSynchronizationObject signaledObj = null)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
if ((thread.SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused)
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
thread.SignaledObj = signaledObj;
|
2019-01-18 23:26:39 +01:00
|
|
|
thread.ObjSyncResult = result;
|
|
|
|
|
|
|
|
thread.Reschedule(ThreadSchedState.Running);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|