Skip to content

Commit 32440e5

Browse files
authored
Fix WCHAR definition on non-Windows for nativeaot (#87465)
This fixes enabling of runtime events on non-Windows. The GC events that don't go through ETW::GCLog are now fired/collected on non-Windows. There is still work needed to pull in the ETW::GCLog implementation on non-Windows
1 parent 94a1208 commit 32440e5

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

src/coreclr/nativeaot/Runtime/clretwallmain.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ inline ULONG FireEtwDestroyGCHandle(
2828
inline BOOL EventEnabledExceptionThrown_V1(void) {return EventPipeEventEnabledExceptionThrown_V1();}
2929

3030
inline ULONG FireEtwExceptionThrown_V1(
31-
wchar_t* ExceptionType,
32-
wchar_t* ExceptionMessage,
31+
const WCHAR* ExceptionType,
32+
const WCHAR* ExceptionMessage,
3333
void* ExceptionEIP,
3434
const unsigned int ExceptionHRESULT,
3535
const unsigned short ExceptionFlags,
@@ -70,7 +70,7 @@ inline ULONG FireEtwGCAllocationTick_V2(
7070
const unsigned short ClrInstanceID,
7171
const unsigned __int64 AllocationAmount64,
7272
void* TypeID,
73-
wchar_t* TypeName,
73+
const WCHAR* TypeName,
7474
const unsigned int HeapIndex,
7575
const GUID * ActivityId = nullptr,
7676
const GUID * RelatedActivityId = nullptr
@@ -91,7 +91,7 @@ inline ULONG FireEtwGCAllocationTick_V3(
9191
const unsigned short ClrInstanceID,
9292
const unsigned __int64 AllocationAmount64,
9393
void* TypeID,
94-
wchar_t* TypeName,
94+
const WCHAR* TypeName,
9595
const unsigned int HeapIndex,
9696
void* Address,
9797
const GUID * ActivityId = nullptr,
@@ -561,15 +561,15 @@ inline ULONG FireEtwModuleLoad_V2(
561561
const unsigned __int64 AssemblyID,
562562
const unsigned int ModuleFlags,
563563
const unsigned int Reserved1,
564-
wchar_t* ModuleILPath,
565-
wchar_t* ModuleNativePath,
564+
const WCHAR* ModuleILPath,
565+
const WCHAR* ModuleNativePath,
566566
const unsigned short ClrInstanceID,
567567
const GUID* ManagedPdbSignature,
568568
const unsigned int ManagedPdbAge,
569-
wchar_t* ManagedPdbBuildPath,
569+
const WCHAR* ManagedPdbBuildPath,
570570
const GUID* NativePdbSignature,
571571
const unsigned int NativePdbAge,
572-
wchar_t* NativePdbBuildPath,
572+
const WCHAR* NativePdbBuildPath,
573573
const GUID * ActivityId = nullptr,
574574
const GUID * RelatedActivityId = nullptr
575575
)

src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ ULONG EventPipeWriteEventDestroyGCHandle(
1515
);
1616
BOOL EventPipeEventEnabledExceptionThrown_V1(void);
1717
ULONG EventPipeWriteEventExceptionThrown_V1(
18-
const wchar_t* ExceptionType,
19-
const wchar_t* ExceptionMessage,
18+
const WCHAR* ExceptionType,
19+
const WCHAR* ExceptionMessage,
2020
const void* ExceptionEIP,
2121
const unsigned int ExceptionHRESULT,
2222
const unsigned short ExceptionFlags,
@@ -39,7 +39,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V2(
3939
const unsigned short ClrInstanceID,
4040
const unsigned __int64 AllocationAmount64,
4141
const void* TypeID,
42-
const wchar_t* TypeName,
42+
const WCHAR* TypeName,
4343
const unsigned int HeapIndex,
4444
const GUID * ActivityId = nullptr,
4545
const GUID * RelatedActivityId = nullptr
@@ -51,7 +51,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V3(
5151
const unsigned short ClrInstanceID,
5252
const unsigned __int64 AllocationAmount64,
5353
const void* TypeID,
54-
const wchar_t* TypeName,
54+
const WCHAR* TypeName,
5555
const unsigned int HeapIndex,
5656
const void* Address,
5757
const GUID * ActivityId = nullptr,
@@ -296,15 +296,15 @@ ULONG EventPipeWriteEventModuleLoad_V2(
296296
const unsigned __int64 AssemblyID,
297297
const unsigned int ModuleFlags,
298298
const unsigned int Reserved1,
299-
const wchar_t* ModuleILPath,
300-
const wchar_t* ModuleNativePath,
299+
const WCHAR* ModuleILPath,
300+
const WCHAR* ModuleNativePath,
301301
const unsigned short ClrInstanceID,
302302
const GUID* ManagedPdbSignature,
303303
const unsigned int ManagedPdbAge,
304-
const wchar_t* ManagedPdbBuildPath,
304+
const WCHAR* ManagedPdbBuildPath,
305305
const GUID* NativePdbSignature,
306306
const unsigned int NativePdbAge,
307-
const wchar_t* NativePdbBuildPath,
307+
const WCHAR* NativePdbBuildPath,
308308
const GUID * ActivityId = nullptr,
309309
const GUID * RelatedActivityId = nullptr
310310
);

src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool ResizeBuffer(BYTE *&buffer, size_t& size, size_t currLen, size_t newSize, b
9191

9292
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
9393
// @TODO - Events need to be audited
94-
const WCHAR* DotNETRuntimeName = L"Microsoft-Windows-DotNETRuntime";
94+
const WCHAR* DotNETRuntimeName = W("Microsoft-Windows-DotNETRuntime");
9595
EventPipeProvider *EventPipeProviderDotNETRuntime = nullptr;
9696
EventPipeEvent *EventPipeEventDestroyGCHandle = nullptr;
9797
EventPipeEvent *EventPipeEventExceptionThrown_V1 = nullptr;
@@ -177,8 +177,8 @@ BOOL EventPipeEventEnabledExceptionThrown_V1(void)
177177
}
178178

179179
ULONG EventPipeWriteEventExceptionThrown_V1(
180-
const wchar_t* ExceptionType,
181-
const wchar_t* ExceptionMessage,
180+
const WCHAR* ExceptionType,
181+
const WCHAR* ExceptionMessage,
182182
const void* ExceptionEIP,
183183
const unsigned int ExceptionHRESULT,
184184
const unsigned short ExceptionFlags,
@@ -196,8 +196,8 @@ ULONG EventPipeWriteEventExceptionThrown_V1(
196196
bool fixedBuffer = true;
197197
bool success = true;
198198

199-
if (!ExceptionType) { ExceptionType = L"NULL"; }
200-
if (!ExceptionMessage) { ExceptionMessage = L"NULL"; }
199+
if (!ExceptionType) { ExceptionType = W("NULL"); }
200+
if (!ExceptionMessage) { ExceptionMessage = W("NULL"); }
201201
success &= WriteToBuffer(ExceptionType, buffer, offset, size, fixedBuffer);
202202
success &= WriteToBuffer(ExceptionMessage, buffer, offset, size, fixedBuffer);
203203
success &= WriteToBuffer(ExceptionEIP, buffer, offset, size, fixedBuffer);
@@ -274,7 +274,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V2(
274274
const unsigned short ClrInstanceID,
275275
const unsigned __int64 AllocationAmount64,
276276
const void* TypeID,
277-
const wchar_t* TypeName,
277+
const WCHAR* TypeName,
278278
const unsigned int HeapIndex,
279279
const GUID * ActivityId,
280280
const GUID * RelatedActivityId)
@@ -289,7 +289,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V2(
289289
bool fixedBuffer = true;
290290
bool success = true;
291291

292-
if (!TypeName) { TypeName = L"NULL"; }
292+
if (!TypeName) { TypeName = W("NULL"); }
293293
success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer);
294294
success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer);
295295
success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer);
@@ -325,7 +325,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V3(
325325
const unsigned short ClrInstanceID,
326326
const unsigned __int64 AllocationAmount64,
327327
const void* TypeID,
328-
const wchar_t* TypeName,
328+
const WCHAR* TypeName,
329329
const unsigned int HeapIndex,
330330
const void* Address,
331331
const GUID * ActivityId,
@@ -341,7 +341,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V3(
341341
bool fixedBuffer = true;
342342
bool success = true;
343343

344-
if (!TypeName) { TypeName = L"NULL"; }
344+
if (!TypeName) { TypeName = W("NULL"); }
345345
success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer);
346346
success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer);
347347
success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer);
@@ -1458,15 +1458,15 @@ ULONG EventPipeWriteEventModuleLoad_V2(
14581458
const unsigned __int64 AssemblyID,
14591459
const unsigned int ModuleFlags,
14601460
const unsigned int Reserved1,
1461-
const wchar_t* ModuleILPath,
1462-
const wchar_t* ModuleNativePath,
1461+
const WCHAR* ModuleILPath,
1462+
const WCHAR* ModuleNativePath,
14631463
const unsigned short ClrInstanceID,
14641464
const GUID* ManagedPdbSignature,
14651465
const unsigned int ManagedPdbAge,
1466-
const wchar_t* ManagedPdbBuildPath,
1466+
const WCHAR* ManagedPdbBuildPath,
14671467
const GUID* NativePdbSignature,
14681468
const unsigned int NativePdbAge,
1469-
const wchar_t* NativePdbBuildPath,
1469+
const WCHAR* NativePdbBuildPath,
14701470
const GUID * ActivityId,
14711471
const GUID * RelatedActivityId)
14721472
{
@@ -1480,10 +1480,10 @@ ULONG EventPipeWriteEventModuleLoad_V2(
14801480
bool fixedBuffer = true;
14811481
bool success = true;
14821482

1483-
if (!ModuleILPath) { ModuleILPath = L"NULL"; }
1484-
if (!ModuleNativePath) { ModuleNativePath = L"NULL"; }
1485-
if (!ManagedPdbBuildPath) { ManagedPdbBuildPath = L"NULL"; }
1486-
if (!NativePdbBuildPath) { NativePdbBuildPath = L"NULL"; }
1483+
if (!ModuleILPath) { ModuleILPath = W("NULL"); }
1484+
if (!ModuleNativePath) { ModuleNativePath = W("NULL"); }
1485+
if (!ManagedPdbBuildPath) { ManagedPdbBuildPath = W("NULL"); }
1486+
if (!NativePdbBuildPath) { NativePdbBuildPath = W("NULL"); }
14871487
success &= WriteToBuffer(ModuleID, buffer, offset, size, fixedBuffer);
14881488
success &= WriteToBuffer(AssemblyID, buffer, offset, size, fixedBuffer);
14891489
success &= WriteToBuffer(ModuleFlags, buffer, offset, size, fixedBuffer);

src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ void GCToCLREventSink::FireGCStart_V2(uint32_t count, uint32_t depth, uint32_t r
2727
{
2828
LIMITED_METHOD_CONTRACT;
2929

30-
#ifdef FEATURE_ETW
30+
#ifdef FEATURE_EVENT_TRACE
3131
ETW::GCLog::ETW_GC_INFO gcStartInfo;
3232
gcStartInfo.GCStart.Count = count;
3333
gcStartInfo.GCStart.Depth = depth;
3434
gcStartInfo.GCStart.Reason = static_cast<ETW::GCLog::ETW_GC_INFO::GC_REASON>(reason);
3535
gcStartInfo.GCStart.Type = static_cast<ETW::GCLog::ETW_GC_INFO::GC_TYPE>(type);
3636
ETW::GCLog::FireGcStart(&gcStartInfo);
37-
#endif // FEATURE_ETW
37+
#endif // FEATURE_EVENT_TRACE
3838
}
3939

4040
void GCToCLREventSink::FireGCGenerationRange(uint8_t generation, void* rangeStart, uint64_t rangeUsedLength, uint64_t rangeReservedLength)

src/coreclr/nativeaot/Runtime/inc/CommonTypes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ using std::size_t;
2424
using std::uintptr_t;
2525
using std::intptr_t;
2626

27+
28+
#ifdef TARGET_WINDOWS
2729
typedef wchar_t WCHAR;
30+
#define W(str) L##str
31+
#else
32+
typedef char16_t WCHAR;
33+
#define W(str) u##str
34+
#endif
2835
typedef void * HANDLE;
2936

3037
typedef uint32_t UInt32_BOOL; // windows 4-byte BOOL, 0 -> false, everything else -> true

src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ extern "C" UInt32_BOOL CloseHandle(HANDLE handle)
613613
return success ? UInt32_TRUE : UInt32_FALSE;
614614
}
615615

616-
REDHAWK_PALEXPORT HANDLE REDHAWK_PALAPI PalCreateEventW(_In_opt_ LPSECURITY_ATTRIBUTES pEventAttributes, UInt32_BOOL manualReset, UInt32_BOOL initialState, _In_opt_z_ const wchar_t* pName)
616+
REDHAWK_PALEXPORT HANDLE REDHAWK_PALAPI PalCreateEventW(_In_opt_ LPSECURITY_ATTRIBUTES pEventAttributes, UInt32_BOOL manualReset, UInt32_BOOL initialState, _In_opt_z_ const WCHAR* pName)
617617
{
618618
UnixEvent event = UnixEvent(manualReset, initialState);
619619
if (!event.Initialize())

0 commit comments

Comments
 (0)