Skip to content

Commit 1a2314a

Browse files
committed
Added a static Boolean on the SocketOptions class to avoid using the opcode injection technique for reading the time stamp counter.
1 parent f416a78 commit 1a2314a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/NetMQ/Core/Utils/OpCode.cs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ internal static class Opcode
1111

1212
public static bool Open()
1313
{
14+
if (SocketOptions.DoNotUseRDTSC)
15+
return false;
1416
#if NETSTANDARD1_1_OR_GREATER || NET471_OR_GREATER
1517
if (RuntimeInformation.ProcessArchitecture != Architecture.X86 &&
1618
RuntimeInformation.ProcessArchitecture != Architecture.X64)

src/NetMQ/SocketOptions.cs

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ namespace NetMQ
1212
/// </summary>
1313
public class SocketOptions
1414
{
15+
/// <summary>
16+
/// If set, the time stamp counter is not read directly through opcode injection,
17+
/// rather <see cref="System.Diagnostics.Stopwatch.GetTimestamp"/> is used.
18+
/// When false, the time stamp counter is read by allocating a few bytes on the heap with
19+
/// read/write/execute privilege. OpCode is copied to this allocated memory and invoked to read
20+
/// the time stamp counter, (which is a register available on most modern CPUs). While this is
21+
/// an accurate way to read the time stamp counter, because it injects code onto the heap, this
22+
/// can be detected as a malware technique by some anti-virus defenders.
23+
/// </summary>
24+
public static bool DoNotUseRDTSC;
1525
/// <summary>
1626
/// The NetMQSocket that this SocketOptions is referencing.
1727
/// </summary>

0 commit comments

Comments
 (0)