Skip to content

Commit 7ac1ca6

Browse files
[release/10.0.1xx] Source code updates from dotnet/runtime (#2155)
[release/10.0.1xx] Source code updates from dotnet/runtime
1 parent 524c878 commit 7ac1ca6

File tree

19 files changed

+171
-57
lines changed

19 files changed

+171
-57
lines changed

src/runtime/src/coreclr/jit/hwintrinsiclistarm64.h

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

src/runtime/src/coreclr/jit/hwintrinsiclistxarch.h

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

src/runtime/src/coreclr/jit/importercalls.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10762,6 +10762,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1076210762
lookupMethodName = nullptr;
1076310763
}
1076410764
}
10765+
else if (strcmp(methodName, "SquareRoot") == 0)
10766+
{
10767+
lookupMethodName = "Sqrt";
10768+
}
1076510769

1076610770
if (lookupMethodName != nullptr)
1076710771
{

src/runtime/src/coreclr/nativeaot/Bootstrap/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#include <stdint.h>
5+
#include <stddef.h>
56

67
#if defined(DEBUG) && defined(_WIN32)
78
#include <process.h>
@@ -138,10 +139,16 @@ MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetUnhandledExceptionPropagationHandler)
138139

139140
typedef void (MANAGED_RUNTIME_EXPORT_CALLCONV *pfn)();
140141

