Skip to content

Commit

Permalink
[NativeAOT-LLVM] A couple of missing symbol fixes (#2482)
Browse files Browse the repository at this point in the history
* Sync LLVM exception code with upstream

* Fixup a couple missing symbol errors
  • Loading branch information
SingleAccretion authored Jan 14, 2024
1 parent b940795 commit 0cf1432
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<DefineConstants Condition="'$(FeatureObjCMarshal)' == 'true'">FEATURE_OBJCMARSHAL;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<FeaturePerfTracing>true</FeaturePerfTracing>
<FeaturePerfTracing Condition="'$(TargetsWasm)' != 'true'">true</FeaturePerfTracing>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(FeaturePerfTracing)' == 'true'">FEATURE_PERFTRACING;$(DefineConstants)</DefineConstants>
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartBackgroundWork(_In_ BackgroundCall
#ifdef HOST_WASM
// No threads, so we can't start one
RhFailFast();
#endif // HOST_WASM
return false;
#else // !HOST_WASM
pthread_attr_t attrs;

int st = pthread_attr_init(&attrs);
Expand Down Expand Up @@ -705,6 +706,7 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartBackgroundWork(_In_ BackgroundCall
ASSERT(st2 == 0);

return st == 0;
#endif // !HOST_WASM
}

REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(_In_ BackgroundCallback callback, _In_opt_ void* pCallbackContext)
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/nativeaot/Runtime/wasm/PalRedhawkWasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,8 @@ REDHAWK_PALEXPORT _Ret_maybenull_ _Post_writable_byte_size_(size) void* REDHAWK_
RhFailFast(); // Not supported per the above.
}

// The Unix version of this function allocates memory with 64K alignment, even as nothing needs such large
// alignments as of the writing of this comment. We do have to return something at least page-aligned.
const unsigned Alignment = 64 * 1024;
ASSERT(OS_PAGE_SIZE <= Alignment);

void* pRetVal;
if (posix_memalign(&pRetVal, Alignment, size) != 0)
if (posix_memalign(&pRetVal, OS_PAGE_SIZE, size) != 0)
{
return nullptr;
}
Expand Down
13 changes: 7 additions & 6 deletions src/coreclr/nativeaot/Runtime/wasm/wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ struct rlimit {
#define RLIM_INFINITY (~0ULL)
#define RLIMIT_AS 9

int getrlimit (int resource_id, struct rlimit * ret_rlimit);

void *mmap_wasi(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
int munmap_wasi(void *addr, size_t length);

inline int getrlimit (int resource_id, struct rlimit * ret_rlimit)
{
// TODO-LLVM: ifdef out the callers.
ret_rlimit->rlim_cur = RLIM_INFINITY;
ret_rlimit->rlim_max = RLIM_INFINITY;
return 0;
}
#endif // _WASI_H
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<Compile Include="System\Diagnostics\StackTrace.NativeAot.Browser.cs" Condition="'$(TargetOS)' == 'browser'" />
<Compile Include="System\Diagnostics\StackTrace.NativeAot.Wasi.cs" Condition="'$(TargetOS)' == 'wasi'" />
<Compile Include="System\Diagnostics\Eventing\EventPipe.NativeAot.cs" />
<Compile Include="System\Diagnostics\Eventing\NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs" />
<Compile Include="System\Diagnostics\Eventing\NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="System\Enum.NativeAot.cs" />
<Compile Include="System\Environment.NativeAot.cs" />
<Compile Include="System\GC.NativeAot.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public partial class Exception
// the full trace upfront, still, it is better than nothing.
private bool _dispatchStateRestored;

// TODO-LLVM: unify with "AppendExceptionStackFrame"; this is a partial copy.
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void InitializeExceptionStackFrameLLVM(object exception, int flags)
internal static unsafe void InitializeExceptionStackFrameLLVM(object exception, int flags)
{
// This method is called by the runtime's EH dispatch code and is not allowed to leak exceptions
// back into the dispatcher.
Expand All @@ -39,15 +40,22 @@ internal static void InitializeExceptionStackFrameLLVM(object exception, int fla
// 1. Don't clear if we're rethrowing with `throw;`.
// 2. Don't clear if we're throwing through ExceptionDispatchInfo.
// This is done through invoking RestoreDispatchState which sets "_dispatchStateRestored" followed by throwing normally using `throw ex;`.
if (isFirstRethrowFrame || ex._dispatchStateRestored)
return;
bool doSetTheStackTrace = !isFirstRethrowFrame && !ex._dispatchStateRestored;

// If out of memory, avoid any calls that may allocate. Otherwise, they may fail
// with another OutOfMemoryException, which may lead to infinite recursion.
if (ex == PreallocatedOutOfMemoryException.Instance)
return;
bool fatalOutOfMemory = ex == PreallocatedOutOfMemoryException.Instance;

if (doSetTheStackTrace && !fatalOutOfMemory)
ex._stackTraceString = new StackTrace(1).ToString().Replace("__", ".").Replace("_", ".");

#if FEATURE_PERFTRACING
string typeName = !fatalOutOfMemory ? ex.GetType().ToString() : "System.OutOfMemoryException";
string message = !fatalOutOfMemory ? ex.Message : "Insufficient memory to continue the execution of the program.";

ex._stackTraceString = new StackTrace(1).ToString().Replace("__", ".").Replace("_", ".");
fixed (char* exceptionTypeName = typeName, exceptionMessage = message)
Runtime.RuntimeImports.NativeRuntimeEventSource_LogExceptionThrown(exceptionTypeName, exceptionMessage, 0, ex.HResult);
#endif
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4058,7 +4058,7 @@ namespace JSInterop
{
internal static class InternalCalls
{
[DllImport("*", EntryPoint = "corert_wasm_invoke_js_unmarshalled")]
[DllImport("js", EntryPoint = "corert_wasm_invoke_js_unmarshalled")]
private static extern IntPtr InvokeJSUnmarshalledInternal(string js, int length, IntPtr p1, IntPtr p2, IntPtr p3, out string exception);

public static IntPtr InvokeJSUnmarshalled(out string exception, string js, IntPtr p1, IntPtr p2, IntPtr p3)
Expand Down
1 change: 1 addition & 0 deletions src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DirectPInvoke Include="ModuleName1!CommonWasmImportFunctionName" />
<DirectPInvoke Include="StaticModule1" />
<DirectPInvoke Include="StaticModule2" />
<DirectPInvoke Condition="'$(TargetsBrowser)' == 'true'" Include="js" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 0cf1432

Please sign in to comment.