Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a static Boolean on the SocketOptions class to avoid using the … #1072

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NetMQ/Core/Utils/OpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal static class Opcode

public static bool Open()
{
if (SocketOptions.DoNotUseRDTSC)
return false;
#if NETSTANDARD1_1_OR_GREATER || NET471_OR_GREATER
if (RuntimeInformation.ProcessArchitecture != Architecture.X86 &&
RuntimeInformation.ProcessArchitecture != Architecture.X64)
Expand Down
10 changes: 10 additions & 0 deletions src/NetMQ/SocketOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ namespace NetMQ
/// </summary>
public class SocketOptions
{
/// <summary>
/// If set, the time stamp counter is not read directly through opcode injection,
/// rather <see cref="System.Diagnostics.Stopwatch.GetTimestamp"/> is used.
/// When false, the time stamp counter is read by allocating a few bytes on the heap with
/// read/write/execute privilege. OpCode is copied to this allocated memory and invoked to read
/// the time stamp counter, (which is a register available on most modern CPUs). While this is
/// an accurate way to read the time stamp counter, because it injects code onto the heap, this
/// can be detected as a malware technique by some anti-virus defenders.
/// </summary>
public static bool DoNotUseRDTSC;
Comment on lines +15 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really seem like a socket option, and we don't have any other static options here as far as I can tell.

Also the timing of setting this value is important, as the result of Open is cached in Clock.s_rdtscSupported.

Because of the timing issue, what about using something like an environment variable to control this. For example, if NETQM_SUPPRESS_RDTSC was present, it would disable any attempt to call Opcode.Open() and store a false in s_rdtscSupported. All that could happen in the static constructor of Clock.

/// <summary>
/// The NetMQSocket that this SocketOptions is referencing.
/// </summary>
Expand Down
Loading