开发者

RIP-relative addressing on x86

开发者 https://www.devze.com 2023-04-03 11:54 出处:网络
I\'m not really experienced with x86 assembler and try to debug a problem related to a bug in mach_inject.

I'm not really experienced with x86 assembler and try to debug a problem related to a bug in mach_inject.

The original code looks like this (function mach_inject in mach_inject.c):

#if defined(__开发者_开发技巧x86_64__)
        imageOffset = 0; // RIP-relative addressing
#else
        ASSERT_CAST( void*, remoteCode );
        imageOffset = ((void*) remoteCode) - image;
#endif

and then somewhat later (function INJECT_ENTRY of mach_inject_bundle_stub.c):

pthread_create( &thread,
                &attr,
                (void* (*)(void*))((long)some_local_function + imageOffset),
                (void*) param );

It seems, for me, when I compile this for x86, it fails. If I change the code so that I have imageOffset = 0; on just every architecture (i.e. also for x86), it all works fine.

So, some questions:

  • RIP-relative addressing is also available for 32bit/x86 mode?
  • What was (probably) the initial intention for this code if we anyway have also RIP-relative addressing for 32bit mode?
  • Is RIP-relative addressing a compiler setting? Or in what way can I control if my code uses RIP-relative addressing or not? (Or more related to this bug: Is imageOffset = 0; always correct? Or when is it not?)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号