Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrCdacSubset=true</ClrRuntimeBuildSubsets>
</PropertyGroup>

<PropertyGroup Condition="$(_subset.Contains('+clr.nativeaotruntime+')) and '$(NativeAotSupported)' == 'true'">
<PropertyGroup Condition="$(_subset.Contains('+clr.nativeaotruntime+'))">
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrNativeAotSubset=true</ClrRuntimeBuildSubsets>
</PropertyGroup>

Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ if ((NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) OR CLR_CROSS_CO
endif ()

if(NOT CLR_CROSS_COMPONENTS_BUILD)
if(NOT CLR_CMAKE_HOST_ARCH_WASM)
add_subdirectory(nativeaot)
endif()
add_subdirectory(nativeaot)
endif(NOT CLR_CROSS_COMPONENTS_BUILD)

# Above projects do not build with these compile options
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/gc/env/gcenv.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter);
#define MemoryBarrier __sync_synchronize
#endif // __riscv

#ifdef HOST_BROWSER
#ifdef HOST_WASM
#define YieldProcessor()
#define MemoryBarrier __sync_synchronize
#endif // HOST_BROWSER
#endif // HOST_WASM

#endif // _MSC_VER

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/daccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ inline void DACCOP_IGNORE(DacCopWarningCode code, const char * szReasonString)
typedef uintptr_t TADDR;

typedef void* PTR_VOID;
typedef LPVOID* PTR_PTR_VOID;
typedef PTR_VOID* PTR_PTR_VOID;
typedef const void* PTR_CVOID;

#define DPTR(type) type*
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Runtime/AsmOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ ASM_OFFSET( 0, 0, Thread, m_eeAllocContext)
ASM_OFFSET( 2c, 40, Thread, m_ThreadStateFlags)
ASM_OFFSET( 30, 48, Thread, m_pTransitionFrame)
ASM_OFFSET( 34, 50, Thread, m_pDeferredTransitionFrame)
#ifdef FEATURE_HIJACK
ASM_OFFSET( 40, 68, Thread, m_ppvHijackedReturnAddressLocation)
ASM_OFFSET( 44, 70, Thread, m_pvHijackedReturnAddress)
#endif // FEATURE_HIJACK
#if defined(TARGET_ARM64)
ASM_OFFSET( 48, 78, Thread, m_pSpForPacSign)
ASM_OFFSET( 4c, 80, Thread, m_pExInfoStackHead)
#elif defined(TARGET_WASM)
ASM_OFFSET( 40, FF, Thread, m_pExInfoStackHead)
#else
ASM_OFFSET( 48, 78, Thread, m_pExInfoStackHead)
#endif
Expand Down
18 changes: 14 additions & 4 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(GC_WKS_SVR_SOURCES
)

set(COMMON_RUNTIME_SOURCES
AsmOffsetsVerify.cpp
rhassert.cpp
${RUNTIME_DIR}/MiscNativeHelpers.cpp
Crst.cpp
Expand Down Expand Up @@ -89,7 +90,6 @@ set(STANDALONEGC_ENABLED_SOURCES
)

set(FULL_RUNTIME_SOURCES
AsmOffsetsVerify.cpp
ThunksMapping.cpp
)

Expand Down Expand Up @@ -200,12 +200,22 @@ else()
${RUNTIME_DIR}/unix/CLREventBase.cpp
unix/PalUnix.cpp
unix/PalCreateDump.cpp
${GC_DIR}/unix/gcenv.unix.cpp
${GC_DIR}/unix/numasupport.cpp
${GC_DIR}/unix/events.cpp
${GC_DIR}/unix/cgroup.cpp
)

if(CLR_CMAKE_TARGET_ARCH_WASM)
list(APPEND COMMON_RUNTIME_SOURCES
${GC_DIR}/wasm/gcenv.cpp
)
include_directories(${GC_DIR}/unix)
else()
list(APPEND COMMON_RUNTIME_SOURCES
${GC_DIR}/unix/gcenv.unix.cpp
${GC_DIR}/unix/numasupport.cpp
${GC_DIR}/unix/cgroup.cpp
)
endif()

