Skip to content

Commit

Permalink
Delete NetEventSource.Enter/Exit events (dotnet#38874)
Browse files Browse the repository at this point in the history
They're super verbose, very inconsistent, costly, and not helpful (they appear to be trying to provide tracing of the full flow of calls, but they fail to do even that).
  • Loading branch information
stephentoub authored Jul 10, 2020
1 parent ba60d75 commit b39c698
Show file tree
Hide file tree
Showing 60 changed files with 756 additions and 2,137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,6 @@ internal static int IndexOfKnownHeader(string headerName)

private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, int headerIndex)
{
if (NetEventSource.Log.IsEnabled()) { NetEventSource.Enter(null); }

string header = null;

HTTP_KNOWN_HEADER* pKnownHeader = (&request->Headers.KnownHeaders) + headerIndex;
Expand All @@ -682,7 +680,6 @@ private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, i
header = new string(pKnownHeader->pRawValue + fixup, 0, pKnownHeader->RawValueLength);
}

if (NetEventSource.Log.IsEnabled()) { NetEventSource.Exit(null, $"HttpApi::GetKnownHeader() return:{header}"); }
return header;
}

Expand Down Expand Up @@ -721,8 +718,6 @@ internal static unsafe string GetVerb(IntPtr memoryBlob, IntPtr originalAddress)

internal static unsafe WebHeaderCollection GetHeaders(IntPtr memoryBlob, IntPtr originalAddress)
{
NetEventSource.Enter(null);

// Return value.
WebHeaderCollection headerCollection = new WebHeaderCollection();
byte* pMemoryBlob = (byte*)memoryBlob;
Expand Down Expand Up @@ -770,17 +765,11 @@ internal static unsafe WebHeaderCollection GetHeaders(IntPtr memoryBlob, IntPtr
pKnownHeader++;
}

NetEventSource.Exit(null);
return headerCollection;
}

internal static unsafe uint GetChunks(IntPtr memoryBlob, IntPtr originalAddress, ref int dataChunkIndex, ref uint dataChunkOffset, byte[] buffer, int offset, int size)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Enter(null, $"HttpApi::GetChunks() memoryBlob:{memoryBlob}");
}

// Return value.
uint dataRead = 0;
byte* pMemoryBlob = (byte*)memoryBlob;
Expand Down Expand Up @@ -828,17 +817,11 @@ internal static unsafe uint GetChunks(IntPtr memoryBlob, IntPtr originalAddress,
dataChunkIndex = -1;
}

if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Exit(null);
}
return dataRead;
}

internal static unsafe HTTP_VERB GetKnownVerb(IntPtr memoryBlob, IntPtr originalAddress)
{
NetEventSource.Enter(null);

// Return value.
HTTP_VERB verb = HTTP_VERB.HttpVerbUnknown;

Expand All @@ -848,14 +831,11 @@ internal static unsafe HTTP_VERB GetKnownVerb(IntPtr memoryBlob, IntPtr original
verb = request->Verb;
}

NetEventSource.Exit(null);
return verb;
}

internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);

SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);

Expand All @@ -874,14 +854,11 @@ internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr or
endpoint = new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MinPort).Create(v6address) as IPEndPoint;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null);
return endpoint;
}

internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);

SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);

Expand All @@ -900,7 +877,6 @@ internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr ori
endpoint = s_ipv6Any.Create(v6address) as IPEndPoint;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null);
return endpoint;
}

Expand Down
46 changes: 9 additions & 37 deletions src/libraries/Common/src/Interop/Windows/SspiCli/SSPIWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ internal static class SSPIWrapper
{
internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(ISSPIInterface secModule)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);

if (secModule.SecurityPackages == null)
{
lock (secModule)
Expand Down Expand Up @@ -52,7 +50,6 @@ internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(ISSPIInterf
}
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null);
return secModule.SecurityPackages;
}

