gpt4 book ai didi

objective-c - EXC_BAD_ACCESS 中的code=1 和code=2 有什么区别?

转载 作者:太空狗 更新时间:2023-10-30 03:15:35 25 4
gpt4 key购买 nike

我收到 code=1 或 code=2 的 EXC_BAD_ACCESS 错误。我想知道 code=1 和 code=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. */

关于objective-c - EXC_BAD_ACCESS 中的code=1 和code=2 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19741409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com