Re: Internal unwinding clobbers non-volatile registers.

  • From: Can Boluk <can.boluk89@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 31 May 2021 06:40:27 +0200

Hey Mike,

Thanks for the reply.

Does this behave as it should for non-MS x64 ABIs, System V for instance?
I'm using LuaJIT in a custom baremetal Ring0 environment so I'm by no means
restricted to MS ABI, it's mainly that I cannot use external unwinding
since I don't have unwind tables and I think I'll run into the same problem
unless there's a major change to EXT when System V ABI is used; r.e. saving
ymm8-ymm15 etc.

My current hacky solution is replacing the pcall with:
register void* _rcx asm( "rcx" ) = L;
register void* _rdx asm("rdx") = api_call_base( L, nargs );
register int _r8d asm("r8d") = nresults + 1;
register ptrdiff_t _r9 asm("r9") = ef;
asm volatile( "call lj_vm_pcall"
: "=a" ( status ), "+r" ( _rcx ), "+r" ( _rdx ), "+r" ( _r8d ), "+r" ( _r9 )
:: "r10", "r11", "r12", "r13", "r14", "r15", "memory", "flags", "ymm0",
"ymm1", "ymm2", "ymm3" );
But yeah, not very ideal and probably not entirely safe.

Best,
Can



On Mon, May 31, 2021 at 5:22 AM Mike Pall <mikelj-2105@xxxxxxx> wrote:

Can Boluk wrote:
I've noticed that internal unwinding [...]

As you can see this will clobber r13-r15 which are defined as callee
saved
under MS ABI.

Precisely for this reason, external unwinding is mandatory on
Windows/x64. A previous version of lj_err.c had this text:

| EXT is mandatory on WIN64 since the calling convention has an abundance
| of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15).

--Mike


Other related posts: