Skip to content

Commit 2fb886e

Browse files
authored
[Service Disc] Change type layout to make it x86 safe (#7387)
## Summary of changes Change service discovery result type to work in x86 systems. ## Reason for change tested locally removing x64 guards it works on both ## Implementation details use a mix of sequential and explicit layouts ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. -->
1 parent e670c1c commit 2fb886e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tracer/src/Datadog.Trace/LibDatadog/ServiceDiscovery/ServiceDiscoveryHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ internal static StoreMetadataResult StoreTracerMetadata(TracerSettings tracerSet
4242

4343
if (result.Tag == ResultTag.Error)
4444
{
45-
Log.Error("Failed to store tracer metadata with message: {Error}", result.Error.Message.ToUtf8String());
46-
NativeInterop.Common.DropError(ref result.Error);
45+
Log.Error("Failed to store tracer metadata with message: {Error}", result.Result.Error.Message.ToUtf8String());
46+
NativeInterop.Common.DropError(ref result.Result.Error);
4747
return StoreMetadataResult.Error;
4848
}
4949

tracer/src/Datadog.Trace/LibDatadog/ServiceDiscovery/TracerMemfdHandleResult.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@
1010
namespace Datadog.Trace.LibDatadog.ServiceDiscovery;
1111

1212
/// <summary>
13-
/// **DO NOT USE THIS TYPE in x86** to map with Libdatadog. OK and Err fields needs a 4 offset instead.
1413
/// Do not change the values of this enum unless you really need to update the interop mapping.
1514
/// Libdatadog interop mapping of the generic type: https://github.com/DataDog/libdatadog/blob/60583218a8de6768f67d04fcd5bc6443f67f516b/ddcommon-ffi/src/result.rs#L44
1615
/// Cf also ddog_Result_TracerMemfdHandle in common.h headers.
1716
/// </summary>
18-
[StructLayout(LayoutKind.Explicit)]
17+
[StructLayout(LayoutKind.Sequential)]
1918
internal struct TracerMemfdHandleResult
2019
{
21-
[FieldOffset(0)]
2220
public ResultTag Tag;
2321

24-
// beware that offset 8 is only valid on x64 and would cause a crash if read on x86.
25-
[FieldOffset(8)]
26-
public int TracerMemfdHandle;
22+
public ResultUnion Result;
2723

28-
[FieldOffset(8)]
29-
public Error Error;
24+
[StructLayout(LayoutKind.Explicit)]
25+
public struct ResultUnion
26+
{
27+
[FieldOffset(0)]
28+
public int TracerMemfdHandle;
29+
30+
[FieldOffset(0)]
31+
public Error Error;
32+
}
3033
}

0 commit comments

Comments
 (0)