aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2021-11-04 20:27:21 -0300
committerGitHub <noreply@github.com>2021-11-04 20:27:21 -0300
commit81e9b86cdb4b2a01cc41b8e8a4dff2c9e3c13843 (patch)
treec3f8a9c5f56b8f994ac6a52cf8265b52b43566cf /Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
parentf78bcb80485419466fde56812425a53e22705765 (diff)
Ensure syncpoints are released and event handles closed on channel close (#2812)
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs70
1 files changed, 48 insertions, 22 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
index f27c065e..46c19c6e 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
@@ -12,11 +12,27 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
private KEvent _smExceptionBptPauseReportEvent;
private KEvent _errorNotifierEvent;
+ private int _smExceptionBptIntReportEventHandle;
+ private int _smExceptionBptPauseReportEventHandle;
+ private int _errorNotifierEventHandle;
+
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner)
{
- _smExceptionBptIntReportEvent = new KEvent(context.Device.System.KernelContext);
- _smExceptionBptPauseReportEvent = new KEvent(context.Device.System.KernelContext);
- _errorNotifierEvent = new KEvent(context.Device.System.KernelContext);
+ _smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle);
+ _smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle);
+ _errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle);
+ }
+
+ private static KEvent CreateEvent(ServiceCtx context, out int handle)
+ {
+ KEvent evnt = new KEvent(context.Device.System.KernelContext);
+
+ if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != KernelResult.Success)
+ {
+ throw new InvalidOperationException("Out of handles!");
+ }
+
+ return evnt;
}
public override NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
@@ -39,41 +55,51 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
{
// TODO: accurately represent and implement those events.
- KEvent targetEvent = null;
-
switch (eventId)
{
case 0x1:
- targetEvent = _smExceptionBptIntReportEvent;
+ eventHandle = _smExceptionBptIntReportEventHandle;
break;
case 0x2:
- targetEvent = _smExceptionBptPauseReportEvent;
+ eventHandle = _smExceptionBptPauseReportEventHandle;
break;
case 0x3:
- targetEvent = _errorNotifierEvent;
+ eventHandle = _errorNotifierEventHandle;
+ break;
+ default:
+ eventHandle = 0;
break;
}
- if (targetEvent != null)
+ return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput;
+ }
+
+ private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
+ {
+ return SubmitGpfifo(ref arguments, inlineData);
+ }
+
+ public override void Close()
+ {
+ if (_smExceptionBptIntReportEventHandle != 0)
{
- if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != KernelResult.Success)
- {
- throw new InvalidOperationException("Out of handles!");
- }
+ Context.Process.HandleTable.CloseHandle(_smExceptionBptIntReportEventHandle);
+ _smExceptionBptIntReportEventHandle = 0;
}
- else
- {
- eventHandle = 0;
- return NvInternalResult.InvalidInput;
+ if (_smExceptionBptPauseReportEventHandle != 0)
+ {
+ Context.Process.HandleTable.CloseHandle(_smExceptionBptPauseReportEventHandle);
+ _smExceptionBptPauseReportEventHandle = 0;
}
- return NvInternalResult.Success;
- }
+ if (_errorNotifierEventHandle != 0)
+ {
+ Context.Process.HandleTable.CloseHandle(_errorNotifierEventHandle);
+ _errorNotifierEventHandle = 0;
+ }
- private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
- {
- return SubmitGpfifo(ref arguments, inlineData);
+ base.Close();
}
}
}