Assembly routines break Windows 64-bit SEH

Niels Möller nisse at lysator.liu.se
Thu May 2 21:44:22 UTC 2019


"E. Madison Bray" <erik.m.bray at gmail.com> writes:

> This is because the assembly routines do not include the metadata that
> is necessary on 64-bit Windows [1] for stack unwinding to work
> properly during exception handling.

It would be a good start to document what's the bare minimum to get an
exception, like a null pointer dereference, to reliable cause a crash
saying what type of crash it was.

It somewhat surprising to me if stack-unwinding meta data is required
for non-recoverable exceptions. Say, you have an executable, and you
replace some part of the object code with random garbage data. It will
most likely crash in an unrecoverable way when you run it, and not carry
any consistent metadata. But it ought to be the operating system's
responsibility to report the failure, without assuming the executable is
particularly cooperative.

>  For example a
> `push_reg(<reg>)` macro would emit (on Windows 64):
>
>     push <reg>
>     .seh_pushreg <reg>
>
> whereas on all other platforms it would just emit the plain `push
> <reg>` instruction.  This part I believe is easy.

Sounds like reasonable approach, if we want to do this. But a bit
intrusive if there are lots of pushes.

> The trickiest part is just ensuring that some register is available to
> establish a frame pointer, when necessary (it doesn't necessarily have
> to be RBP; any nonvolatile register will do). 

We strive to not spend registers on frame pointers. I think most gmp
assembly functions are leaf functions. mpn_divrem_1 is an unusual case.
And the mpn_invert function it calls is unlikely to crash for any input;
I don't see any way it can crash, except if the object code is corrupted
or the relocation for mpn_invert_limb_table or the function itself is
somehow buggy and makes it point into nowhere.

I also wonder if any other architectures (ARM?) needs anything similar?

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-bugs mailing list