Skip to content

Commit 841c89e

Browse files
committed
Merge dotnet/main into feature/HMF-removal/JIT_Box
2 parents 0fafa0a + b32d486 commit 841c89e

File tree

27 files changed

+1747
-128
lines changed

27 files changed

+1747
-128
lines changed

docs/design/specs/runtime-async.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ Applicability of `MethodImplOptions.Async`:
1818
* The `[MethodImpl(MethodImplOptions.Async)]` only has effect when applied to method definitions with CIL implementation.
1919
* Async method definitions are only valid inside async-capable assemblies. An async-capable assembly is one which references a corlib containing an `abstract sealed class RuntimeFeature` with a `public const string` field member named `Async`.
2020
* Combining `MethodImplOptions.Async` with `MethodImplOptions.Synchronized` is invalid.
21-
* Applying `MethodImplOptions.Async` to methods with `byref` or `ref-like` parameters is invalid.
21+
* Applying `MethodImplOptions.Async` to methods with a `byref` or `ref-like` return value is invalid.
2222
* Applying `MethodImplOptions.Async` to vararg methods is invalid.
2323

2424
_[Note: these rules operate before generic substitution, meaning that a method which only meets requirements after substitution would not be considered as valid.]_
2525

2626
Sync methods are all other methods.
2727

28-
Unlike sync methods, async methods support suspension. Suspension allows async methods to yield control flow back to their caller at certain well-defined suspension points, and resume execution of the remaining method at a later time or location, potentially on another thread.
28+
Unlike sync methods, async methods support suspension. Suspension allows async methods to yield control flow back to their caller at certain well-defined suspension points, and resume execution of the remaining method at a later time or location, potentially on another thread. Suspension points are where suspension may occur, but suspension is not required if all Task-like objects are completed.
2929

3030
Async methods also do not have matching return type conventions as sync methods. For sync methods, the stack should contain a value convertible to the stated return type before the `ret` instruction. For async methods, the stack should be empty in the case of `Task` or `ValueTask`, or the type argument in the case of `Task<T>` or `ValueTask<T>`.
3131

@@ -64,13 +64,12 @@ Async methods support suspension using one of the following methods:
6464

6565
These methods are only legal to call inside async methods. The `...AwaitAwaiter...` methods will have semantics analogous to the current `AsyncTaskMethodBuilder.AwaitOnCompleted/AwaitUnsafeOnCompleted` methods. After calling either method, it can be presumed that the task or awaiter has completed. The `Await` methods perform suspension like the `AwaitAwaiter...` methods, but are optimized for calling on the return value of a call to an async method. To achieve maximum performance, the IL sequence of two `call` instructions -- one to the async method and immediately one to the `Await` method -- should be preferred.
6666

67-
Only local variables which are "hoisted" may be used across suspension points. That is, only "hoisted" local variables will have their state preserved after returning from a suspension. On methods with the `localsinit` flag set, non-"hoisted" local variables will be initialized to their default value when resuming from suspension. Otherwise, these variables will have an undefined value. To identify "hoisted" local variables, they must have an optional custom modifier to the `System.Runtime.CompilerServices.HoistedLocal` class, which will be a new .NET runtime API. This custom modifier must be the last custom modifier on the variable. It is invalid for by-ref variables, or variables with a by-ref-like type, to be marked hoisted. Hoisted local variables are stored in managed memory and cannot be converted to unmanaged pointers without explicit pinning.
68-
The code generator is free to ignore the `HoistedLocal` modifier if it can prove that this makes no observable difference in the execution of the generated program. This can be observable in diagnostics since it may mean the value of a local with the `HoistedLocal` modifier will not be available after certain suspension points.
67+
Local variables used across suspension points are considered "hoisted." That is, only "hoisted" local variables will have their state preserved after returning from a suspension. By-ref variables may not be hoisted across suspension points, and any read of a by-ref variable after a suspension point will produce null. Structs containing by-ref variables will also not be hoisted across suspension points and will have their default value after a suspension point.
68+
In the same way, pinning locals may not be "hoisted" across suspension points and will have `null` value after a suspension point.
6969

7070
Async methods have some temporary restrictions with may be lifted later:
7171
* The `tail` prefix is forbidden
7272
* Usage of the `localloc` instruction is forbidden
73-
* Pinning locals may not be marked `HoistedLocal`
7473

7574
Other restrictions are likely to be permanent, including
7675
* By-ref locals cannot be hoisted across suspension points

docs/workflow/building/coreclr/ios.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cross Compilation for iOS Simulator on macOS
1+
# Cross Compilation for iOS/tvOS Simulator on macOS
22

