forked from DataDog/dd-trace-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[ASM] New marshalling system for Waf.Run calls to improve spe… (
DataDog#4891) * Revert "[ASM] New marshalling system for Waf.Run calls to improve speed and reduce allocations (DataDog#4302)" This reverts commit 096f106. * fix schema test by syncing with master
- Loading branch information
Showing
20 changed files
with
381 additions
and
755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// <copyright file="Obj.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using Datadog.Trace.AppSec.Waf.NativeBindings; | ||
|
||
namespace Datadog.Trace.AppSec.Waf | ||
{ | ||
// NOTE: this is referred to as ddwaf_object in the C++ code, we call it Obj to avoid a naming clash | ||
internal class Obj : IDisposable | ||
{ | ||
private IntPtr ptr; | ||
private DdwafObjectStruct innerObj; | ||
private bool innerObjInitialized; | ||
private bool disposed; | ||
|
||
public Obj(IntPtr ptr) => this.ptr = ptr; | ||
|
||
~Obj() | ||
{ | ||
Dispose(false); | ||
} | ||
|
||
public ObjType ArgsType | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return Encoder.DecodeArgsType(innerObj.Type); | ||
} | ||
} | ||
|
||
public long IntValue | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return innerObj.IntValue; | ||
} | ||
} | ||
|
||
public ulong UintValue | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return innerObj.UintValue; | ||
} | ||
} | ||
|
||
public nint InnerPtr | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return innerObj.Array; | ||
} | ||
} | ||
|
||
public DdwafObjectStruct InnerStruct | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return innerObj; | ||
} | ||
} | ||
|
||
public IntPtr RawPtr => ptr; | ||
|
||
public void Dispose(WafLibraryInvoker libraryInvoker) | ||
{ | ||
if (libraryInvoker != null) | ||
{ | ||
var rawPtr = ptr; | ||
libraryInvoker.ObjectFreePtr(ref rawPtr); | ||
Dispose(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
if (disposed) | ||
{ | ||
ptr = IntPtr.Zero; | ||
return; | ||
} | ||
|
||
disposed = true; | ||
|
||
if (ptr != IntPtr.Zero) | ||
{ | ||
Marshal.FreeHGlobal(ptr); | ||
ptr = IntPtr.Zero; | ||
} | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
if (innerObjInitialized) | ||
{ | ||
return; | ||
} | ||
|
||
innerObjInitialized = true; | ||
innerObj = (DdwafObjectStruct)Marshal.PtrToStructure(ptr, typeof(DdwafObjectStruct)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// <copyright file="ObjType.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Datadog.Trace.AppSec.Waf | ||
{ | ||
internal enum ObjType | ||
{ | ||
Invalid = 0, | ||
SignedNumber = 1 << 0, | ||
UnsignedNumber = 1 << 1, | ||
String = 1 << 2, | ||
Array = 1 << 3, | ||
Map = 1 << 4, | ||
Bool = 1 << 5, | ||
Double = 1 << 6, | ||
Null = 1 << 7 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.