I'm filing this bug on behalf of someone else who understands the issue better than I, so I'll try to give the relevant info but can get more if necessary. I asked for a brief description: "When SIGSEGV is delivered due to a page fault, freebsd sets mc_trapno sigcontext member to 0xc, as if it was a stack fault. But mc_addr and mc_err are the correct values corresponding to a page fault (for stack fault they'd be entirely different), so simply changing mc_trapno from 0xc to 0xe by hands, allows the JIT to work. This means the bug is very simple: freebsd just corrupts the mc_trapno value somehow. If it be something more complex, like a real stack fault in between, then simply fixing up the mc_trapno would not help, but it does." Here is a test case: https://github.com/dosemu2/dosemu2/commit/180184d2efa8f80db60330f823cfa1bc9b9e40f2
This is tickling some brain cell... IIRC, we have a different internal mapping of fault values for some historical reason. I vaguely recall running into this with qemu-user-static. Let's start with kib, maybe.
mc_trapno values are T_XXX from machine/trap.h. In particular, for the page fault, value is #define T_PAGEFLT 12 /* page fault */ This is *not* the CPU fault number in IDT.
Linux uses the x86 fault number FreeBSD uses T_FAULT we did hit this difference in bsd-user