Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CoreCLR/tvOS build #111804

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/workflow/building/coreclr/ios.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cross Compilation for iOS Simulator on macOS
# Cross Compilation for iOS/tvOS Simulator on macOS

## Requirements

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

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

## Running the sample iOS app
Expand Down
41 changes: 18 additions & 23 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ if(CLR_CMAKE_HOST_UNIX)
add_linker_flag(-Wl,-z,notext)
endif()

if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(pal)
endif()
add_subdirectory(pal)

if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(hosts)
endif()
Expand Down Expand Up @@ -131,9 +130,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)

if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(debug/debug-pal)
endif()
add_subdirectory(debug/debug-pal)

add_subdirectory(minipal)

Expand Down Expand Up @@ -245,23 +242,21 @@ if(CLR_CMAKE_HOST_UNIX)
add_subdirectory(nativeresources)
endif(CLR_CMAKE_HOST_UNIX)

if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(utilcode)
add_subdirectory(inc)

add_subdirectory(ilasm)
add_subdirectory(ildasm)
add_subdirectory(gcinfo)
add_subdirectory(jit)
add_subdirectory(vm)
add_subdirectory(md)
add_subdirectory(debug)
add_subdirectory(binder)
add_subdirectory(classlibnative)
add_subdirectory(dlls)
add_subdirectory(unwinder)
add_subdirectory(interop)
endif()
add_subdirectory(utilcode)
add_subdirectory(inc)

add_subdirectory(ilasm)
add_subdirectory(ildasm)
add_subdirectory(gcinfo)
add_subdirectory(jit)
add_subdirectory(vm)
add_subdirectory(md)
add_subdirectory(debug)
add_subdirectory(binder)
add_subdirectory(classlibnative)
add_subdirectory(dlls)
add_subdirectory(unwinder)
add_subdirectory(interop)

if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(tools)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ endif(CLR_CMAKE_TARGET_WIN32)

# add the install targets
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS)
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
endif()

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#cmakedefine01 HAVE__LWP_SELF
#cmakedefine01 HAVE_MACH_THREADS
#cmakedefine01 HAVE_MACH_EXCEPTIONS
#cmakedefine01 HAVE_SIGALTSTACK
#cmakedefine01 HAVE_VM_ALLOCATE
#cmakedefine01 HAVE_VM_READ
#cmakedefine01 HAVE_DIRECTIO
Expand Down
14 changes: 13 additions & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,19 @@ check_function_exists(statvfs HAVE_STATVFS)
check_function_exists(thread_self HAVE_THREAD_SELF)
check_function_exists(_lwp_self HAVE__LWP_SELF)
check_function_exists(pthread_mach_thread_np HAVE_MACH_THREADS)
check_function_exists(thread_set_exception_ports HAVE_MACH_EXCEPTIONS)
check_cxx_source_compiles("
#import <mach/mach.h>
int main(int argc, char **argv) {
static mach_port_name_t port;
thread_set_exception_ports(mach_thread_self(), EXC_MASK_BAD_ACCESS, port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE);
return 0;
}" HAVE_MACH_EXCEPTIONS)
check_cxx_source_compiles("
#import <signal.h>
int main(int argc, char **argv) {
sigaltstack(NULL, NULL);
return 0;
}" HAVE_SIGALTSTACK)
check_function_exists(vm_allocate HAVE_VM_ALLOCATE)
check_function_exists(vm_read HAVE_VM_READ)
check_function_exists(directio HAVE_DIRECTIO)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const BOOL DBG_DETACH = FALSE;
#endif
static const char PAL_OUTPUTDEBUGSTRING[] = "PAL_OUTPUTDEBUGSTRING";

#ifdef _DEBUG
#if defined(_DEBUG) && !defined(TARGET_IOS) && !defined(TARGET_TVOS)
#define ENABLE_RUN_ON_DEBUG_BREAK 1
#endif // _DEBUG

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/pal/src/exception/seh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ PAL_ERROR SEHEnable(CPalThread *pthrCurrent)
{
#if HAVE_MACH_EXCEPTIONS
return pthrCurrent->EnableMachExceptions();
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__)
return NO_ERROR;
#else// HAVE_MACH_EXCEPTIONS
#error not yet implemented
Expand All @@ -329,7 +329,7 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent)
{
#if HAVE_MACH_EXCEPTIONS
return pthrCurrent->DisableMachExceptions();
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__)
return NO_ERROR;
#else // HAVE_MACH_EXCEPTIONS
#error not yet implemented
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags)
handle_signal(SIGINT, sigint_handler, &g_previous_sigint, 0 /* additionalFlags */, true /* skipIgnored */);
handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit, 0 /* additionalFlags */, true /* skipIgnored */);

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

