Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>UPDATE</h2> <p>Core Foundation has a bug that makes <code>CFAllocatorSetDefault</code> useless.</p> <p>Specifically, if you study the implementation of <code>_CFRuntimeCreateInstance</code> in <a href="http://www.opensource.apple.com/source/CF/CF-744.18/CFRuntime.c" rel="nofollow"><code>CFRuntime.c</code></a>, you'll see that:</p> <ul> <li>If it's not using the system default allocator, it tries to retain the allocator.</li> <li>If it's been passed <code>NULL</code> as its <code>allocator</code> argument, it will try to retain that <code>NULL</code> instead of the current default allocator.</li> <li>The call to <code>CFRetain</code> will therefore crash.</li> </ul> <p>What it <strong>should</strong> do is retain the current default allocator when it's given <code>NULL</code> as its <code>allocator</code> argument.</p> <p>Since lots of functions in Apple's own libraries apparently pass <code>NULL</code> (or <code>kCFAllocatorDefault</code>, which is also a null pointer) to functions that create a Core Foundation object, you're bound to crash quickly if you change the default allocator at all.</p> <p>My test case: I created a new, single-view iPhone app. I added one line to <code>main</code>:</p> <pre><code>int main(int argc, char *argv[]) { CFAllocatorSetDefault(kCFAllocatorMalloc); @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } </code></pre> <p>The app crashes during startup on the simulator and on my test device, in <code>CFRetain</code>, with <code>EXC_BREAKPOINT</code>, with a null pointer as the function argument.</p> <h2>ORIGINAL</h2> <p>You are passing a null pointer to <code>CFRetain</code>. If this has anything to do with your custom allocator, you need to post more details, like the full call stack when the exception occurs.</p> <p>In your disassembly listing, the instructions from <code>0x1c089b0</code> through <code>0x1c089bd</code> are the function prologue.</p> <p>At <code>0x1c089be</code>, the <code>movl 8(%ebp), %esi</code> instruction loads the first function argument from the stack into <code>%esi</code>.</p> <p>At <code>0x1c089c1</code>, the <code>testl %esi, %esi</code> instruction sets the processor flags based on the value of <code>%esi</code>. In particular, it sets the Z (zero) flag to 1 if <code>%esi</code> contains zero, and sets the Z flag to 0 if <code>%esi</code> contains anything else.</p> <p>At <code>0x1c089c3</code>, the <code>jne 0x1c089db</code> instruction jumps if the <code>ne</code> condition is true. The <code>ne</code> condition is true when the Z flag is 0 and false when the Z flag is 1. So this instruction jumps when <code>%esi</code> (the first argument) is non-zero, and falls through when <code>%esi</code> is zero.</p> <p>At <code>0x1c089c5</code>, the <code>int3</code> instruction raises a <code>SIGTRAP</code> signal with exception code <code>EXC_BREAKPOINT</code>. The <code>int3</code> instruction is normally stuffed into a program by the debugger when you set a breakpoint. In this case, it was hardcoded in the program at compile-time.</p> <p>Thus, you are getting this exception because you are passing a null pointer to <code>CFRetain</code>.</p> <p>You can also look at the source code of <code>CFRetain</code> if you like. It is in <a href="http://www.opensource.apple.com/source/CF/CF-744.18/CFRuntime.c" rel="nofollow"><code>CFRuntime.c</code></a>:</p> <pre><code>CFTypeRef CFRetain(CFTypeRef cf) { if (NULL == cf) { CRSetCrashLogMessage("*** CFRetain() called with NULL ***"); HALT; } if (cf) __CFGenericAssertIsCF(cf); return _CFRetain(cf, false); } </code></pre> <p>So the very first thing <code>CFRetain</code> does is test whether its argument is <code>NULL</code>. <code>CGSetCrashLogMessage</code> is a macro defined in <a href="http://www.opensource.apple.com/source/CF/CF-744.18/CoreFoundation_Prefix.h" rel="nofollow"><code>CoreFoundation_Prefix.h</code></a> that does nothing. <code>HALT</code> is a macro defined in <a href="http://www.opensource.apple.com/source/CF/CF-744.18/CFInternal.h" rel="nofollow"><code>CFInternal.h</code></a>:</p> <pre><code> #define HALT do {asm __volatile__("int3"); kill(getpid(), 9); } while (0) </code></pre> <p>As you can see, <code>HALT</code> has a hard-coded <code>int3</code> instruction. Then it calls <code>kill(getpid(), 9)</code>. This matches your disassembly listing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload