Skip to content

Commit 9dd19de

Browse files
committed
Merge branch 'main' into wasm_load_crypto_asset
# Conflicts: # src/mono/wasm/runtime/debug.ts
2 parents f011496 + d9df7c4 commit 9dd19de

File tree

17 files changed

+553
-242
lines changed

17 files changed

+553
-242
lines changed

eng/pipelines/coreclr/jitrollingbuild.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ trigger:
33
branches:
44
include:
55
- main
6+
- release/*.*
67
paths:
78
include:
89
- src/coreclr/jit/*

src/coreclr/System.Private.CoreLib/src/System/Runtime/ControlledExecution.CoreCLR.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public static partial class ControlledExecution
4242
[Obsolete(Obsoletions.ControlledExecutionRunMessage, DiagnosticId = Obsoletions.ControlledExecutionRunDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
4343
public static void Run(Action action, CancellationToken cancellationToken)
4444
{
45-
if (!OperatingSystem.IsWindows())
46-
{
47-
throw new PlatformNotSupportedException();
48-
}
49-
5045
ArgumentNullException.ThrowIfNull(action);
5146

5247
// ControlledExecution.Run does not support nested invocations. If there's one already in flight

src/coreclr/inc/eventtracebase.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,11 @@ class CrstBase;
690690
class BulkTypeEventLogger;
691691
class TypeHandle;
692692
class Thread;
693-
693+
template<typename ELEMENT, typename TRAITS>
694+
class SetSHash;
695+
template<typename ELEMENT>
696+
class PtrSetSHashTraits;
697+
typedef SetSHash<MethodDesc*, PtrSetSHashTraits<MethodDesc*>> MethodDescSet;
694698

695699
// All ETW helpers must be a part of this namespace
696700
// We have auto-generated macros to directly fire the events
@@ -903,8 +907,8 @@ namespace ETW
903907
static VOID SendEventsForNgenMethods(Module *pModule, DWORD dwEventOptions);
904908
static VOID SendMethodJitStartEvent(MethodDesc *pMethodDesc, SString *namespaceOrClassName=NULL, SString *methodName=NULL, SString *methodSignature=NULL);
905909
static VOID SendMethodILToNativeMapEvent(MethodDesc * pMethodDesc, DWORD dwEventOptions, PCODE pNativeCodeStartAddress, DWORD nativeCodeId, ReJITID ilCodeId);
906-
static VOID SendMethodRichDebugInfo(MethodDesc * pMethodDesc, PCODE pNativeCodeStartAddress, DWORD nativeCodeId, ReJITID ilCodeId);
907-
static VOID SendMethodEvent(MethodDesc *pMethodDesc, DWORD dwEventOptions, BOOL bIsJit, SString *namespaceOrClassName=NULL, SString *methodName=NULL, SString *methodSignature=NULL, PCODE pNativeCodeStartAddress = 0, PrepareCodeConfig *pConfig = NULL);
910+
static VOID SendMethodRichDebugInfo(MethodDesc * pMethodDesc, PCODE pNativeCodeStartAddress, DWORD nativeCodeId, ReJITID ilCodeId, MethodDescSet* sentMethodDetailsSet);
911+
static VOID SendMethodEvent(MethodDesc *pMethodDesc, DWORD dwEventOptions, BOOL bIsJit, SString *namespaceOrClassName=NULL, SString *methodName=NULL, SString *methodSignature=NULL, PCODE pNativeCodeStartAddress = 0, PrepareCodeConfig *pConfig = NULL, MethodDescSet* sentMethodDetailsSet = NULL);
908912
static VOID SendHelperEvent(ULONGLONG ullHelperStartAddress, ULONG ulHelperSize, LPCWSTR pHelperName);
909913
public:
910914
typedef union _MethodStructs
@@ -937,6 +941,7 @@ namespace ETW
937941
static VOID MethodJitting(MethodDesc *pMethodDesc, SString *namespaceOrClassName, SString *methodName, SString *methodSignature);
938942
static VOID MethodJitted(MethodDesc *pMethodDesc, SString *namespaceOrClassName, SString *methodName, SString *methodSignature, PCODE pNativeCodeStartAddress, PrepareCodeConfig *pConfig);
939943
static VOID SendMethodDetailsEvent(MethodDesc *pMethodDesc);
944+
static VOID SendNonDuplicateMethodDetailsEvent(MethodDesc* pMethodDesc, MethodDescSet* set);
940945
static VOID StubInitialized(ULONGLONG ullHelperStartAddress, LPCWSTR pHelperName);
941946
static VOID StubsInitialized(PVOID *pHelperStartAddress, PVOID *pHelperNames, LONG ulNoOfHelpers);
942947
static VOID MethodRestored(MethodDesc * pMethodDesc);

src/coreclr/inc/nibblestream.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ class NibbleWriter
159159
WriteEncodedU32(dw);
160160
};
161161

162+
void WriteUnencodedU32(uint32_t x)
163+
{
164+
CONTRACTL
165+
{
166+
THROWS;
167+
GC_NOTRIGGER;
168+
}
169+
CONTRACTL_END;
170+
171+
for (int i = 0; i < 8; i++)
172+
{
173+
WriteNibble(static_cast<NIBBLE>(x & 0b1111));
174+
x >>= 4;
175+
}
176+
}
177+
162178
protected:
163179
NIBBLE m_PendingNibble; // Pending value, not yet written out.
164180
bool m_fPending;
@@ -288,6 +304,26 @@ class NibbleReader
288304
return (dw & 1) ? (-x) : (x);
289305
}
290306

307+
DWORD ReadUnencodedU32()
308+
{
309+
CONTRACTL
310+
{
311+
THROWS;
312+
GC_NOTRIGGER;
313+
SUPPORTS_DAC;
314+
}
315+
CONTRACTL_END;
316+
317+
DWORD result = 0;
318+
319+
for (int i = 0; i < 8; i++)
320+
{
321+
result |= static_cast<DWORD>(ReadNibble()) << (i * 4);
322+
}
323+
324+
return result;
325+
}
326+
291327
protected:
292328
PTR_BYTE m_pBuffer;
293329
size_t m_cBytes; // size of buffer.

src/coreclr/pal/src/exception/seh-unwind.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL
558558
// Frame pointer relative offset of a local containing a pointer to the windows style context of a location
559559
// where a hardware exception occurred.
560560
int g_hardware_exception_context_locvar_offset = 0;
561+
// Frame pointer relative offset of a local containing a pointer to the windows style context of a location
562+
// where an activation signal interrupted the thread.
563+
int g_inject_activation_context_locvar_offset = 0;
561564

562565
BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
563566
{
@@ -579,6 +582,18 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
579582
return TRUE;
580583
}
581584

585+
// Check if the PC is the return address from the InvokeActivationHandler.
586+
// If that's the case, extract its local variable containing a pointer to the windows style context of the activation
587+
// injection location and return that. This skips the signal handler trampoline that the libunwind
588+
// cannot cross on some systems.
589+
if ((void*)curPc == g_InvokeActivationHandlerReturnAddress)
590+
{
591+
CONTEXT* activationContext = (CONTEXT*)(CONTEXTGetFP(context) + g_inject_activation_context_locvar_offset);
592+
memcpy_s(context, sizeof(CONTEXT), activationContext, sizeof(CONTEXT));
593+
594+
return TRUE;
595+
}
596+
582597
if ((context->ContextFlags & CONTEXT_EXCEPTION_ACTIVE) != 0)
583598
{
584599
// The current frame is a source of hardware exception. Due to the fact that

src/coreclr/pal/src/exception/seh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ PGET_GCMARKER_EXCEPTION_CODE g_getGcMarkerExceptionCode = NULL;
6161
// Return address of the SEHProcessException, which is used to enable walking over
6262
// the signal handler trampoline on some Unixes where the libunwind cannot do that.
6363
void* g_SEHProcessExceptionReturnAddress = NULL;
64+
void* g_InvokeActivationHandlerReturnAddress = NULL;
6465

6566
/* Internal function definitions **********************************************/
6667

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef void (*SIGFUNC)(int, siginfo_t *, void *);
7373
static void sigterm_handler(int code, siginfo_t *siginfo, void *context);
7474
#ifdef INJECT_ACTIVATION_SIGNAL
7575
static void inject_activation_handler(int code, siginfo_t *siginfo, void *context);
76+
extern void* g_InvokeActivationHandlerReturnAddress;
7677
#endif
7778

7879
static void sigill_handler(int code, siginfo_t *siginfo, void *context);
@@ -775,6 +776,29 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context)
775776
}
776777

777778
#ifdef INJECT_ACTIVATION_SIGNAL
779+
780+
/*++
781+
Function :
782+
InvokeActivationHandler
783+
784+
Invoke the registered activation handler.
785+
It also saves the return address (inject_activation_handler) so that PAL_VirtualUnwind can detect that
786+
it has reached that method and use the context stored in the winContext there to unwind to the code
787+
where the activation was injected. This is necessary on Alpine Linux where the libunwind cannot correctly
788+
unwind past the signal frame.
789+
790+
Parameters :
791+
Windows style context of the location where the activation was injected
792+
793+
(no return value)
794+
--*/
795+
__attribute__((noinline))
796+
static void InvokeActivationHandler(CONTEXT *pWinContext)
797+
{
798+
g_InvokeActivationHandlerReturnAddress = __builtin_return_address(0);
799+
g_activationFunction(pWinContext);
800+
}
801+
778802
/*++
779803
Function :
780804
inject_activation_handler
@@ -803,15 +827,26 @@ static void inject_activation_handler(int code, siginfo_t *siginfo, void *contex
803827
native_context_t *ucontext = (native_context_t *)context;
804828

805829
CONTEXT winContext;
830+
// Pre-populate context with data from current frame, because ucontext doesn't have some data (e.g. SS register)
831+
// which is required for restoring context
832+
RtlCaptureContext(&winContext);
833+
834+
ULONG contextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT;
835+
836+
#if defined(HOST_AMD64)
837+
contextFlags |= CONTEXT_XSTATE;
838+
#endif
839+
806840
CONTEXTFromNativeContext(
807841
ucontext,
808842
&winContext,
809-
CONTEXT_CONTROL | CONTEXT_INTEGER);
843+
contextFlags);
810844

811845
if (g_safeActivationCheckFunction(CONTEXTGetPC(&winContext), /* checkingCurrentThread */ TRUE))
812846
{
847+
g_inject_activation_context_locvar_offset = (int)((char*)&winContext - (char*)__builtin_frame_address(0));
813848
int savedErrNo = errno; // Make sure that errno is not modified
814-
g_activationFunction(&winContext);
849+
InvokeActivationHandler(&winContext);
815850
errno = savedErrNo;
816851

817852
// Activation function may have modified the context, so update it.

src/coreclr/pal/src/include/pal/seh.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ CorUnix::PAL_ERROR SEHDisable(CorUnix::CPalThread *pthrCurrent);
148148
// Offset of the local variable containing pointer to windows style context in the common_signal_handler / PAL_DispatchException function.
149149
// This offset is relative to the frame pointer.
150150
extern int g_hardware_exception_context_locvar_offset;
151-
151+
// Offset of the local variable containing pointer to windows style context in the inject_activation_handler.
152+
// This offset is relative to the frame pointer.
153+
extern int g_inject_activation_context_locvar_offset;
152154

153155
#endif /* _PAL_SEH_HPP_ */
154156

0 commit comments

Comments
 (0)