Fixes illegal CALL emitted in handler_block_trampoline on Win64.
authorNiklas Therning <niklas@therning.org>
Tue, 16 Aug 2016 08:46:36 +0000 (10:46 +0200)
committerNiklas Therning <niklas@therning.org>
Tue, 16 Aug 2016 08:46:36 +0000 (10:46 +0200)
commit89a1552d6f578f12c62eb9e3a566cf3d785409ca
tree880bee89d8267f3cf133086efeeb04ab9d0e5c86
parentc3405680eb43a8abc73056ccae986b541cdf6f3c
Fixes illegal CALL emitted in handler_block_trampoline on Win64.

The code in mono_arch_create_handler_block_trampoline() in tramp-amd64.c emits
a relative CALL which calls the mono_amd64_handler_block_trampoline_helper()
functions via:

  amd64_call_code (code, mono_amd64_handler_block_trampoline_helper)

This macro however only works properly for offsets less than 32-bits. For
64-bit offsets it truncates the offset to a 32-bit number. On Win64 the offset
in this case is always a number larger than 2^32. The emitted CALL will jump
to an illegal address causing a crash.

This patch changes the emitted code sequence to load the address of
mono_amd64_handler_block_trampoline_helper() to RAX and then calls the address
in RAX.

The test mono/tests/finally_block_ending_in_dead_bb.exe triggered this bug.
After this patch the test still crashes but in a new way related to another
bug.
mono/mini/tramp-amd64.c