#if HAVE_SIGALTSTACK
/*++
Function :
SwitchStackAndExecuteHandler
Expand Down Expand Up @@ -603,6 +604,7 @@ static bool SwitchStackAndExecuteHandler(int code, siginfo_t *siginfo, void *con

return pReturnPoint->returnFromHandler;
}
#endif

#endif // !HAVE_MACH_EXCEPTIONS

Expand Down Expand Up @@ -632,6 +634,10 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
{
if (GetCurrentPalThread())
{
#if defined(TARGET_TVOS)
(void)!write(STDERR_FILENO, StackOverflowMessage, sizeof(StackOverflowMessage) - 1);
PROCAbort(SIGSEGV, siginfo);
Comment on lines +638 to +639
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely needs to be resolved in a different way.

#else
size_t handlerStackTop = __sync_val_compare_and_swap((size_t*)&g_stackOverflowHandlerStack, (size_t)g_stackOverflowHandlerStack, 0);
if (handlerStackTop == 0)
{
Expand All @@ -648,6 +654,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
{
PROCAbort(SIGSEGV, siginfo);
}
#endif
}
else
{
Expand All @@ -662,6 +669,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
// Now that we know the SIGSEGV didn't happen due to a stack overflow, execute the common
// hardware signal handler on the original stack.

#if HAVE_SIGALTSTACK
if (GetCurrentPalThread() && IsRunningOnAlternateStack(context))
{
if (SwitchStackAndExecuteHandler(code, siginfo, context, 0 /* sp */)) // sp == 0 indicates execution on the original stack
Expand All @@ -670,6 +678,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
}
}
else
#endif
{
// The code flow gets here when the signal handler is not running on an alternate stack or when it wasn't created
// by coreclr. In both cases, we execute the common_signal_handler directly.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/include/pal/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ namespace CorUnix
m_pNext = pNext;
};

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
BOOL
EnsureSignalAlternateStack(
void
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/init/sxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ AllocatePalThread(CPalThread **ppThread)
goto exit;
}

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
// Ensure alternate stack for SIGSEGV handling. Our SIGSEGV handler is set to
// run on an alternate stack and the stack needs to be allocated per thread.
if (!pThread->EnsureSignalAlternateStack())
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ CorUnix::InternalCreateProcess(
LPPROCESS_INFORMATION lpProcessInformation
)
{
#ifdef TARGET_TVOS
return ERROR_NOT_SUPPORTED;
#else
PAL_ERROR palError = NO_ERROR;
IPalObject *pobjProcess = NULL;
IPalObject *pobjProcessRegistered = NULL;
Expand Down Expand Up @@ -1079,6 +1082,7 @@ CorUnix::InternalCreateProcess(
}

return palError;
#endif // !TARGET_TVOS
}


Expand Down Expand Up @@ -2210,7 +2214,7 @@ PROCCreateCrashDump(
INT cbErrorMessageBuffer,
bool serialize)
{
#if defined(TARGET_IOS)
#if defined(TARGET_IOS) || defined(TARGET_TVOS)
return FALSE;
#else
_ASSERTE(argv.size() > 0);
Expand Down Expand Up @@ -2340,7 +2344,7 @@ PROCCreateCrashDump(
}
}
return true;
#endif // !TARGET_IOS
#endif // !TARGET_IOS && !TARGET_TVOS
}

/*++
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/pal/src/thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void InternalEndCurrentThreadWrapper(void *arg)
will lock its own critical section */
LOADCallDllMain(DLL_THREAD_DETACH, NULL);

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
pThread->FreeSignalAlternateStack();
#endif // !HAVE_MACH_EXCEPTIONS

Expand Down Expand Up @@ -1552,7 +1552,7 @@ CPalThread::ThreadEntry(
}
#endif // HAVE_SCHED_GETAFFINITY && HAVE_SCHED_SETAFFINITY

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
if (!pThread->EnsureSignalAlternateStack())
{
ASSERT("Cannot allocate alternate stack for SIGSEGV!\n");
Expand Down Expand Up @@ -2275,7 +2275,7 @@ CPalThread::WaitForStartStatus(
return m_fStartStatus;
}

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
/*++
Function :
EnsureSignalAlternateStack
Expand Down
Loading