list(APPEND FULL_RUNTIME_SOURCES
unix/cgroupcpu.cpp
unix/HardwareExceptions.cpp
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ project(PortableRuntime)

add_definitions(-DFEATURE_PORTABLE_HELPERS)

add_library(PortableRuntime STATIC ${COMMON_RUNTIME_SOURCES} ${PORTABLE_RUNTIME_SOURCES})
add_library(Runtime.GC.Workstation OBJECT ${GC_WKS_SVR_SOURCES})
set_target_properties(Runtime.GC.Workstation PROPERTIES UNITY_BUILD ON UNITY_BUILD_BATCH_SIZE 0)

add_library(PortableRuntime STATIC
${COMMON_RUNTIME_SOURCES}
${PORTABLE_RUNTIME_SOURCES}
$<TARGET_OBJECTS:Runtime.GC.Workstation>)
target_link_libraries(PortableRuntime PRIVATE aotminipal)

add_library(standalonegc-disabled STATIC ${STANDALONEGC_DISABLED_SOURCES})

# Get the current list of definitions
get_compile_definitions(DEFINITIONS)
set(ASM_OFFSETS_CSPP ${NATIVEAOT_RUNTIME_DIR}/../Runtime.Base/src/AsmOffsets.cspp)
Expand All @@ -29,9 +37,10 @@ endif()
add_custom_command(
# The AsmOffsetsPortable.cs is consumed later by the managed build
TARGET PortableRuntime
POST_BUILD
COMMAND ${CMAKE_CXX_COMPILER} ${COMPILER_LANGUAGE} ${DEFINITIONS} ${PREPROCESSOR_FLAGS} -I"${ARCH_SOURCES_DIR}" "${ASM_OFFSETS_CSPP}" >"${CMAKE_CURRENT_BINARY_DIR}/AsmOffsetsPortable.cs"
DEPENDS "${NATIVEAOT_RUNTIME_DIR}/AsmOffsets.cpp" "${NATIVEAOT_RUNTIME_DIR}/AsmOffsets.h"
)

install_static_library(PortableRuntime aotsdk nativeaot)
install_static_library(standalonegc-disabled aotsdk nativeaot)
install_static_library(aotminipal aotsdk nativeaot)
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ void StackFrameIterator::InternalInit(Thread * pThreadToWalk, PTR_PAL_LIMITED_CO
// thunks report a conservative range).
void StackFrameIterator::InternalInit(Thread * pThreadToWalk, NATIVE_CONTEXT* pCtx, uint32_t dwFlags)
{
#ifdef HOST_WASM
PORTABILITY_ASSERT("StackFrameIterator::InternalInit with native context");
#else
ASSERT((dwFlags & MethodStateCalculated) == 0);

EnterInitialInvalidState(pThreadToWalk);
Expand Down Expand Up @@ -854,6 +857,7 @@ void StackFrameIterator::InternalInit(Thread * pThreadToWalk, NATIVE_CONTEXT* pC

// adjust for thunks, if needed
EnsureInitializedToManagedFrame();
#endif // HOST_WASM
}

void StackFrameIterator::EnsureInitializedToManagedFrame()
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/nativeaot/Runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void Thread::Destroy()
extern OBJECTREF * t_pShadowStackTop;
extern OBJECTREF * t_pShadowStackBottom;

void GcScanWasmShadowStack(void * pfnEnumCallback, void * pvCallbackData)
void GcScanWasmShadowStack(ScanFunc* pfnEnumCallback, ScanContext* pvCallbackData)
{
// Wasm does not permit iteration of stack frames so is uses a shadow stack instead
EnumGcRefsInRegionConservatively(t_pShadowStackBottom, t_pShadowStackTop, pfnEnumCallback, pvCallbackData);
Expand Down Expand Up @@ -472,6 +472,7 @@ bool Thread::GcScanRoots(GcScanRootsCallbackFunc * pfnEnumCallback, void * token
}
#endif //DACCESS_COMPILE

#ifndef TARGET_WASM
Comment thread
MichalStrehovsky marked this conversation as resolved.
void Thread::GcScanRootsWorker(ScanFunc * pfnEnumCallback, ScanContext * pvCallbackData, StackFrameIterator & frameIterator)
{
PTR_OBJECTREF pHijackedReturnValue = NULL;
Expand Down Expand Up @@ -594,6 +595,7 @@ void Thread::GcScanRootsWorker(ScanFunc * pfnEnumCallback, ScanContext * pvCallb
}
}
}
#endif // !TARGET_WASM

#ifndef DACCESS_COMPILE

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/NativeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef __NATIVE_CONTEXT_H__
#define __NATIVE_CONTEXT_H__

#ifndef HOST_WASM

#if HAVE_UCONTEXT_H
#include <ucontext.h>
#else
Expand Down Expand Up @@ -277,4 +279,5 @@ struct NATIVE_CONTEXT
#endif // TARGET_ARM
};

#endif // !HOST_WASM
#endif // __NATIVE_CONTEXT_H__
20 changes: 11 additions & 9 deletions src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <errno.h>
#include <sal.h>
#include "config.h"
#include "PalCreateDump.h"
#include <pthread.h>
#include <string.h>
#include <assert.h>
Expand All @@ -15,12 +16,13 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#if HAVE_PRCTL_H
#include <sys/prctl.h>
#include <sys/syscall.h>
#endif
#ifndef HOST_WASM
#include <sys/wait.h>
#endif
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -50,7 +52,7 @@
#include <minipal/thread.h>
#include <generatedumpflags.h>

#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)

// Crash dump generating program arguments. MAX_ARGV_ENTRIES is the max number
// of entries if every createdump option/argument is passed.
Expand Down Expand Up @@ -345,7 +347,7 @@ CreateCrashDump(
return true;
}

#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)

// Helper function to prevent compiler from optimizing away a variable
#if defined(__llvm__)
Expand Down Expand Up @@ -380,7 +382,7 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, void*
// Preserve context pointer to prevent optimization
DoNotOptimize(&context);

#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)
// If enabled, launch the create minidump utility and wait until it completes
if (g_argvCreateDump[0] != nullptr)
{
Expand Down Expand Up @@ -466,7 +468,7 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, void*
free(signalAddressArg);
free(exceptionRecordArg);
}
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)
}

