Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

objective c - what's the difference between code=1 and code=2 in EXC_BAD_ACCESS?

I am receiving code=1 or code=2 for EXC_BAD_ACCESS error. I am wondering what's the difference between code=1 and code=2?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Code = 1 is KERN_INVALID_ADDRESS and code = 2 is KERN_PROTECTION_FAILURE. Both are explained in the "Technical Note TN2123 CrashReporter":

The most common forms of exception are:

  • EXC_BAD_ACCESS/KERN_INVALID_ADDRESS — This is caused by the thread accessing unmapped memory. It may be triggered by either a data access or an instruction fetch; the Thread State section describes how to tell the difference.
  • EXC_BAD_ACCESS/KERN_PROTECTION_FAILURE — This is caused by the thread trying to write to read-only memory. This is always caused by a data access.

The codes are defined in <mach/kern_return.h>:

#define KERN_INVALID_ADDRESS            1
                /* Specified address is not currently valid.
                 */

#define KERN_PROTECTION_FAILURE         2
                /* Specified memory is valid, but does not permit the
                 * required forms of access.
                 */

and in <mach/exception_types.h> it is documented that the code for a EXC_BAD_ACCESS is a kern_return_t:

#define EXC_BAD_ACCESS          1       /* Could not access memory */
                /* Code contains kern_return_t describing error. */
                /* Subcode contains bad memory address. */

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...