33
## Requirements
44

@@ -9,7 +9,7 @@ Build requirements are the same as for building native CoreCLR on macOS. iPhone
99
Build the runtime pack and tools with
1010

1111
```
12-
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
12+
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
1313
```
1414

1515
## Running the sample iOS app

src/coreclr/CMakeLists.txt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ if(CLR_CMAKE_HOST_UNIX)
105105
add_linker_flag(-Wl,-z,notext)
106106
endif()
107107

108-
if(NOT CLR_CMAKE_HOST_TVOS)
109-
add_subdirectory(pal)
110-
endif()
108+
add_subdirectory(pal)
109+
111110
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
112111
add_subdirectory(hosts)
113112
endif()
@@ -135,9 +134,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
135134
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
136135
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)
137136

138-
if(NOT CLR_CMAKE_HOST_TVOS)
139-
add_subdirectory(debug/debug-pal)
140-
endif()
137+
add_subdirectory(debug/debug-pal)
141138

142139
add_subdirectory(minipal)
143140

@@ -273,36 +270,34 @@ if(CLR_CMAKE_HOST_UNIX)
273270
add_subdirectory(nativeresources)
274271
endif(CLR_CMAKE_HOST_UNIX)
275272

276-
if(NOT CLR_CMAKE_HOST_TVOS)
277-
add_subdirectory(utilcode)
278-
add_subdirectory(inc)
273+
add_subdirectory(utilcode)
274+
add_subdirectory(inc)
279275

280-
if (CLR_CMAKE_BUILD_TOOLS)
281-
add_subdirectory(ilasm)
282-
add_subdirectory(ildasm)
283-
endif(CLR_CMAKE_BUILD_TOOLS)
284-
add_subdirectory(gcinfo)
276+
if (CLR_CMAKE_BUILD_TOOLS)
277+
add_subdirectory(ilasm)
278+
add_subdirectory(ildasm)
279+
endif(CLR_CMAKE_BUILD_TOOLS)
280+
add_subdirectory(gcinfo)
285281

286-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
287-
add_subdirectory(jit)
288-
endif()
282+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
283+
add_subdirectory(jit)
284+
endif()
289285

290-
add_subdirectory(vm)
291-
add_subdirectory(md)
286+
add_subdirectory(vm)
287+
add_subdirectory(md)
292288

293-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
294-
add_subdirectory(debug)
295-
endif()
289+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
290+
add_subdirectory(debug)
291+
endif()
296292

297-
add_subdirectory(binder)
298-
add_subdirectory(classlibnative)
299-
add_subdirectory(dlls)
293+
add_subdirectory(binder)
294+
add_subdirectory(classlibnative)
295+
add_subdirectory(dlls)
300296

301-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
302-
add_subdirectory(unwinder)
303-
add_subdirectory(interop)
304-
endif()
305-
endif(NOT CLR_CMAKE_HOST_TVOS)
297+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
298+
add_subdirectory(unwinder)
299+
add_subdirectory(interop)
300+
endif()
306301

307302
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
308303
add_subdirectory(tools)

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ endif(CLR_CMAKE_TARGET_WIN32)
228228

229229
# add the install targets
230230
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
231-
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
231+
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS)
232232
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
233233
endif()
234234

src/coreclr/pal/src/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#cmakedefine01 HAVE__LWP_SELF
4646
#cmakedefine01 HAVE_MACH_THREADS
4747
#cmakedefine01 HAVE_MACH_EXCEPTIONS
48+
#cmakedefine01 HAVE_SIGALTSTACK
4849
#cmakedefine01 HAVE_VM_ALLOCATE
4950
#cmakedefine01 HAVE_VM_READ
5051
#cmakedefine01 HAVE_DIRECTIO

