From 79a043e5bf82757a5587c1c7ffe8ac48de34b84c Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:54:24 +0200 Subject: [PATCH] Fixes #1889 --- LibreHardwareMonitorLib/Hardware/Mutexes.cs | 12 +++++++++++- .../LibreHardwareMonitorLib.csproj | 1 + LibreHardwareMonitorLib/PawnIo/RyzenSmu.cs | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/LibreHardwareMonitorLib/Hardware/Mutexes.cs b/LibreHardwareMonitorLib/Hardware/Mutexes.cs index ec42e16..b1de10e 100644 --- a/LibreHardwareMonitorLib/Hardware/Mutexes.cs +++ b/LibreHardwareMonitorLib/Hardware/Mutexes.cs @@ -1,4 +1,6 @@ using System; +using System.Security.AccessControl; +using System.Security.Principal; using System.Threading; namespace LibreHardwareMonitor.Hardware; @@ -24,7 +26,15 @@ internal static class Mutexes { try { - return new Mutex(false, name); + var worldRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); + var mutexSecurity = new MutexSecurity(); + mutexSecurity.AddAccessRule(worldRule); + +#if NETFRAMEWORK + return new Mutex(false, name, out _, mutexSecurity); +#else + return MutexAcl.Create(false, name, out _, mutexSecurity); +#endif } catch (UnauthorizedAccessException) { diff --git a/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj b/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj index b342bb1..a7e3301 100644 --- a/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj +++ b/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj @@ -50,6 +50,7 @@ + diff --git a/LibreHardwareMonitorLib/PawnIo/RyzenSmu.cs b/LibreHardwareMonitorLib/PawnIo/RyzenSmu.cs index 57674ea..6ca834c 100644 --- a/LibreHardwareMonitorLib/PawnIo/RyzenSmu.cs +++ b/LibreHardwareMonitorLib/PawnIo/RyzenSmu.cs @@ -13,6 +13,7 @@ public class RyzenSmu throw new TimeoutException("Timeout waiting for PCI bus mutex"); uint version; + try { long[] outArray = _pawnIO.Execute("ioctl_get_smu_version", [], 1); @@ -34,8 +35,18 @@ public class RyzenSmu public long[] ReadPmTable(int size) { - long[] outArray = _pawnIO.Execute("ioctl_read_pm_table", [], size); - return outArray; + if (!Mutexes.WaitPciBus(5000)) + throw new TimeoutException("Timeout waiting for PCI bus mutex"); + + try + { + long[] outArray = _pawnIO.Execute("ioctl_read_pm_table", [], size); + return outArray; + } + finally + { + Mutexes.ReleasePciBus(); + } } public void UpdatePmTable()