From 13e7b54c6150ee8eeb858a8784f1188e51bae786 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 31 Jul 2022 14:44:50 +0100 Subject: [PATCH] Ensure failed IOCTLs are logged as a warning log --- .../cpp/skyline/services/nvdrv/driver.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp index c4448dbe..9eeb7c83 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp @@ -60,6 +60,23 @@ namespace skyline::service::nvdrv { return NvResult::FileOperationFailed; } + static PosixResult LogIoctlResult(PosixResult result, u32 ioctl) { + switch (result) { + case PosixResult::Success: + case PosixResult::TryAgain: + case PosixResult::Busy: + case PosixResult::TimedOut: + return result; + case PosixResult::NotPermitted: + case PosixResult::InvalidArgument: + case PosixResult::InappropriateIoctlForDevice: + case PosixResult::NotSupported: + default: + Logger::Warn("IOCTL {} failed: {}", ioctl, static_cast(result)); + return result; + } + } + static NvResult ConvertResult(PosixResult result) { switch (result) { case PosixResult::Success: @@ -87,7 +104,7 @@ namespace skyline::service::nvdrv { 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)); + return ConvertResult(LogIoctlResult(devices.at(fd)->Ioctl(cmd, buffer), cmd.raw)); } catch (const std::out_of_range &) { throw exception("Ioctl was called with invalid fd: {}", fd); } @@ -97,7 +114,7 @@ namespace skyline::service::nvdrv { 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)); + return ConvertResult(LogIoctlResult(devices.at(fd)->Ioctl2(cmd, buffer, inlineBuffer), cmd.raw)); } catch (const std::out_of_range &) { throw exception("Ioctl2 was called with invalid fd: {}", fd); } @@ -107,7 +124,7 @@ namespace skyline::service::nvdrv { 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)); + return ConvertResult(LogIoctlResult(devices.at(fd)->Ioctl3(cmd, buffer, inlineBuffer), cmd.raw)); } catch (const std::out_of_range &) { throw exception("Ioctl3 was called with invalid fd: {}", fd); }