libffcall
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libffcall] libtrampoline: Feature Request, getting size of trampoli


From: Bruno Haible
Subject: Re: [Libffcall] libtrampoline: Feature Request, getting size of trampoline
Date: Wed, 05 Jul 2017 22:11:59 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-81-generic; KDE/5.18.0; x86_64; ; )

Hi,

Alibek Omarov wrote:
> I have a proprietary library compiled for ARM(Android), with totally broken
> debug log. I try to restore it by generating trampoline with libffcall,
> replacing first few bytes of original function, so any call leads to my
> implementation.
> 
> It works as it is intended, debug log is repaired.
> 
> That's why I need getting trampoline size in more flexible way, than
> copying value from source code, so I can just update libffcall, when new
> version will out.

Ah, you do "code patching", like kpatch, gdb, maybe also dtrace do.

What you are doing cannot be a portably supported use-case of libffcall.
The simple reason the trampoline has up to ca. 64 bytes, which is way
more than 1 instruction. Now, when you have a function with a loop that
starts near the beginning:

    func:
          init some registers
    startloop:
            loop body
            test condition, jump to startloop
    endloop:
          continue...

when you overwrite more than (startloop-func) bytes, you cannot jump
back into the function from anywhere, because execution of the loop
would bring $pc back to startloop - and part of the loop body has already
been overwritten.

So, basically, you must use an instruction that is as small as possible
at the beginning of func.

libffcall's trampolines are designed for something different.

The only common parts between what you are doing and libffcall are
  - the generation of a "jump" instruction (not terribly difficult to do
    yourself),
  - the cache flushing (which nowadays is a function in libgcc, on most
    platforms).

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]