Skip to content

Commit

Permalink
For now
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Feb 5, 2025
1 parent be6a3e7 commit 1f6ddc2
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 16 deletions.
24 changes: 22 additions & 2 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,9 @@ ExitProcess(
else
{
WARN("thread re-called ExitProcess\n");
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE);
}
}
Expand All @@ -1177,6 +1180,9 @@ ExitProcess(
*/
if (PALInitLock() && PALIsInitialized())
{
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE);

/* Should not get here, because we terminate the current process */
Expand Down Expand Up @@ -1214,7 +1220,9 @@ TerminateProcess(

PERF_ENTRY(TerminateProcess);
ENTRY("TerminateProcess(hProcess=%p, uExitCode=%u)\n",hProcess, uExitCode );

#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
ret = PROCEndProcess(hProcess, uExitCode, TRUE);

LOGEXIT("TerminateProcess returns BOOL %d\n", ret);
Expand All @@ -1239,6 +1247,9 @@ RaiseFailFastException(
PERF_ENTRY(RaiseFailFastException);
ENTRY("RaiseFailFastException");

#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort at %s:%u", __FILE_NAME__, __LINE__);
#endif
TerminateCurrentProcessNoExit(TRUE);
for (;;) PROCAbort();

Expand Down Expand Up @@ -1318,6 +1329,9 @@ static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUncon
// (2) can invoke CrashReporter or produce a coredump, which is appropriate for TerminateProcess calls
// TerminationRequestHandlingRoutine in synchmanager.cpp sets the exit code to this special value. The
// Watson analyzer needs to know that the process was terminated with a SIGTERM.
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u", __FILE_NAME__, __LINE__);
#endif
PROCAbort(uExitCode == (128 + SIGTERM) ? SIGTERM : SIGABRT);
}
else
Expand Down Expand Up @@ -2620,12 +2634,18 @@ InitializeFlushProcessWriteBuffers()
#endif // TARGET_APPLE
}

#if defined(TARGET_ANDROID)
#define FATAL_ASSERT_PRINT(msg) __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u. %s", __FILE_NAME__, __LINE__, (msg))
#else
#define FATAL_ASSERT_PRINT(msg) fprintf(stderr, "FATAL ERROR: " msg)
#endif

#define FATAL_ASSERT(e, msg) \
do \
{ \
if (!(e)) \
{ \
fprintf(stderr, "FATAL ERROR: " msg); \
FATAL_ASSERT_PRINT(msg); \
PROCAbort(); \
} \
} \
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/vm/eepolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "dwreport.h"
#endif // !TARGET_UNIX

#if defined(TARGET_ANDROID)
#include <android/log.h>
#endif

#include "eventtrace.h"
#undef ExitProcess

Expand Down Expand Up @@ -58,7 +62,9 @@ void SafeExitProcess(UINT exitCode, ShutdownCompleteAction sca = SCA_ExitProcess
{
// disabled because if we fault in this code path we will trigger our Watson code
CONTRACT_VIOLATION(ThrowsViolation);

#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(exitCode);
}
else if (sca == SCA_ExitProcessWhenShutdownComplete)
Expand Down Expand Up @@ -737,7 +743,9 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalStackOverflow(EXCEPTION_POINTERS *pE
WatsonLastChance(pThread, pExceptionInfo,
(fTreatAsNativeUnhandledException == FALSE)? TypeOfReportedError::UnhandledException: TypeOfReportedError::NativeThreadUnhandledException);
}

#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(COR_E_STACKOVERFLOW);
UNREACHABLE();
}
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "virtualcallstub.h"
#include "typestring.h"

#if defined(TARGET_ANDROID)
#include <android/log.h>
#endif

#ifndef TARGET_UNIX
#include "dwreport.h"
#endif // !TARGET_UNIX
Expand Down Expand Up @@ -3944,6 +3948,9 @@ void CrashDumpAndTerminateProcess(UINT exitCode)
{
#ifdef HOST_WINDOWS
CreateCrashDumpIfEnabled(exitCode == COR_E_STACKOVERFLOW);
#endif
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
TerminateProcess(GetCurrentProcess(), exitCode);
}
Expand Down Expand Up @@ -4074,6 +4081,9 @@ LONG UserBreakpointFilter(EXCEPTION_POINTERS* pEP)
}