Expand Down Expand Up @@ -82,11 +79,7 @@ internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(ISSPIInterf

public static SafeFreeCredentials AcquireDefaultCredential(ISSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Enter(null, package);
NetEventSource.Log.AcquireDefaultCredential(package, intent);
}
if (NetEventSource.Log.IsEnabled()) NetEventSource.Log.AcquireDefaultCredential(package, intent);

SafeFreeCredentials? outCredential = null;
int errorCode = secModule.AcquireDefaultCredential(package, intent, out outCredential);
Expand Down Expand Up @@ -117,11 +110,7 @@ public static SafeFreeCredentials AcquireCredentialsHandle(ISSPIInterface secMod

public static SafeFreeCredentials AcquireCredentialsHandle(ISSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent, Interop.SspiCli.SCHANNEL_CRED scc)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Enter(null, package);
NetEventSource.Log.AcquireCredentialsHandle(package, intent, scc);
}
if (NetEventSource.Log.IsEnabled()) NetEventSource.Log.AcquireCredentialsHandle(package, intent, scc);

SafeFreeCredentials? outCredential = null;
int errorCode = secModule.AcquireCredentialsHandle(
Expand All @@ -136,7 +125,6 @@ public static SafeFreeCredentials AcquireCredentialsHandle(ISSPIInterface secMod
throw new Win32Exception(errorCode);
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, outCredential);
return outCredential;
}

Expand Down Expand Up @@ -355,24 +343,19 @@ private static unsafe int EncryptDecryptHelper(OP op, ISSPIInterface secModule,

public static SafeFreeContextBufferChannelBinding? QueryContextChannelBinding(ISSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, contextAttribute);

SafeFreeContextBufferChannelBinding result;
int errorCode = secModule.QueryContextChannelBinding(securityContext, contextAttribute, out result);
if (errorCode != 0)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return null;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, result);
return result;
}

public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute, ref T attribute) where T : unmanaged
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, contextAttribute);

Span<T> span =
#if NETSTANDARD2_0
stackalloc T[1] { attribute };
Expand All @@ -392,19 +375,16 @@ public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule,
{
if (errorCode != 0)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return false;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, attribute);
return true;
}
}

public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute, Type safeHandleType, out SafeHandle? sspiHandle, ref T attribute) where T : unmanaged
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, contextAttribute);

Span<T> span =
#if NETSTANDARD2_0
stackalloc T[1] { attribute };
Expand All @@ -422,11 +402,10 @@ public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule,

if (errorCode != 0)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return false;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, attribute);
return true;
}

Expand All @@ -436,7 +415,6 @@ public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule,
contextAttribute == Interop.SspiCli.ContextAttribute.SECPKG_ATTR_NAMES ||
contextAttribute == Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CLIENT_SPECIFIED_TARGET);

if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, contextAttribute);

Span<IntPtr> buffer = stackalloc IntPtr[1];
int errorCode = secModule.QueryContextAttributes(
Expand All @@ -452,20 +430,18 @@ public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule,
{
if (errorCode != 0)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return null;
}

string? result = Marshal.PtrToStringUni(sspiHandle.DangerousGetHandle());
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, result);
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, result);
return result;
}
}

public static SafeFreeCertContext? QueryContextAttributes_SECPKG_ATTR_REMOTE_CERT_CONTEXT(ISSPIInterface secModule, SafeDeleteContext securityContext)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);

Span<IntPtr> buffer = stackalloc IntPtr[1];
int errorCode = secModule.QueryContextAttributes(
securityContext,
Expand All @@ -477,19 +453,16 @@ public static bool QueryBlittableContextAttributes<T>(ISSPIInterface secModule,
if (errorCode != 0)
{
sspiHandle?.Dispose();
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return null;
}

var result = (SafeFreeCertContext)sspiHandle!;
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, result);
return result;
}

public static bool QueryContextAttributes_SECPKG_ATTR_ISSUER_LIST_EX(ISSPIInterface secModule, SafeDeleteContext securityContext, ref Interop.SspiCli.SecPkgContext_IssuerListInfoEx ctx, out SafeHandle? sspiHandle)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);

