From 6b2e84712bc9379acba13984df09acb67d5195a6 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 31 Jul 2022 13:46:13 +0100 Subject: [PATCH] Avoid race in nvdrv debug prints Looking up the device name without locking it could race with map insertions or deletions, so lock it to avoid that --- app/src/main/cpp/skyline/services/nvdrv/driver.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp index 0ef73e56..c4448dbe 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp @@ -84,10 +84,9 @@ namespace skyline::service::nvdrv { } NvResult Driver::Ioctl(FileDescriptor fd, IoctlDescriptor cmd, span buffer) { - Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); - try { std::shared_lock lock(deviceMutex); + Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); return ConvertResult(devices.at(fd)->Ioctl(cmd, buffer)); } catch (const std::out_of_range &) { throw exception("Ioctl was called with invalid fd: {}", fd); @@ -95,10 +94,9 @@ namespace skyline::service::nvdrv { } NvResult Driver::Ioctl2(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { - Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); - try { std::shared_lock lock(deviceMutex); + Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); return ConvertResult(devices.at(fd)->Ioctl2(cmd, buffer, inlineBuffer)); } catch (const std::out_of_range &) { throw exception("Ioctl2 was called with invalid fd: {}", fd); @@ -106,10 +104,9 @@ namespace skyline::service::nvdrv { } NvResult Driver::Ioctl3(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { - Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); - try { std::shared_lock lock(deviceMutex); + Logger::Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); return ConvertResult(devices.at(fd)->Ioctl3(cmd, buffer, inlineBuffer)); } catch (const std::out_of_range &) { throw exception("Ioctl3 was called with invalid fd: {}", fd);