加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 在EXC_BAD_ACCESS中代码= 1和代码= 2之间有什么

发布时间:2020-12-15 01:38:36 所属栏目:百科 来源:网络整理
导读:我正在为EXC_BAD_ACCESS错误接收代码= 1或代码= 2.我想知道代码= 1和代码= 2之间有什么区别? 解决方法 代码= 1是KERN_INVALID_ADDRESS,代码= 2是KERN_PROTECTION_FAILURE.两者都是 在 “Technical Note TN2123 CrashReporter”年解释: The most common for
我正在为EXC_BAD_ACCESS错误接收代码= 1或代码= 2.我想知道代码= 1和代码= 2之间有什么区别?

解决方法

代码= 1是KERN_INVALID_ADDRESS,代码= 2是KERN_PROTECTION_FAILURE.两者都是
在 “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.

代码定义在<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.
                 */

并在<mach/exception_types.h>中记录了代码
对于EXC_BAD_ACCESS是一个kern_return_t:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读