1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00

Make sure to not leak copy handles passed in request (#1772)

* Make sure to not leak copy handles passed in request

Following last gdkchan's PR this make sure to close copy handles that
are passed by guest when it should.

* fix comment copy pasta
This commit is contained in:
Mary 2020-12-03 19:19:10 +01:00 committed by GitHub
parent 1b053d2222
commit 0ab1c42eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 15 deletions

View file

@ -1,6 +1,7 @@
using Ryujinx.Audio;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using System;
@ -10,18 +11,20 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
{
class IAudioOut : IpcService, IDisposable
{
private readonly IAalOutput _audioOut;
private readonly KEvent _releaseEvent;
private int _releaseEventHandle;
private readonly int _track;
private readonly int _clientHandle;
private readonly KernelContext _kernelContext;
private readonly IAalOutput _audioOut;
private readonly KEvent _releaseEvent;
private int _releaseEventHandle;
private readonly int _track;
private readonly int _clientHandle;
public IAudioOut(IAalOutput audioOut, KEvent releaseEvent, int track, int clientHandle)
public IAudioOut(KernelContext kernelContext, IAalOutput audioOut, KEvent releaseEvent, int track, int clientHandle)
{
_audioOut = audioOut;
_releaseEvent = releaseEvent;
_track = track;
_clientHandle = clientHandle;
_kernelContext = kernelContext;
_audioOut = audioOut;
_releaseEvent = releaseEvent;
_track = track;
_clientHandle = clientHandle;
}
[Command(0)]
@ -217,6 +220,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
{
if (disposing)
{
_kernelContext.Syscall.CloseHandle(_clientHandle);
_audioOut.CloseTrack(_track);
}
}

View file

@ -134,7 +134,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio
int track = audioOut.OpenTrack(sampleRate, channels, callback);
MakeObject(context, new IAudioOut(audioOut, releaseEvent, track, context.Request.HandleDesc.ToCopy[0]));
MakeObject(context, new IAudioOut(context.Device.System.KernelContext, audioOut, releaseEvent, track, context.Request.HandleDesc.ToCopy[0]));
context.ResponseData.Write(sampleRate);
context.ResponseData.Write(channels);

View file

@ -329,6 +329,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv
context.ResponseData.Write((uint)NvResult.Success);
// Close transfer memory immediately as we don't use it.
context.Device.System.KernelContext.Syscall.CloseHandle(transferMemHandle);
return ResultCode.Success;
}
@ -384,9 +387,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
if (errorCode == NvResult.Success)
{
KSharedMemory sharedMemory = context.Process.HandleTable.GetObject<KSharedMemory>(sharedMemoryHandle);
errorCode = ConvertInternalErrorCode(deviceFile.MapSharedMemory(sharedMemory, argument));
errorCode = ConvertInternalErrorCode(deviceFile.MapSharedMemory(sharedMemoryHandle, argument));
}
}

View file

@ -28,8 +28,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices
return NvInternalResult.NotImplemented;
}
public virtual NvInternalResult MapSharedMemory(KSharedMemory sharedMemory, uint argument)
public virtual NvInternalResult MapSharedMemory(int sharedMemoryHandle, uint argument)
{
// Close shared memory immediately as we don't use it.
Context.Device.System.KernelContext.Syscall.CloseHandle(sharedMemoryHandle);
return NvInternalResult.NotImplemented;
}