0

This ia32 ASM code is from apache project and it's used for JNI calls. How can I analyze where to pass the arguments in this code?

My target is to add some code in it for the condition that the parameter number is 0.

For JNI, there're env argument at least, this code is correct. But I want to use the code for other thing, in that case, there're not env arguments. Does anybody knows how to add a "if (0 arguments) {do not push arguments} else {push arguments}" judgment?

invokeNative:
    push    %ebp
    movl    %esp, %ebp
    push    %ecx
    movl    8(%ebp), %eax
    movl    12(%ebp), %ecx
    leal    -4(%eax,%ecx,4), %eax
    subl    %esp, %eax
1:
    push    0(%esp,%eax)
    loop 1b
    movl    -4(%ebp), %ecx
    movl    16(%ebp), %eax
    call    *%eax
    leave
    ret
halfer
  • 19,824
  • 17
  • 99
  • 186
aaltonen
  • 31
  • 5
  • The `loop` instruction is very slow, so you already want to replace it, and probably replace the `push` as well with something that just modifies ESP once and then does a normal copy loop. It looks like it's just copying a variable number of stack args. It would be nice to avoid copying entirely and just tail-call the native function, but it needs its args right above the return address, so you can't make that happen without modifying the caller's ESP. – Peter Cordes Nov 05 '18 at 09:26
  • See [Why are loops always compiled into "do...while" style (tail jump)?](https://stackoverflow.com/q/47783926) for how to write efficient loops that might need to run zero times. – Peter Cordes Nov 05 '18 at 09:27
  • Are you sure there’s not a typo in the code shown? The push 0(esp,eax) seems wrong (but the typo could be in a different instruction). Do you know what the first two parameters to this function are? – prl Nov 17 '18 at 23:24

0 Answers0