Span<Interop.SspiCli.SecPkgContext_IssuerListInfoEx> buffer =
#if NETSTANDARD2_0
stackalloc Interop.SspiCli.SecPkgContext_IssuerListInfoEx[1] { ctx };
Expand All @@ -508,11 +481,10 @@ public static bool QueryContextAttributes_SECPKG_ATTR_ISSUER_LIST_EX(ISSPIInterf

if (errorCode != 0)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, $"ERROR = {ErrorDescription(errorCode)}");
return false;
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, ctx);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ public static unsafe int AcquireDefaultCredential(
Interop.SspiCli.CredentialUse intent,
out SafeFreeCredentials outCredential)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, package, intent);

int errorCode = -1;
long timeStamp;

Expand Down Expand Up @@ -262,12 +260,9 @@ public static unsafe int AcquireCredentialsHandle(
ref Interop.SspiCli.SCHANNEL_CRED authdata,
out SafeFreeCredentials outCredential)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, package, intent, authdata);

int errorCode = -1;
long timeStamp;


// If there is a certificate, wrap it into an array.
// Not threadsafe.
IntPtr copiedPtr = authdata.paCred;
Expand Down Expand Up @@ -389,8 +384,6 @@ internal static unsafe int InitializeSecurityContext(
ref SecurityBuffer outSecBuffer,
ref Interop.SspiCli.ContextFlags outFlags)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, $"credential:{inCredentials}, crefContext:{refContext}, targetName:{targetName}, inFlags:{inFlags}, endianness:{endianness}");

if (inCredentials == null)
{
throw new ArgumentNullException(nameof(inCredentials));
Expand Down Expand Up @@ -514,7 +507,6 @@ internal static unsafe int InitializeSecurityContext(
outFreeContextBuffer?.Dispose();
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}");
return errorCode;
}

Expand Down Expand Up @@ -621,8 +613,6 @@ internal static unsafe int AcceptSecurityContext(
ref SecurityBuffer outSecBuffer,
ref Interop.SspiCli.ContextFlags outFlags)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null, $"credential={inCredentials}, refContext={refContext}, inFlags={inFlags}");

if (inCredentials == null)
{
throw new ArgumentNullException(nameof(inCredentials));
Expand Down Expand Up @@ -756,7 +746,6 @@ internal static unsafe int AcceptSecurityContext(
}
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}");
return errorCode;
}

Expand Down Expand Up @@ -854,12 +843,7 @@ internal static unsafe int CompleteAuthToken(
ref SafeDeleteSslContext? refContext,
in SecurityBuffer inSecBuffer)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Enter(null, "SafeDeleteContext::CompleteAuthToken");
NetEventSource.Info(null, $" refContext = {refContext}");
NetEventSource.Info(null, $" inSecBuffer = {inSecBuffer}");
}
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"refContext = {refContext}, inSecBuffer = {inSecBuffer}");

var inSecurityBufferDescriptor = new Interop.SspiCli.SecBufferDesc(1);
int errorCode = (int)Interop.SECURITY_STATUS.InvalidHandle;
Expand Down Expand Up @@ -906,20 +890,14 @@ internal static unsafe int CompleteAuthToken(
}
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"unmanaged CompleteAuthToken() errorCode:0x{errorCode:x8} refContext:{refContext}");
return errorCode;
}

internal static unsafe int ApplyControlToken(
ref SafeDeleteContext? refContext,
in SecurityBuffer inSecBuffer)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Enter(null);
NetEventSource.Info(null, $" refContext = {refContext}");
NetEventSource.Info(null, $" inSecBuffer = {inSecBuffer}");
}
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"refContext = {refContext}, inSecBuffer = {inSecBuffer}");

int errorCode = (int)Interop.SECURITY_STATUS.InvalidHandle;

Expand Down Expand Up @@ -968,7 +946,6 @@ internal static unsafe int ApplyControlToken(
}
}

if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null, $"unmanaged ApplyControlToken() errorCode:0x{errorCode:x8} refContext: {refContext}");
return errorCode;
}
}
Expand Down
Loading

0 comments on commit b39c698

Please sign in to comment.