I'm currently dealing with a really weird bug in my iOS app. It doesn't happen in the simulator, and it doesn't happen when I recompile the core of the app for x86 and run it on Mac or Linux.
It takes the form of an EXC_BAD_ACCESS when you do some particular thing. The code is 1, which apparently means KERN_INVALID_ADDRESS. In other words, the kernel says nothing is mapped at that address. But when I use the
memory region
command in lldb, it says there's a page mapped at that address with read and write permissions turned on. I've confirmed with debug logging that the region is mapped with mmap earlier in the program and never unmapped. (I haven't tried calling mach_vm_region_info, but I suspect it would return the same thing.)So the question is, why would the kernel throw EXC_BAD_ACCESS with code 1 for an address that's apparently valid?
One clue: If you run the app in lldb over USB, runn
memory region ptr
, and then run memory region
with no arguments, LLDB will crash, and the app just continues and works fine. Maybe memory region ptr
caused some sort of probe that made the kernel realize the pointer was actually valid?