var_list and arm64 device

Hey, I'm struggling with weird problem when I try read varargs on my device (iphone6s). Everytime va_args is called returns messed up pointer which doesn't return proper object and cause EXEC_BAD_ACCESS when NSInvocation is invoked.

The same code run on Simulator and IPhone 4s works well.


void (*actionSelectorImplementationBlock) = ^(id self_, ...) {
     // Initialize invocation etc.
     // ......

     va_list arguments;
     a_start(arguments, self_); 
     NSUIntegerarg_count = [methodSignature numberOfArguments];
     for(NSUInteger i = 0; i < arg_count - 2; i++ ) {
          NSUInteger idx = i+2; const char *type = [methodSignature getArgumentTypeAtIndex:idx]; 
          id arg = va_arg(arguments, id); 
          [invocation setArgument:&arg atIndex:idx]; 
     } 
     va_end(arguments);

     // Call invocation etc.
     // .......

} 
IMP newImplementation =imp_implementationWithBlock(actionSelectorImplementationBlock); 
method_setImplementation(originalMethod, newImplementation);

Replies

Your approach is not going to work. On 64-bit ARM varargs routines use different calling conventions from standard routines, thus implementing a non-varargs method with a varargs block is simply not feasible.

This limitation is not just for 64-bit ARM. There are similar differences between varargs and non-varargs calling conventions on other runtime architectures as well, it’s just that those differences general occur at the ‘edges’ of the runtime architecture and thus you don’t trip over them very often.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"