142+
#if defined(_WIN32)
143+
extern "C" int ThreadEntryPoint(void* pContext);
144+
#else
145+
extern "C" size_t ThreadEntryPoint(void* pContext);
146+
#endif
147+
141148
static const pfn c_classlibFunctions[] = {
142149
&MANAGED_RUNTIME_EXPORT_NAME(GetRuntimeException),
143150
&MANAGED_RUNTIME_EXPORT_NAME(RuntimeFailFast),
144-
nullptr, // &UnhandledExceptionHandler,
151+
(pfn)&ThreadEntryPoint,
145152
&MANAGED_RUNTIME_EXPORT_NAME(AppendExceptionStackFrame),
146153
nullptr, // &CheckStaticClassConstruction,
147154
&MANAGED_RUNTIME_EXPORT_NAME(GetSystemArrayEEType),

src/runtime/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal enum ClassLibFunctionId
3838
{
3939
GetRuntimeException = 0,
4040
FailFast = 1,
41-
// UnhandledExceptionHandler = 2, // unused
41+
ThreadEntryPoint = 2,
4242
AppendExceptionStackFrame = 3,
4343
// unused = 4,
4444
GetSystemArrayEEType = 5,

src/runtime/src/coreclr/nativeaot/Runtime/ICodeManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ enum class ClasslibFunctionId
9999
{
100100
GetRuntimeException = 0,
101101
FailFast = 1,
102-
UnhandledExceptionHandler = 2,
102+
ThreadEntryPoint = 2,
103103
AppendExceptionStackFrame = 3,
104104
// unused = 4,
105105
GetSystemArrayEEType = 5,

src/runtime/src/coreclr/nativeaot/Runtime/thread.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "common.h"
55
#include "gcenv.h"
66
#include "gcheaputilities.h"
7+
#include "gchandleutilities.h"
78

89
#include "CommonTypes.h"
910
#include "CommonMacros.h"
@@ -1278,6 +1279,49 @@ FCIMPL0(Object**, RhGetThreadStaticStorage)
12781279
}
12791280
FCIMPLEND
12801281

1282+
#ifdef TARGET_UNIX
1283+
#define NEWTHREAD_RETURN_TYPE size_t
1284+
#else
1285+
#define NEWTHREAD_RETURN_TYPE uint32_t
1286+
#endif
1287+
1288+
static NEWTHREAD_RETURN_TYPE RhThreadEntryPoint(void* pContext)
1289+
{
1290+
// We will attach the thread early so that when the managed thread entrypoint
1291+
// starts running and performs its reverse p/invoke transition, the thread is
1292+
// already attached.
1293+
//
1294+
// This avoids potential deadlocks with module initializers that may be running
1295+
// as part of runtime initialization (in non-EXE scenario) and creating new
1296+
// threads. When RhThreadEntryPoint runs, the runtime must already be initialized
1297+
// enough to be able to run managed code so we don't need to wait for it to
1298+
// finish.
1299+
1300+
ThreadStore::AttachCurrentThread();
1301+
1302+
Thread * pThread = ThreadStore::GetCurrentThread();
1303+
pThread->SetDeferredTransitionFrameForNativeHelperThread();
1304+
pThread->DisablePreemptiveMode();
1305+
1306+
Object * pThreadObject = ObjectFromHandle((OBJECTHANDLE)pContext);
1307+
MethodTable* pMT = pThreadObject->GetMethodTable();
1308+
1309+
pThread->EnablePreemptiveMode();
1310+
1311+
NEWTHREAD_RETURN_TYPE (*pFn)(void*) = (NEWTHREAD_RETURN_TYPE (*)(void*))
1312+
pMT->GetTypeManagerPtr()
1313+
->AsTypeManager()
1314+
->GetClasslibFunction(ClasslibFunctionId::ThreadEntryPoint);
1315+
1316+
return pFn(pContext);
1317+
}
1318+
1319+
FCIMPL0(void*, RhGetThreadEntryPointAddress)
1320+
{
1321+
return (void*)&RhThreadEntryPoint;
1322+
}
1323+
FCIMPLEND
1324+
12811325
InlinedThreadStaticRoot* Thread::GetInlinedThreadStaticList()
12821326
{
12831327
return m_pInlinedThreadLocalStatics;

src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
2727
throw new PlatformNotSupportedException();
2828
}
2929

30-
private static unsafe ref byte GetSpanDataFrom(
31-
RuntimeFieldHandle fldHandle,
32-
RuntimeTypeHandle targetTypeHandle,
33-
out int count)
34-
{
35-
// We only support this intrinsic when it occurs within a well-defined IL sequence.
36-
// If a call to this method occurs within the recognized sequence, codegen must expand the IL sequence completely.
37-
// For any other purpose, the API is currently unsupported.
38-
// https://github.com/dotnet/corert/issues/364
39-
throw new PlatformNotSupportedException();
40-
}
41-
4230
[RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")]
4331
public static void RunClassConstructor(RuntimeTypeHandle type)
4432
{

src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ internal static partial class RuntimeImports
2626
{
2727
internal const string RuntimeLibrary = "*";
2828

29+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
30+
[RuntimeImport(RuntimeLibrary, "RhGetThreadEntryPointAddress")]
31+
#if TARGET_UNIX
32+
internal static extern unsafe delegate* unmanaged<nint, nint> RhGetThreadEntryPointAddress();
33+
#else
34+
internal static extern unsafe delegate* unmanaged<nint, uint> RhGetThreadEntryPointAddress();
35+
#endif
36+
2937
[MethodImplAttribute(MethodImplOptions.InternalCall)]
3038
[RuntimeImport(RuntimeLibrary, "RhGetCrashInfoBuffer")]
3139
internal static extern unsafe byte* RhGetCrashInfoBuffer(out int cbMaxSize);

src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private unsafe bool CreateThread(GCHandle<Thread> thisThreadHandle)
101101
stackSize = RuntimeImports.RhGetDefaultStackSize();
102102
}
103103

104-
if (!Interop.Sys.CreateThread(stackSize, &ThreadEntryPoint, GCHandle<Thread>.ToIntPtr(thisThreadHandle)))
104+
if (!Interop.Sys.CreateThread(stackSize, RuntimeImports.RhGetThreadEntryPointAddress(), GCHandle<Thread>.ToIntPtr(thisThreadHandle)))
105105
{
106106
return false;
107107
}
@@ -115,7 +115,7 @@ private unsafe bool CreateThread(GCHandle<Thread> thisThreadHandle)
115115
/// <summary>
116116
/// This is an entry point for managed threads created by application
117117
/// </summary>
118-
[UnmanagedCallersOnly]
118+
[UnmanagedCallersOnly(EntryPoint = "ThreadEntryPoint")]
119119
private static IntPtr ThreadEntryPoint(IntPtr parameter)
120120
{
121121
StartThread(parameter);

0 commit comments

Comments
 (0)