Does the return value always go into eax register after a method call?

Bartlomiej Lewandowski

I have written a hooking library, that examines a PE executables dll import table, to create a library that enables changing of parameters and return values. I have a few questions on how the return value is passed from a function.

I have learned that the return value of a function is saved in the accumulator register. Is this always the case? If not, how does the compiler know where to look for the function result?

What about the return type size? An integer will easily fit, but what about a bigger structure? Does the caller reserve stack space so the method it calls could write the result onto stack?

qwm

It's all specific to calling convention.

For most calling conventions floating point numbers are returned either on FPU-stack or in XMM registers.

Call to the function returning a structure

    some_struct foo(int arg1, int arg2);
    some_struct s = foo(1, 2);

will be compiled into some equivalent of:

    some_struct* foo(some_struct* ret_val, int arg1, int arg2);
    some_struct s; // constructor isn't called
    foo(&s, 1, 2); // constructor will be called in foo

Edit: (add info)

just to clarify: this works for all structs and classes even when sizeof(some_struct) <= 4. So if you define small useful class like ip4_type with the only unsigned field and some constructors/convertors to/trom unsigned, in_addr, char* it will lack efficiency compared to use of raw unigned value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python: Why does the value always return 0

From Dev

Zeroing %EAX Register on the 8086

From Dev

Why does the Synchronized method always return false?

From Dev

Using reflection to call a method and return a value

From Dev

What value is in EAX after execution of each instruction?

From Dev

why echo return value ($?) after pipeline always return "0"

From Dev

Does detach() method call after attach() method?

From Dev

Best way to return a function value and call another method after async animation block or timer has ended

From Dev

Moq: Callback after method invocation on a method that does not return a value

From Dev

Does it matter what you call after() method with?

From Dev

Script Windbg to dump eax register after a call to FindFirstFileW

From Dev

Aurelia: always call method in the view (problems after upgrade)

From Dev

Why does this method always produce 0 as its return value?

From Dev

Does __asm{}; return the value of eax?

From Dev

Call a method on the return value of a method reference

From Dev

Return value register and destructor call order

From Dev

Thread.Join method does not always return the same value when the thread has already terminated (.NET 5 / Core)

From Dev

Thread.Join method does not always return the same value when the thread has already terminated (.NET 5 / Core)

From Dev

How to get string value of integer in the EAX register

From Dev

What does making the sys_read system call to linux put in the register eax?

From Dev

Does setText() method always set value to a string?

From Dev

Return value in a method that call stored procedure

From Dev

Return Value %eax Convention

From Dev

Why does this method always produce 0 as its return value?

From Dev

Why does TokenOrigin always return the same value?

From Dev

Will the call to the last awaited method be optimized to never return INTO the method if there is nothing after it?

From Dev

Sentinel::check() always return false after redirect from login method

From Dev

Printf text and return value of a method call

From Dev

Why does this method not return a value?

Related Related

  1. 1

    Python: Why does the value always return 0

  2. 2

    Zeroing %EAX Register on the 8086

  3. 3

    Why does the Synchronized method always return false?

  4. 4

    Using reflection to call a method and return a value

  5. 5

    What value is in EAX after execution of each instruction?

  6. 6

    why echo return value ($?) after pipeline always return "0"

  7. 7

    Does detach() method call after attach() method?

  8. 8

    Best way to return a function value and call another method after async animation block or timer has ended

  9. 9

    Moq: Callback after method invocation on a method that does not return a value

  10. 10

    Does it matter what you call after() method with?

  11. 11

    Script Windbg to dump eax register after a call to FindFirstFileW

  12. 12

    Aurelia: always call method in the view (problems after upgrade)

  13. 13

    Why does this method always produce 0 as its return value?

  14. 14

    Does __asm{}; return the value of eax?

  15. 15

    Call a method on the return value of a method reference

  16. 16

    Return value register and destructor call order

  17. 17

    Thread.Join method does not always return the same value when the thread has already terminated (.NET 5 / Core)

  18. 18

    Thread.Join method does not always return the same value when the thread has already terminated (.NET 5 / Core)

  19. 19

    How to get string value of integer in the EAX register

  20. 20

    What does making the sys_read system call to linux put in the register eax?

  21. 21

    Does setText() method always set value to a string?

  22. 22

    Return value in a method that call stored procedure

  23. 23

    Return Value %eax Convention

  24. 24

    Why does this method always produce 0 as its return value?

  25. 25

    Why does TokenOrigin always return the same value?

  26. 26

    Will the call to the last awaited method be optimized to never return INTO the method if there is nothing after it?

  27. 27

    Sentinel::check() always return false after redirect from login method

  28. 28

    Printf text and return value of a method call

  29. 29

    Why does this method not return a value?

HotTag

Archive