How to invalidate registers.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
vlad9486
Posts: 14
Joined: Thu Jan 24, 2013 9:05 am

How to invalidate registers.

Post by vlad9486 »

GCC thinks that registers is not changed in function.

Code: Select all

  100021:	bb 24 15 10 00       	mov    $0x101524,%ebx
  100026:	31 ff                	xor    %edi,%edi
  100028:	be e1 10 10 00       	mov    $0x1010e1,%esi
  10002d:	e8 f9 00 00 00       	callq  10012b <sys_call_kernel>
  100032:	0f b7 03             	movzwl (%rbx),%eax
But registers are changed in sys_call_kernel and movzwl causes to page fault. Must be a key for gcc that fixes this trouble.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: How to invalidate registers.

Post by Nable »

vlad9486 wrote:GCC thinks that registers is not changed in function.
GCC just follows ABI and you should do the same. If ABI claims that functions must preserve some registers, then you should save these registers before modification and restore their values before returning to caller.
If you don't know enough about ABI and calling conventions, you can find nice articles on wiki.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to invalidate registers.

Post by iansjack »

Rewrite sys_call_kernel so that it leaves register ebx untouched? I believe that GCC requires this.
vlad9486
Posts: 14
Joined: Thu Jan 24, 2013 9:05 am

Re: How to invalidate registers.

Post by vlad9486 »

Yeah, gcc requires that registers to be untouched, but, how to make it think that registers might change? How to change calling convention?
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to invalidate registers.

Post by iansjack »

Well, the GCC source is freely available. If you think it is easier you could rewrite GCC to not use ebx rather than doing so for your sys_call_kernel. It would certainly be educational.
Post Reply