Skip to content

Commit a31c5df

Browse files
committed
Mutexes fixed
1 parent b46bcdb commit a31c5df

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

OpenHardwareMonitorLib/Hardware/Mutexes.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Security.AccessControl;
3+
using System.Security.Principal;
24
using System.Threading;
35

46
namespace OpenHardwareMonitor.Hardware;
@@ -24,7 +26,15 @@ static Mutex CreateOrOpenExistingMutex(string name)
2426
{
2527
try
2628
{
27-
return new Mutex(false, name);
29+
var worldRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
30+
var mutexSecurity = new MutexSecurity();
31+
mutexSecurity.AddAccessRule(worldRule);
32+
33+
#if NETFRAMEWORK
34+
return new Mutex(false, name, out _, mutexSecurity);
35+
#else
36+
return MutexAcl.Create(false, name, out _, mutexSecurity);
37+
#endif
2838
}
2939
catch (UnauthorizedAccessException)
3040
{

OpenHardwareMonitorLib/Hardware/OpCode.cs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static class OpCode
2525
// }
2626

2727
private static readonly byte[] CpuId32 =
28-
{
28+
[
2929
0x55, // push ebp
3030
0x8B,
3131
0xEC, // mov ebp, esp
@@ -94,10 +94,10 @@ internal static class OpCode
9494
0xC2,
9595
0x18,
9696
0x00 // ret 18h
97-
};
97+
];
9898

9999
private static readonly byte[] CpuId64Linux =
100-
{
100+
[
101101
0x49,
102102
0x89,
103103
0xD2, // mov r10, rdx
@@ -125,10 +125,10 @@ internal static class OpCode
125125
0x11, // mov dword ptr [r9], edx
126126
0x5B, // pop rbx
127127
0xC3 // ret
128-
};
128+
];
129129

130130
private static readonly byte[] CpuId64Windows =
131-
{
131+
[
132132
0x48,
133133
0x89,
134134
0x5C,
@@ -166,21 +166,21 @@ internal static class OpCode
166166
0x89,
167167
0x10, // mov dword ptr [rax], edx
168168
0xC3 // ret
169-
};
169+
];
170170

171171
// unsigned __int64 __stdcall rdtsc() {
172172
// return __rdtsc();
173173
// }
174174

175175
private static readonly byte[] Rdtsc32 =
176-
{
176+
[
177177
0x0F,
178178
0x31, // rdtsc
179179
0xC3 // ret
180-
};
180+
];
181181

182182
private static readonly byte[] Rdtsc64 =
183-
{
183+
[
184184
0x0F,
185185
0x31, // rdtsc
186186
0x48,
@@ -191,7 +191,7 @@ internal static class OpCode
191191
0x0B,
192192
0xC2, // or rax, rdx
193193
0xC3 // ret
194-
};
194+
];
195195

196196
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
197197
public delegate bool CpuidDelegate(uint index, uint ecxValue, out uint eax, out uint ebx, out uint ecx, out uint edx);
@@ -239,7 +239,7 @@ public static void Open()
239239
(int)mmapFlags.GetField("MAP_PRIVATE").GetValue(null));
240240

241241
if (mmap != null)
242-
_codeBuffer = (IntPtr)mmap.Invoke(null, new[] { IntPtr.Zero, _size, mmapProtsParam, mmapFlagsParam, -1, 0 });
242+
_codeBuffer = (IntPtr)mmap.Invoke(null, [IntPtr.Zero, _size, mmapProtsParam, mmapFlagsParam, -1, 0]);
243243
}
244244
else
245245
{
@@ -266,30 +266,16 @@ public static void Close()
266266
#if NETFRAMEWORK
267267
Assembly assembly = Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " + "PublicKeyToken=0738eb9f132ed756");
268268
#else
269-
Assembly assembly = Assembly.Load("Mono.Posix.NETStandard, Version=1.0.0.0, Culture=neutral");
269+
Assembly assembly = Assembly.Load("Mono.Posix.NETStandard, Version=1.0.0.0, Culture=neutral");
270270
#endif
271271

272272
Type sysCall = assembly.GetType("Mono.Unix.Native.Syscall");
273273
MethodInfo method = sysCall.GetMethod("munmap");
274-
method?.Invoke(null, new object[] { _codeBuffer, _size });
274+
method?.Invoke(null, [_codeBuffer, _size]);
275275
}
276276
else
277277
{
278278
Interop.Kernel32.VirtualFree(_codeBuffer, UIntPtr.Zero, Interop.Kernel32.MEM.MEM_RELEASE);
279279
}
280280
}
281-
282-
public static bool CpuIdTx(uint index, uint ecxValue, out uint eax, out uint ebx, out uint ecx, out uint edx, GroupAffinity affinity)
283-
{
284-
GroupAffinity previousAffinity = ThreadAffinity.Set(affinity);
285-
if (previousAffinity == GroupAffinity.Undefined)
286-
{
287-
eax = ebx = ecx = edx = 0;
288-
return false;
289-
}
290-
291-
CpuId(index, ecxValue, out eax, out ebx, out ecx, out edx);
292-
ThreadAffinity.Set(previousAffinity);
293-
return true;
294-
}
295281
}

OpenHardwareMonitorLib/OpenHardwareMonitorLib.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@
8888
<EmbeddedResource Include="Resources\WinRing0x64.gz" />
8989
</ItemGroup>
9090
<ItemGroup>
91-
<PackageReference Include="HidSharp" Version="2.6.2" />
91+
<PackageReference Include="HidSharp" Version="2.6.3" />
9292
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
9393
<PackageReference Include="System.IO.Ports" Version="9.0.9" />
9494
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
9595
<PackageReference Include="SergiyE.Common" Version="1.*" />
9696
<PackageReference Include="System.Management" Version="9.0.9" />
97+
<PackageReference Include="System.Threading.AccessControl" Version="9.0.9" />
9798
<PackageReference Include="RAMSPDToolkit-NDD" Version="1.2.2" />
9899
</ItemGroup>
99100
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">

0 commit comments

Comments
 (0)