当我尝试使用自己的实现更改指向当前 malloc 函数指针的指针时,我在 iPhone 模拟器中收到 EXC_BAD_ACCESS 错误:
malloc_zone_t *zone = malloc_default_zone();
zone->malloc = my_malloc;
集会:
0x2b73: movl $0, %ecx
0x2b78: leal -40(%ebp), %edx
0x2b7b: movl -92(%ebp), %esi
0x2b7e: movl 13828(%esi), %edi
0x2b84: movl %eax, -76(%ebp)
0x2b87: movl -76(%ebp), %eax
0x2b8a: movl %edi, 12(%eax) <------ EXC_BAD_ACCESS (code=2, address=0x675100c
0x2b8d: movl 16836(%esi), %eax
0x2b93: movl 16588(%esi), %edi
0x2b99: movl %eax, (%esp)
0x2b9c: movl %edi, 4(%esp)
0x2ba0: movl %ecx, -132(%ebp)
0x2ba6: movl %edx, -136(%ebp)
即使我尝试更改像版本这样的简单字段,我也会收到错误消息:
zone->version = 9;