runtime: [ARM32] System.AccessViolationException during exception handling

On ARM32, CoreCLR currently shows unexpected behavior for the following code:

using System;

namespace ConsoleApplication { public class Program {

  public static void Begin()      { Console.WriteLine("BEGIN"); }
  public static void AfterTry()   { Console.WriteLine("AFTER TRY"); }
  public static void AfterCalc()  { Console.WriteLine("AFTER CALC"); }
  public static void AfterCatch() { Console.WriteLine("AFTER CATCH"); }
  public static void End()        { Console.WriteLine("END"); }

  public static void Main(string[] args) {
    Begin();

    try {
      AfterTry();

      checked
      {
        byte src = 1 + byte.MaxValue / 2;

        AfterCalc();

        byte res = (byte)( src + src );
      }
    } catch (System.OverflowException) {
      AfterCatch();
    }

    End();
  }

} }

When running the above code, CoreCLR shows the following outputs:

BEGIN
AFTER TRY
AFTER CALC

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ConsoleApplication.Program.Main(String[] args)

The normal behavior would be the following:

BEGIN
AFTER TRY
AFTER CALC
AFTER CATCH
END

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

It seems that I found the solution. In WinContextToUnwindCursor, it creates a fresh local variable of type unw_context_t, and uses it to re-initialize unw_cursor_t.

I can execute the above code after I change the code to update existing unw_context_t.