Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1063 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about Objective C calling convention and argument passing on ARM

#1
I want to know how objective C runtime handle arguments when I call a objective C method like

[NSString stringWithFomat:@"%@, %@", @"Hello", @"World"]

There are three arguments for this objective C call, how does it work compared to typical way on a ARM system. I have known register r0, r1, r2, r3 will hold first 4 arguments, how about there are additional arguments? How does it put them on a stack and pop them later?
Reply

#2
For functions that returns a simple type:

r0 = self (NSString)
r1 = _cmd (@selector(stringWithFormat:))
r2 = 1st argument (@"%@, %@")
r3 = 2nd argument (@"Hello")

then the rest is placed on the stack:

[sp,#0] = 3rd argument (@"World")
[sp,#4] = 4th argument (does not exist in your example)
...

Of course, "argument" here means a 4-byte object. If the argument has >4 bytes then it will be split out, e.g.

-[UIView initWithFrame:rect];

r0 = self
r1 = _cmd
r2 = rect.origin.x
r3 = rect.origin.y
[sp,#0] = rect.size.width
[sp,#4] = rect.size.height

The returned value (up to 16 bytes) will be placed in r0, r1, r2, r3.

---

For functions that returns a struct: `r0` is used to store the pointer of the return value.

NSRange retval = [self rangeOfString:string options:options range:range]

r0 = &retval (of type NSRange*)
r1 = self
r2 = _cmd (@selector(rangeOfString:options:range:))
r3 = string
[sp,#0] = options
[sp,#4] = range.location
[sp,#8] = range.length
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through