首页 > 解决方案 > arm中mcontext_t的error_code的含义

问题描述

我们使用以下代码片段在通过 sigaction 注册的处理程序中打印用户上下文信息:

ucontext_t *p = (ucontext_t *)context;
fprintf(out, "pc %x\n", p->uc_mcontext.arm_pc);
fprintf(out, "fault addr %x\n", p->uc_mcontext.fault_address);
fprintf(out, "error %lu\n", p->uc_mcontext.error_code);

有谁知道是什么意思uc_mcontext.error_code。在哪里可以找到可能的错误代码列表?谢谢。

标签: c

解决方案


“有时故障地址为0时,错误码为23。23是什么意思?”

如果您从 /arch/arm/kernel/signal.h 中的 arm 信号源开始您会发现该结构在/arch/arm/include/uapi/asm/sigcontext.h中定义

然后你发现error_code定义为unsigned longin struct sigcontext,例如

struct sigcontext {
    unsigned long trap_no;
    unsigned long error_code;
    unsigned long oldmask;
    unsigned long arm_r0;
    unsigned long arm_r1;
    unsigned long arm_r2;
    unsigned long arm_r3;
    unsigned long arm_r4;
    unsigned long arm_r5;
    unsigned long arm_r6;
    unsigned long arm_r7;
    unsigned long arm_r8;
    unsigned long arm_r9;
    unsigned long arm_r10;
    unsigned long arm_fp;
    unsigned long arm_ip;
    unsigned long arm_sp;
    unsigned long arm_lr;
    unsigned long arm_pc;
    unsigned long arm_cpsr;
    unsigned long fault_address;
};

注意:结构不同arm64

然后要找出错误号 ( errno)23是什么,您将从/arch/arm/kernel/signal.c开始并查看它linux/errno.h是否包含在内,然后跟踪到/include/linux/errno.h,它会引导您到/include/ uapi/asm-generic/errno.h最终将您带到/include/uapi/asm-generic/errno-base.h

#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H

#define EPERM        1  /* Operation not permitted */
...
#define ENFILE      23  /* File table overflow */
...

注意:前 38 个错误代码对所有进程和架构都是通用的,尽管有些不会出现在特定架构上。因此在定义下找到它们的原因_ASM_GENERIC_ERRNO_BASE_H

然后,您可以使用任何一般参考来查找man 3 errno,这将解释:

   ENFILE          Too many open files in system (POSIX.1-2001).  On
                   Linux, this is probably a result of encountering the
                   /proc/sys/fs/file-max limit (see proc(5)).

您还可以查阅libc 错误代码文档以查找:

Macro: int ENFILE

    “Too many open files in system.” There are too many distinct file 
    openings in the entire system. Note that any number of linked 
    channels count as just one file opening; see Linked Channels. This 
    error never occurs on GNU/Hurd systems.

两者都清楚地指出了“系统中打开的文件太多”的问题。现在由您来找出为什么会在您的代码中发生这种情况。

注意:作为一种快捷方式,您可以简单地搜索,例如"linux error 23",您可以从中找到所需的信息,例如Errors: Linux System Errors,但在不进行反向跟踪时,请密切注意文件位置信息的年龄,因为errno现在可以位于树中与旧页面上列出的位置完全不同的位置——就像上面的链接一样)


推荐阅读