[mono][jit] Emit profiler enter after jit attach; leave before detach (#44345)
* [jit] Emit profiler enter after jit attach; leave before detach
profiler enter code (such as mono_trace_enter_method) must not be
called before a thread attaches to the runtime - otherwise calls like
`mono_domain_get()` will return NULL unexpectedly and then crash.
When detaching, we should call the profiler leave code before the
detach, and suppress it on return.
Simple repro (that relies on pal_signal.c SignalHandlerLoop - which is
a background thread from System.Native that calls back into managed
when there's a SIGCHLD): compile and run this program with `MONO_ENV_OPTIONS=--trace`
```csharp
using System;
using System.Diagnostics;
namespace Repro
{
internal class Program
{
private static void Main(string[] args)
{
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "echo";
myProcess.StartInfo.Arguments = "hello from shell";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit();
}
Console.ReadKey ();
}
}
}
```