flat assembler
Message board for the users of flat assembler.

Index > Windows > x64 SEH Jump to label from exception handler

Author
Thread Post new topic Reply to topic
pro3carp3



Joined: 16 Jun 2019
Posts: 2
Location: Iowa
pro3carp3 25 May 2022, 04:08
I'm adding some exception handling using the example here: https://board.flatassembler.net/topic.php?t=11266.

The example transfers control back to the procedure by setting context.Rip to the point immediately past the errant code:

Code:
buggy_instruction:
   div     ebx
sizeof_buggy_instruction =       $ - buggy_instruction
...
add     [context.Rip],sizeof_buggy_instruction 
    


Rather than jump to the code following the error, however, I want to jump to a particular label to handle the exception, similar to a finally block.

I'm getting a value out of range error when attempting this:
Code:
mov [context.Rip], finally_label
    


How do I adjust the context.Rip to jump to the finally label upon exiting the exception handler?

Thanks.
Post 25 May 2022, 04:08
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 804
Location: Russian Federation, Sochi
ProMiNick 25 May 2022, 05:03
finally_label - is 64 bit immediate value.
only instruction that accept 64 IMM is "mov REG, IMM64" so
mov RAX, finally_label
mov [context.Rip], RAX
will work.
Post 25 May 2022, 05:03
View user's profile Send private message Send e-mail Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 25 May 2022, 09:04
Isn't it better for 64-bit code to use LEA rather than MOV? I thought MOV would give a 64-bit address but LEA would use RIP-relative (and no relocation).
Post 25 May 2022, 09:04
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2565
Furs 25 May 2022, 13:24
Code:
add [context.Rip], finally_label - buggy_instruction    
Post 25 May 2022, 13:24
View user's profile Send private message Reply with quote
pro3carp3



Joined: 16 Jun 2019
Posts: 2
Location: Iowa
pro3carp3 26 May 2022, 02:42
I should have realized that. Thank you.
Post 26 May 2022, 02:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.