void
Expand Down Expand Up @@ -510,7 +512,7 @@ PalGenerateCoreDump(
char* errorMessageBuffer,
int cbErrorMessageBuffer)
{
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)
const char* argvCreateDump[MAX_ARGV_ENTRIES];
if (dumpType <= DumpTypeUnknown || dumpType > DumpTypeMax)
{
Expand All @@ -528,7 +530,7 @@ PalGenerateCoreDump(
return result;
#else
return false;
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)
}

/*++
Expand All @@ -547,7 +549,7 @@ Return
bool
PalCreateDumpInitialize()
{
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)
bool enabled = false;
RhConfig::Environment::TryGetBooleanValue("DbgEnableMiniDump", &enabled);
if (enabled)
Expand Down Expand Up @@ -657,7 +659,7 @@ PalCreateDumpInitialize()
return false;
}
}
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
#endif // !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS) && !defined(HOST_WASM)

return true;
}
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/unix/PalCreateDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <signal.h>
#include "UnixSignals.h"

extern bool PalCreateDumpInitialize();
extern void PalCreateCrashDumpIfEnabled();
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void PalGetPDBInfo(HANDLE hOsHandle, GUID * pGuidSignature, _Out_ uint32_t * pdw
#endif
}

#ifdef FEATURE_HIJACK
static void UnmaskActivationSignal()
{
sigset_t signal_set;
Expand All @@ -194,6 +195,7 @@ static void UnmaskActivationSignal()
int sigmaskRet = pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
_ASSERTE(sigmaskRet == 0);
}
#endif // FEATURE_HIJACK

// This functions configures behavior of the signals that are not
// related to hardware exception handling.
Expand Down Expand Up @@ -383,7 +385,9 @@ void PalAttachThread(void* thread)
tls_destructionMonitor.SetThread(thread);
#endif

#ifdef FEATURE_HIJACK
UnmaskActivationSignal();
#endif // FEATURE_HIJACK
}

#if !defined(FEATURE_PORTABLE_HELPERS) && !defined(FEATURE_RX_THUNKS)
Expand Down Expand Up @@ -703,7 +707,7 @@ void PalFlushInstructionCache(_In_ void* pAddress, size_t size)
}
#elif (defined(HOST_MACCATALYST) || defined(HOST_IOS) || defined(HOST_TVOS)) && defined(HOST_ARM64)
sys_icache_invalidate (pAddress, size);
#else
#elif !defined(HOST_WASM)
__builtin___clear_cache((char *)pAddress, (char *)pAddress + size);
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/UnixSignals.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include <signal.h>

#ifdef TARGET_WASI
struct siginfo_t;
#endif // TARGET_WASI

#ifdef SIGRTMIN
#define INJECT_ACTIVATION_SIGNAL SIGRTMIN
#else
Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/nativeaot/Runtime/wasm/AsmOffsetsCpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
// This file is used by AsmOffsets.h to validate that our
// assembly-code offsets always match their C++ counterparts.
//
// NOTE: the offsets MUST be in hex notation WITHOUT the 0x prefix

PLAT_ASM_SIZEOF(98, ExInfo)
PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo)
PLAT_ASM_OFFSET(4, ExInfo, m_pExContext)
PLAT_ASM_OFFSET(8, ExInfo, m_exception)
PLAT_ASM_OFFSET(0c, ExInfo, m_kind)
PLAT_ASM_OFFSET(0d, ExInfo, m_passNumber)
PLAT_ASM_OFFSET(10, ExInfo, m_idxCurClause)
PLAT_ASM_OFFSET(14, ExInfo, m_frameIter)
PLAT_ASM_OFFSET(94, ExInfo, m_notifyDebuggerSP)

PLAT_ASM_SIZEOF(80, StackFrameIterator)
PLAT_ASM_OFFSET(08, StackFrameIterator, m_FramePointer)
PLAT_ASM_OFFSET(0c, StackFrameIterator, m_ControlPC)
PLAT_ASM_OFFSET(10, StackFrameIterator, m_RegDisplay)
PLAT_ASM_OFFSET(78, StackFrameIterator, m_OriginalControlPC)
PLAT_ASM_OFFSET(7c, StackFrameIterator, m_pPreviousTransitionFrame)

PLAT_ASM_SIZEOF(4, PAL_LIMITED_CONTEXT)
PLAT_ASM_OFFSET(0, PAL_LIMITED_CONTEXT, IP)

PLAT_ASM_SIZEOF(8, REGDISPLAY)
PLAT_ASM_OFFSET(0, REGDISPLAY, SP)
Loading