src/coreclr/pal/src/configure.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,20 @@ check_function_exists(statvfs HAVE_STATVFS)
120120
check_function_exists(thread_self HAVE_THREAD_SELF)
121121
check_function_exists(_lwp_self HAVE__LWP_SELF)
122122
check_function_exists(pthread_mach_thread_np HAVE_MACH_THREADS)
123-
check_function_exists(thread_set_exception_ports HAVE_MACH_EXCEPTIONS)
123+
check_cxx_source_compiles("
124+
#include <mach/mach.h>
125+
int main(int argc, char **argv) {
126+
static mach_port_name_t port;
127+
thread_set_exception_ports(mach_thread_self(), EXC_MASK_BAD_ACCESS, port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE);
128+
return 0;
129+
}" HAVE_MACH_EXCEPTIONS)
130+
check_cxx_source_compiles("
131+
#include <signal.h>
132+
#include <stdlib.h>
133+
int main(int argc, char **argv) {
134+
sigaltstack(NULL, NULL);
135+
return 0;
136+
}" HAVE_SIGALTSTACK)
124137
check_function_exists(vm_allocate HAVE_VM_ALLOCATE)
125138
check_function_exists(vm_read HAVE_VM_READ)
126139
check_function_exists(directio HAVE_DIRECTIO)

src/coreclr/pal/src/debug/debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const BOOL DBG_DETACH = FALSE;
8888
#endif
8989
static const char PAL_OUTPUTDEBUGSTRING[] = "PAL_OUTPUTDEBUGSTRING";
9090

91-
#ifdef _DEBUG
91+
#if defined(_DEBUG) && !defined(TARGET_IOS) && !defined(TARGET_TVOS)
9292
#define ENABLE_RUN_ON_DEBUG_BREAK 1
9393
#endif // _DEBUG
9494

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ PAL_ERROR SEHEnable(CPalThread *pthrCurrent)
304304
{
305305
#if HAVE_MACH_EXCEPTIONS
306306
return pthrCurrent->EnableMachExceptions();
307-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__wasm__)
307+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__) || defined(__wasm__)
308308
return NO_ERROR;
309-
#else// HAVE_MACH_EXCEPTIONS
309+
#else // HAVE_MACH_EXCEPTIONS
310310
#error not yet implemented
311311
#endif // HAVE_MACH_EXCEPTIONS
312312
}
@@ -329,7 +329,7 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent)
329329
{
330330
#if HAVE_MACH_EXCEPTIONS
331331
return pthrCurrent->DisableMachExceptions();
332-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__wasm__)
332+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__) || defined(__wasm__)
333333
return NO_ERROR;
334334
#else // HAVE_MACH_EXCEPTIONS
335335
#error not yet implemented

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags)
188188
handle_signal(SIGINT, sigint_handler, &g_previous_sigint, 0 /* additionalFlags */, true /* skipIgnored */);
189189
handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit, 0 /* additionalFlags */, true /* skipIgnored */);
190190

191-
#if HAVE_MACH_EXCEPTIONS
191+
#if HAVE_MACH_EXCEPTIONS || !HAVE_SIGALTSTACK
192192
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv);
193193
#else
194194
handle_signal(SIGTRAP, sigtrap_handler, &g_previous_sigtrap);
@@ -569,6 +569,7 @@ extern "C" void signal_handler_worker(int code, siginfo_t *siginfo, void *contex
569569
RtlRestoreContext(&returnPoint->context, NULL);
570570
}
571571

572+
#if HAVE_SIGALTSTACK
572573
/*++
573574
Function :
574575
SwitchStackAndExecuteHandler
@@ -609,6 +610,7 @@ static bool SwitchStackAndExecuteHandler(int code, siginfo_t *siginfo, void *con
609610

610611
return pReturnPoint->returnFromHandler;
611612
}
613+
#endif
612614

613615
#endif // !HAVE_MACH_EXCEPTIONS
614616

@@ -644,6 +646,10 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
644646
{
645647
if (GetCurrentPalThread())
646648
{
649+
#if defined(TARGET_TVOS)
650+
(void)!write(STDERR_FILENO, StackOverflowMessage, sizeof(StackOverflowMessage) - 1);
651+
PROCAbort(SIGSEGV, siginfo);
652+
#else // TARGET_TVOS
647653
size_t handlerStackTop = __sync_val_compare_and_swap((size_t*)&g_stackOverflowHandlerStack, (size_t)g_stackOverflowHandlerStack, 0);
648654
if (handlerStackTop == 0)
649655
{
@@ -672,6 +678,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
672678
PROCAbort(SIGSEGV, siginfo);
673679
}
674680
(void)!write(STDERR_FILENO, StackOverflowHandlerReturnedMessage, sizeof(StackOverflowHandlerReturnedMessage) - 1);
681+
#endif // TARGET_TVOS
675682
}
676683
else
677684
{
@@ -686,6 +693,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
686693
// Now that we know the SIGSEGV didn't happen due to a stack overflow, execute the common
687694
// hardware signal handler on the original stack.
688695

696+
#if HAVE_SIGALTSTACK
689697
if (GetCurrentPalThread() && IsRunningOnAlternateStack(context))
690698
{
691699
if (SwitchStackAndExecuteHandler(code, siginfo, context, 0 /* sp */)) // sp == 0 indicates execution on the original stack
@@ -694,6 +702,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
694702
}
695703
}
696704
else
705+
#endif
697706
{
698707
// The code flow gets here when the signal handler is not running on an alternate stack or when it wasn't created
699708
// by coreclr. In both cases, we execute the common_signal_handler directly.

src/coreclr/pal/src/include/pal/thread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ namespace CorUnix
572572
m_pNext = pNext;
573573
};
574574