// Otherwise, we terminate the process.
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(STATUS_BREAKPOINT);

// Shouldn't get here ...
Expand Down
21 changes: 20 additions & 1 deletion src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "exinfo.h"
#include "configuration.h"

#if defined(TARGET_ANDROID)
#include <android/log.h>
#endif

#if defined(TARGET_X86)
#define USE_CURRENT_CONTEXT_IN_FILTER
#endif // TARGET_X86
Expand Down Expand Up @@ -4902,6 +4906,9 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT
LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers);
_ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH);
}
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(1);
}
else
Expand Down Expand Up @@ -4961,6 +4968,9 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT
LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers);
_ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH);
}
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(1);
UNREACHABLE();
}
Expand Down Expand Up @@ -5029,6 +5039,9 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar
// There are no managed frames on the stack, so the exception was not handled
LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers);
_ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH);
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(1);
UNREACHABLE();
}
Expand Down Expand Up @@ -5908,7 +5921,7 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo
}

pDispatcherContext->ControlPc = (UINT_PTR) GetIP(pDispatcherContext->ContextRecord);

#if defined(TARGET_ARM64)
// Since this routine is used to fixup contexts for async exceptions,
// clear the CONTEXT_UNWOUND_TO_CALL flag since, semantically, frames
Expand Down Expand Up @@ -8496,6 +8509,9 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk
GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException);
RaiseException(pExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pExInfo->m_ptrs.ExceptionRecord->NumberParameters, pExInfo->m_ptrs.ExceptionRecord->ExceptionInformation);
#else
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(pExInfo->m_ExceptionCode);
#endif
}
Expand Down Expand Up @@ -8615,6 +8631,9 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException);
RaiseException(pTopExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pTopExInfo->m_ptrs.ExceptionRecord->NumberParameters, pTopExInfo->m_ptrs.ExceptionRecord->ExceptionInformation);
#else
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(pTopExInfo->m_ExceptionCode);
#endif
}
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "dynamicinterfacecastable.h"
#include "comsynchronizable.h"

#if defined(TARGET_ANDROID)
#include <android/log.h>
#endif

#ifndef TARGET_UNIX
// Included for referencing __report_gsfailure
#include "process.h"
Expand Down Expand Up @@ -2016,7 +2020,9 @@ void DoJITFailFast ()
COR_E_EXECUTIONENGINE,
GetClrInstanceId());
}

#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__);
#endif
CrashDumpAndTerminateProcess(STATUS_STACK_BUFFER_OVERRUN);
#endif // !TARGET_UNIX
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

Expand Down Expand Up @@ -63,5 +64,15 @@ internal enum FileStatusFlags

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
internal static partial int LStat(string path, out FileStatus output);

[LibraryImport("log", EntryPoint="__android_log_write", StringMarshalling = StringMarshalling.Utf8, SetLastError = false)]
static partial void AndroidLog (int prio, string tag, string message);

