Skip to content

Commit

Permalink
required changes to NativeAOT to support EP
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanF committed Jan 9, 2023
1 parent a4ee746 commit fe8252c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
#endif
#endif

#ifndef __GCENV_BASE_INCLUDED__
// TODO: gcenv.base.h provides these definitions only if it has been included and windows.h
// has not been included (even though though windows.h does not define these services); in
// all other cases the services need to be defined here.

#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))

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

#endif // !__GCENV_BASE_INCLUDED__
#endif // !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))

inline bool IS_ALIGNED(uintptr_t val, uintptr_t alignment);
template <typename T>
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/nativeaot/Runtime/CommonMacros.inl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef __GCENV_BASE_INCLUDED__
// TODO: gcenv.base.h provides these definitions only if it has been included and windows.h
// has not been included (even though though windows.h does not define these services); in
// all other cases the services need to be defined here.

#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))

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

#endif // !__GCENV_BASE_INCLUDED__
#endif // !(defined(__GCENV_BASE_INCLUDED__) && !defined(_INC_WINDOWS))

inline bool IS_ALIGNED(uintptr_t val, uintptr_t alignment)
{
Expand Down
20 changes: 17 additions & 3 deletions src/coreclr/nativeaot/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

#endif // !_MSC_VER

// defined in gcrhenv.cpp
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);

#ifndef _INC_WINDOWS
//#ifndef DACCESS_COMPILE

Expand Down Expand Up @@ -101,9 +104,6 @@ typedef struct _GUID {

#define DECLARE_HANDLE(_name) typedef HANDLE _name

// defined in gcrhenv.cpp
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);

struct FILETIME
{
uint32_t dwLowDateTime;
Expand Down Expand Up @@ -602,6 +602,19 @@ extern uint32_t g_RhNumberOfProcessors;
#endif // !_INC_WINDOWS
#endif // !DACCESS_COMPILE

// TODO: Duplicate the definition from PalRedhawkFunctions.h to allow the EventPipe code to
// access PalEventWrite even though the PalRedhawkFunctions.h services are generally not
// available in NativeAOT runtime contexts where windows.h has been included.
#ifdef _INC_WINDOWS
#ifdef BUILDING_SHARED_NATIVEAOT_EVENTPIPE_CODE
extern "C" uint32_t __stdcall EventWrite(REGHANDLE, const EVENT_DESCRIPTOR *, uint32_t, EVENT_DATA_DESCRIPTOR *);
inline uint32_t PalEventWrite(REGHANDLE arg1, const EVENT_DESCRIPTOR * arg2, uint32_t arg3, EVENT_DATA_DESCRIPTOR * arg4)
{
return EventWrite(arg1, arg2, arg3, arg4);
}
#endif // BUILDING_SHARED_NATIVEAOT_EVENTPIPE_CODE
#endif // _INC_WINDOWS

// The Redhawk PAL must be initialized before any of its exports can be called. Returns true for a successful
// initialization and false on failure.
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalInit();
Expand Down Expand Up @@ -716,6 +729,7 @@ REDHAWK_PALIMPORT void* REDHAWK_PALAPI PalAddVectoredExceptionHandler(uint32_t f
typedef uint32_t (__stdcall *BackgroundCallback)(_In_opt_ void* pCallbackContext);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext);

typedef void (*PalHijackCallback)(_In_ NATIVE_CONTEXT* pThreadContext, _In_opt_ void* pThreadToHijack);
REDHAWK_PALIMPORT void REDHAWK_PALAPI PalHijack(HANDLE hThread, _In_opt_ void* pThreadToHijack);
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/loglf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ DEFINE_LOG_FACILITY(LF_GCALLOC ,0x00000004)
DEFINE_LOG_FACILITY(LF_GCROOTS ,0x00000008)
DEFINE_LOG_FACILITY(LF_STARTUP ,0x00000010) // Log startup and shutdown failures
DEFINE_LOG_FACILITY(LF_STACKWALK ,0x00000020)
DEFINE_LOG_FACILITY(LF_DIAGNOSTICS_PORT, 0x00000040)
// LF_ALWAYS 0x80000000 // make certain you don't try to use this bit for a real facility
// LF_ALL 0xFFFFFFFF
//
#undef DEFINE_LOG_FACILITY

#define INFINITE 0xFFFFFFFF // Infinite timeout
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ typedef DacScanCallbackData EnumGcRefScanContext;
typedef void EnumGcRefCallbackFunc(PTR_PTR_Object, EnumGcRefScanContext* callbackData, uint32_t flags);

#else // DACCESS_COMPILE
#ifndef __GCENV_BASE_INCLUDED__
#if !(defined(__GCENV_BASE_INCLUDED__) && !defined(FEATURE_PERFTRACING))
struct ScanContext;
typedef void promote_func(PTR_PTR_Object, ScanContext*, unsigned);
#endif // !__GCENV_BASE_INCLUDED__
#endif // !__GCENV_BASE_INCLUDED__ && FEATURE_PERFTRACING
typedef promote_func EnumGcRefCallbackFunc;
typedef ScanContext EnumGcRefScanContext;

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCal
#endif // HOST_WASM
}

REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext)
{
return PalStartBackgroundWork(callback, pCallbackContext, UInt32_FALSE);
}

// Returns a 64-bit tick count with a millisecond resolution. It tries its best
// to return monotonically increasing counts and avoid being affected by changes
// to the system clock (either due to drift or due to explicit changes to system
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartFinalizerThread(_In_ BackgroundCal
return PalStartBackgroundWork(callback, pCallbackContext, TRUE);
}

REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext)
{
return PalStartBackgroundWork(callback, pCallbackContext, FALSE);
}

REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalEventEnabled(REGHANDLE regHandle, _In_ const EVENT_DESCRIPTOR* eventDescriptor)
{
return !!EventEnabled(regHandle, eventDescriptor);
Expand Down

0 comments on commit fe8252c

Please sign in to comment.