Page 1 of 1

How to invalidate registers.

Posted: Sun Apr 06, 2014 12:41 pm
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.

Re: How to invalidate registers.

Posted: Sun Apr 06, 2014 1:04 pm
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.

Re: How to invalidate registers.

Posted: Sun Apr 06, 2014 1:06 pm
by iansjack
Rewrite sys_call_kernel so that it leaves register ebx untouched? I believe that GCC requires this.

Re: How to invalidate registers.

Posted: Sun Apr 06, 2014 1:14 pm
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?

Re: How to invalidate registers.

Posted: Sun Apr 06, 2014 1:16 pm
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.