Skip to content

Commit fe8252c

Browse files
committed
required changes to NativeAOT to support EP
1 parent a4ee746 commit fe8252c

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

src/coreclr/nativeaot/Runtime/CommonMacros.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@
6262
#endif
6363
#endif
6464

65-
#ifndef __GCENV_BASE_INCLUDED__
65+
// TODO: gcenv.base.h provides these definitions only if it has been included and windows.h
66+
// has not been included (even though though windows.h does not define these services); in
67+
// all other cases the services need to be defined here.
68+
69+
#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))
6670

6771
//
6872
// This macro returns val rounded up as necessary to be a multiple of alignment; alignment must be a power of 2
@@ -75,7 +79,7 @@ inline uintptr_t ALIGN_DOWN(uintptr_t val, uintptr_t alignment);
7579
template <typename T>
7680
inline T* ALIGN_DOWN(T* val, uintptr_t alignment);
7781

78-
#endif // !__GCENV_BASE_INCLUDED__
82+
#endif // !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))
7983

8084
inline bool IS_ALIGNED(uintptr_t val, uintptr_t alignment);
8185
template <typename T>

src/coreclr/nativeaot/Runtime/CommonMacros.inl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#ifndef __GCENV_BASE_INCLUDED__
4+
// TODO: gcenv.base.h provides these definitions only if it has been included and windows.h
5+
// has not been included (even though though windows.h does not define these services); in
6+
// all other cases the services need to be defined here.
7+
8+
#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))
59

610
//
711
// This macro returns val rounded up as necessary to be a multiple of alignment; alignment must be a power of 2
@@ -36,7 +40,7 @@ inline T* ALIGN_DOWN(T* val, uintptr_t alignment)
3640
return reinterpret_cast<T*>(ALIGN_DOWN(reinterpret_cast<uintptr_t>(val), alignment));
3741
}
3842

39-
#endif // !__GCENV_BASE_INCLUDED__
43+
#endif // !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))
4044

4145
inline bool IS_ALIGNED(uintptr_t val, uintptr_t alignment)
4246
{

src/coreclr/nativeaot/Runtime/PalRedhawk.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949

5050
#endif // !_MSC_VER
5151

52+
// defined in gcrhenv.cpp
53+
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);
54+
5255
#ifndef _INC_WINDOWS
5356
//#ifndef DACCESS_COMPILE
5457

@@ -101,9 +104,6 @@ typedef struct _GUID {
101104

102105
#define DECLARE_HANDLE(_name) typedef HANDLE _name
103106

104-
// defined in gcrhenv.cpp
105-
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);
106-
107107
struct FILETIME
108108
{
109109
uint32_t dwLowDateTime;
@@ -602,6 +602,19 @@ extern uint32_t g_RhNumberOfProcessors;
602602
#endif // !_INC_WINDOWS
603603
#endif // !DACCESS_COMPILE
604604

605+
// TODO: Duplicate the definition from PalRedhawkFunctions.h to allow the EventPipe code to
606+
// access PalEventWrite even though the PalRedhawkFunctions.h services are generally not
607+
// available in NativeAOT runtime contexts where windows.h has been included.
608+
#ifdef _INC_WINDOWS
609+
#ifdef BUILDING_SHARED_NATIVEAOT_EVENTPIPE_CODE
610+
extern "C" uint32_t __stdcall EventWrite(REGHANDLE, const EVENT_DESCRIPTOR *, uint32_t, EVENT_DATA_DESCRIPTOR *);
611+
inline uint32_t PalEventWrite(REGHANDLE arg1, const EVENT_DESCRIPTOR * arg2, uint32_t arg3, EVENT_DATA_DESCRIPTOR * arg4)
612+
{
613+
return EventWrite(arg1, arg2, arg3, arg4);
614+
}
615+
#endif // BUILDING_SHARED_NATIVEAOT_EVENTPIPE_CODE
616+
#endif // _INC_WINDOWS
617+
605618
// The Redhawk PAL must be initialized before any of its exports can be called. Returns true for a successful
606619
// initialization and false on failure.
607620
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalInit();
@@ -716,6 +729,7 @@ REDHAWK_PALIMPORT void* REDHAWK_PALAPI PalAddVectoredExceptionHandler(uint32_t f
716729
typedef uint32_t (__stdcall *BackgroundCallback)(_In_opt_ void* pCallbackContext);
717730
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);
718731
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);
732+
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);
719733

720734
typedef void (*PalHijackCallback)(_In_ NATIVE_CONTEXT* pThreadContext, _In_opt_ void* pThreadToHijack);
721735
REDHAWK_PALIMPORT void REDHAWK_PALAPI PalHijack(HANDLE hThread, _In_opt_ void* pThreadToHijack);

src/coreclr/nativeaot/Runtime/loglf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ DEFINE_LOG_FACILITY(LF_GCALLOC ,0x00000004)
1010
DEFINE_LOG_FACILITY(LF_GCROOTS ,0x00000008)
1111
DEFINE_LOG_FACILITY(LF_STARTUP ,0x00000010) // Log startup and shutdown failures
1212
DEFINE_LOG_FACILITY(LF_STACKWALK ,0x00000020)
13+
DEFINE_LOG_FACILITY(LF_DIAGNOSTICS_PORT, 0x00000040)
1314
// LF_ALWAYS 0x80000000 // make certain you don't try to use this bit for a real facility
1415
// LF_ALL 0xFFFFFFFF
1516
//
1617
#undef DEFINE_LOG_FACILITY
1718

19+
#define INFINITE 0xFFFFFFFF // Infinite timeout

src/coreclr/nativeaot/Runtime/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ typedef DacScanCallbackData EnumGcRefScanContext;
331331
typedef void EnumGcRefCallbackFunc(PTR_PTR_Object, EnumGcRefScanContext* callbackData, uint32_t flags);
332332

333333
#else // DACCESS_COMPILE
334-
#ifndef __GCENV_BASE_INCLUDED__
334+
#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(FEATURE_PERFTRACING))
335335
struct ScanContext;
336336
typedef void promote_func(PTR_PTR_Object, ScanContext*, unsigned);
337-
#endif // !__GCENV_BASE_INCLUDED__
337+
#endif // !__GCENV_BASE_INCLUDED__ && FEATURE_PERFTRACING
338338
typedef promote_func EnumGcRefCallbackFunc;
339339
typedef ScanContext EnumGcRefScanContext;
340340

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCal
632632
#endif // HOST_WASM
633633
}
634634

635+
REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext)
636+
{
637+
return PalStartBackgroundWork(callback, pCallbackContext, UInt32_FALSE);
638+
}
639+
635640
// Returns a 64-bit tick count with a millisecond resolution. It tries its best
636641
// to return monotonically increasing counts and avoid being affected by changes
637642
// to the system clock (either due to drift or due to explicit changes to system

src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,11 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCal
612612
return PalStartBackgroundWork(callback, pCallbackContext, TRUE);
613613
}
614614

615+
REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext)
616+
{
617+
return PalStartBackgroundWork(callback, pCallbackContext, FALSE);
618+
}
619+
615620
REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalEventEnabled(REGHANDLE regHandle, _In_ const EVENT_DESCRIPTOR* eventDescriptor)
616621
{
617622
return !!EventEnabled(regHandle, eventDescriptor);

0 commit comments

Comments
 (0)