Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Last active March 2, 2017 02:06
Show Gist options
  • Save NSExceptional/0fed1a356cbfb92b05e277702d8b6f94 to your computer and use it in GitHub Desktop.
Save NSExceptional/0fed1a356cbfb92b05e277702d8b6f94 to your computer and use it in GitHub Desktop.
Code which demonstrates strangely aligned stack arguments in ARM64.
_main:
// Prologue
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #96 // Space for stack paramters to +[Foo method::::::::]
// First two implicit arguments to any Objc method call
ldr x0, #552 // Objc class ref: Foo
ldr x1, #536 // Objc selector ref: "method::::::::"
// Same `Bar` struct used for all `Bar` args
movz w8, #0xbe
movz w9, #0xbf
movz w10, #0xaf
stp x8, x9, [x29, #-24] // Arg `f` storage (@ `[sp, #72]`)
stur x10, [x29, #-8]
stp x8, x9, [sp, #48] // Arg `c` storage (@ `[sp, #48]`)
str x10, [sp, #64]
stp x8, x9, [sp, #24] // Arg `a` storage (@ `[sp, #24]`)
str x10, [sp, #40]
orr w8, wzr, #0x2 // Arg `h` (@ `[sp, #8]`)
str x8, [sp, #8]
orr w8, wzr, #0x1 // Arg `g` (@ `[sp]`)
str x8, [sp]
sub x2, x29, #24 // Arg `a` ref
movz w3, #0x3 // Arg `b`
add x4, sp, #48 // Arg `c` ref
movz w5, #0x5 // Arg `d`
movz w6, #0x6 // Arg `e`
add x7, sp, #24 // Arg `f` ref
// Method call
bl 0x100007f24 // Objc message: +[Foo method::::::::]
// Epilogue
movz w0, #0
mov sp, x29
ldp x29, x30, [sp], #16
ret
typedef struct _Bar {
long x;
long y;
long z;
} Bar;
@interface Foo : NSObject
+ (void)method:(Bar)a :(long)b :(Bar)c :(long)d :(long)e :(Bar)f :(long)g :(long)h;
@end
@implementation Foo
+ (void)method:(Bar)a :(long)b :(Bar)c :(long)d :(long)e :(Bar)f :(long)g :(long)h {
f.x = 0;
}
@end
int main() {
Bar c;
c.x = 0xbe;
c.y = 0xbf;
c.z = 0xaf;
[Foo method:c:3:c:5:6:c:1:2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment