OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 6:14 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Skipping the instruction after IRET
PostPosted: Wed Jan 22, 2020 2:32 am 
Offline

Joined: Mon Jan 02, 2017 4:55 am
Posts: 2
In x86 long mode, is there a better way to skip the instruction after IRET than parsing the bytes at the stored IP and working out how much to add to it?

Modifying the bytes at IP isn't an option because I don't want the change to be "permanent".


Top
 Profile  
 
 Post subject: Re: Skipping the instruction after IRET
PostPosted: Wed Jan 22, 2020 2:58 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5137
No.

Why do you want to skip the instruction?


Top
 Profile  
 
 Post subject: Re: Skipping the instruction after IRET
PostPosted: Wed Jan 22, 2020 3:27 am 
Offline

Joined: Mon Jan 02, 2017 4:55 am
Posts: 2
Because it's a non-fatal condition and I don't want the failing instruction to be retried.

To vastly simplify, what's going on is GC trickery; If a page contains candidates for garbage collection, I tag it oldspace and make it read-only. If something later tries to write to the page, it will page fault, allowing me to trap the write. The kernel will do the right thing for the object that was touched, but not the entire page. Since the kernel has completed the write, having the program try it again will loop.

Later I can GC the objects in the page that didn't get written to and keep just what's being actively used.


Top
 Profile  
 
 Post subject: Re: Skipping the instruction after IRET
PostPosted: Wed Jan 22, 2020 3:46 am 
Offline
Member
Member

Joined: Wed Oct 26, 2011 12:00 pm
Posts: 202
No, you would need to parse the assembly pointed to by the IP and figure out the length of that instruction and add it to the IP. There is no easy way to solve that.

_________________
mollenos | gracht (protocol library) | vioarr (window-manager) | bake (package manager)


Top
 Profile  
 
 Post subject: Re: Skipping the instruction after IRET
PostPosted: Wed Jan 22, 2020 12:56 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Hi Suzuran,

If you're using long mode (64 bit), you could try my disassembler: https://gitlab.com/bztsrc/osz/blob/master/src/core/x86_64/disasm.h. It has one function only:
Code:
virt_t disasm(virt_t addr, char *str)
Where "virt_t" is a virtual address, uint64_t. This function receives an address, and returns the address of the next instruction. You obviously won't need the disassembled string, so just pass NULL as the second argument.
Code:
nextinst = disasm(exceptioninst, NULL);


For protected mode (32 bit), you might want to take a look at OpenBSD's version: https://github.com/openbsd/src/blob/master/sys/arch/i386/i386/db_disasm.c. It has a very similar interface:
Code:
vaddr_t db_disasm(vaddr_t loc, int altfmt);
but it is not that trivial to reuse this code as it is a bit tied up with other parts of the BSD kernel (but not particularly hard either, just provide you own db_access implementation), and you'll have to manually remove the disassembled string writes from the code (all those db_print* calls). But at the end, it will do the job.

Cheers,
bzt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], SemrushBot [Bot] and 307 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group