Bug 272149 - mc_trapno incorrectly reports 0xc instead of 0xe
Summary: mc_trapno incorrectly reports 0xc instead of 0xe
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-22 15:24 UTC by Patrick McMunn
Modified: 2023-06-22 17:24 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick McMunn 2023-06-22 15:24:59 UTC
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
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2023-06-22 15:45:42 UTC
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.
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2023-06-22 16:11:54 UTC
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.
Comment 3 Warner Losh freebsd_committer freebsd_triage 2023-06-22 17:24:50 UTC
Linux uses the x86 fault number
FreeBSD uses T_FAULT
we did hit this difference in bsd-user