575-
#if !HAVE_MACH_EXCEPTIONS
575+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
576576
BOOL
577577
EnsureSignalAlternateStack(
578578
void

src/coreclr/pal/src/init/sxs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ AllocatePalThread(CPalThread **ppThread)
6464
goto exit;
6565
}
6666

67-
#if !HAVE_MACH_EXCEPTIONS
67+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
6868
// Ensure alternate stack for SIGSEGV handling. Our SIGSEGV handler is set to
6969
// run on an alternate stack and the stack needs to be allocated per thread.
7070
if (!pThread->EnsureSignalAlternateStack())

src/coreclr/pal/src/thread/process.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ CorUnix::InternalCreateProcess(
513513
LPPROCESS_INFORMATION lpProcessInformation
514514
)
515515
{
516+
#ifdef TARGET_TVOS
517+
return ERROR_NOT_SUPPORTED;
518+
#else
516519
PAL_ERROR palError = NO_ERROR;
517520
IPalObject *pobjProcess = NULL;
518521
IPalObject *pobjProcessRegistered = NULL;
@@ -1049,6 +1052,7 @@ CorUnix::InternalCreateProcess(
10491052
}
10501053

10511054
return palError;
1055+
#endif // !TARGET_TVOS
10521056
}
10531057

10541058

@@ -2180,7 +2184,7 @@ PROCCreateCrashDump(
21802184
INT cbErrorMessageBuffer,
21812185
bool serialize)
21822186
{
2183-
#if defined(TARGET_IOS)
2187+
#if defined(TARGET_IOS) || defined(TARGET_TVOS)
21842188
return FALSE;
21852189
#else
21862190
_ASSERTE(argv.size() > 0);
@@ -2310,7 +2314,7 @@ PROCCreateCrashDump(
23102314
}
23112315
}
23122316
return true;
2313-
#endif // !TARGET_IOS
2317+
#endif // !TARGET_IOS && !TARGET_TVOS
23142318
}
23152319

23162320
/*++

src/coreclr/pal/src/thread/thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void InternalEndCurrentThreadWrapper(void *arg)
134134
will lock its own critical section */
135135
LOADCallDllMain(DLL_THREAD_DETACH, NULL);
136136

137-
#if !HAVE_MACH_EXCEPTIONS
137+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
138138
pThread->FreeSignalAlternateStack();
139139
#endif // !HAVE_MACH_EXCEPTIONS
140140

@@ -1552,7 +1552,7 @@ CPalThread::ThreadEntry(
15521552
}
15531553
#endif // HAVE_SCHED_GETAFFINITY && HAVE_SCHED_SETAFFINITY
15541554

1555-
#if !HAVE_MACH_EXCEPTIONS
1555+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
15561556
if (!pThread->EnsureSignalAlternateStack())
15571557
{
15581558
ASSERT("Cannot allocate alternate stack for SIGSEGV!\n");
@@ -2275,7 +2275,7 @@ CPalThread::WaitForStartStatus(
22752275
return m_fStartStatus;
22762276
}
22772277

2278-
#if !HAVE_MACH_EXCEPTIONS
2278+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
22792279
/*++
22802280
Function :
22812281
EnsureSignalAlternateStack

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ internal static int UpRefEvpPkey(SafeEvpPKeyHandle handle)
4747
[LibraryImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPKeyType")]
4848
internal static partial EvpAlgorithmId EvpPKeyType(SafeEvpPKeyHandle handle);
4949

50+
[LibraryImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPKeyFamily")]
51+
internal static partial EvpAlgorithmFamilyId EvpPKeyFamily(SafeEvpPKeyHandle handle);
52+
5053
[LibraryImport(Libraries.CryptoNative)]
5154
private static unsafe partial SafeEvpPKeyHandle CryptoNative_DecodeSubjectPublicKeyInfo(
5255
byte* buf,
@@ -327,5 +330,14 @@ internal enum EvpAlgorithmId
327330
DSA = 116,
328331
ECC = 408,
329332
}
333+
334+
internal enum EvpAlgorithmFamilyId
335+
{
336+
Unknown = 0,
337+
RSA = 1,
338+
DSA = 2,
339+
ECC = 3,
340+
MLKem = 4,
341+
}
330342
}
331343
}

0 commit comments

Comments
 (0)