internal static int LStatWrap(string path, out FileStatus output)
{
AndroidLog (4, "CoreCLR", $"LStat (\"{path}\"");
AndroidLog (4, "CoreCLR", new StackTrace (false).ToString ());
return LStat (path, out output);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix'">
<Reference Include="System.Collections.Immutable" />
<Reference Include="System.Reflection.Metadata" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
<Reference Include="System.Threading.ThreadPool" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Reference Include="System.Memory" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Overlapped" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Net.Primitives" />
<Reference Include="System.Net.Sockets" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Overlapped" />
<Reference Include="System.Threading.ThreadPool" />
<Reference Include="System.Diagnostics.StackTrace" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static bool FileExists(ReadOnlySpan<char> fullPath, out Interop.ErrorInf
// See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 for details.
fullPath = Path.TrimEndingDirectorySeparator(fullPath);

if (Interop.Sys.LStat(fullPath, out fileinfo) < 0)
if (Interop.Sys.LStatWrap(fullPath.ToString (), out fileinfo) < 0)
{
errorInfo = Interop.Sys.GetLastErrorInfo();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin
{
// Unix rename works in more cases, we limit to what is allowed by Windows File.Replace.
// These checks are not atomic, the file could change after a check was performed and before it is renamed.
Interop.CheckIo(Interop.Sys.LStat(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath);
Interop.CheckIo(Interop.Sys.LStatWrap(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath);

// Check source is not a directory.
if ((sourceStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
Expand All @@ -132,7 +132,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin
}

Interop.Sys.FileStatus destStat;
if (Interop.Sys.LStat(destFullPath, out destStat) == 0)
if (Interop.Sys.LStatWrap(destFullPath, out destStat) == 0)
{
// Check destination is not a directory.
if ((destStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
Expand Down Expand Up @@ -222,8 +222,8 @@ public static void MoveFile(string sourceFullPath, string destFullPath, bool ove
// link/unlink approach and generating any exceptional messages from there as necessary.

Interop.Sys.FileStatus sourceStat, destStat;
if (Interop.Sys.LStat(sourceFullPath, out sourceStat) == 0 && // source file exists
(Interop.Sys.LStat(destFullPath, out destStat) != 0 || // dest file does not exist
if (Interop.Sys.LStatWrap(sourceFullPath, out sourceStat) == 0 && // source file exists
(Interop.Sys.LStatWrap(destFullPath, out destStat) != 0 || // dest file does not exist
(sourceStat.Dev == destStat.Dev && // source and dest are on the same device
sourceStat.Ino == destStat.Ino)) && // source and dest are the same file on that device
Interop.Sys.Rename(sourceFullPath, destFullPath) == 0) // try the rename
Expand Down Expand Up @@ -411,12 +411,12 @@ private static void MoveDirectory(string sourceFullPath, string destFullPath, bo

// The destination must not exist (unless it is a case-sensitive rename).
// On Unix 'rename' will overwrite the destination file if it already exists, we need to manually check.
if (!isCaseSensitiveRename && Interop.Sys.LStat(destNoDirectorySeparator, out Interop.Sys.FileStatus destFileStatus) >= 0)
if (!isCaseSensitiveRename && Interop.Sys.LStatWrap(destNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus destFileStatus) >= 0)
{
// Maintain order of exceptions as on Windows.

// Throw if the source doesn't exist.
if (Interop.Sys.LStat(srcNoDirectorySeparator, out Interop.Sys.FileStatus sourceFileStatus) < 0)
if (Interop.Sys.LStatWrap(srcNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus sourceFileStatus) < 0)
{
throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceFullPath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class Path
// Checks if the given path is available for use.
private static bool ExistsCore(string fullPath, out bool isDirectory)
{
bool result = Interop.Sys.LStat(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS;
bool result = Interop.Sys.LStatWrap(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS;
isDirectory = result && (fileInfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR;

return result;
Expand Down
3 changes: 3 additions & 0 deletions src/native/libs/Common/pal_error_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ typedef enum

inline static int32_t ConvertErrorPlatformToPal(int32_t platformErrno)
{
#if defined(TARGET_ANDROID)
__android_log_print (ANDROID_LOG_INFO, "CoreCLR", "%s at %s:%d. platformErrno == %d", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, platformErrno);
#endif
switch (platformErrno)
{
case 0:
Expand Down
Loading

0 comments on commit 1f6ddc2

Please sign in to comment.