• glibc: 这个函数是平台定制__syscall_sigreturn;如x86可能就返回 errno=ENOSYS


    glibc里的定义

    在/glibc/sysdeps/unix/sysv/linux/这个目录,如果平台不需要特制化的改动会在使用目录下的文件。如果需要特制化的代码,就会在这个目录创建平台特定的目录,实现其特制的代码。

    /glibc/sysdeps/unix/sysv/linux/sigreturn.c

    /* The sigreturn syscall cannot be explicitly called on Linux, only
       implicitly by returning from a signal handler.  */
    #include 
    
    • 1
    • 2
    • 3

    signal/sigreturn.c

    int
    __sigreturn (struct sigcontext *context)
    {
      __set_errno (ENOSYS);
      return -1;
    }
    stub_warning (sigreturn)
    
    weak_alias (__sigreturn, sigreturn)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    0x26 =

    /*
     * This error code is special: arch syscall entry code will return
     * -ENOSYS if users try to call a syscall that doesn't exist.  To keep
     * failures of syscalls that really do exist distinguishable from
     * failures due to attempts to use a nonexistent syscall, syscall
     * implementations should refrain from returning -ENOSYS.
     */
    #define	ENOSYS		38	/* Invalid system call number */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    (gdb) disass __sigreturn
    Dump of assembler code for function sigreturn:
       0x0000000000036f90 <+0>:       mov    0x38feb9(%rip),%rax        # 0x3c6e50
       0x0000000000036f97 <+7>:       movl   $0x26,%fs:(%rax); 这里可以看到直接讲errno放到了线程相关数据的某一个位置。
       0x0000000000036f9e <+14>:      mov    $0xffffffff,%eax
       0x0000000000036fa3 <+19>:      
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    errno 使用的示例

    即使是O2的优化,还是会调用库函数__errno_location。原因在于errno的相对位置在库函数里确定的,离开库函数,应用找不到errno的地址。这里也可以看到
    (gdb) disass main
    Dump of assembler code for function main:
    0x0000000000400500 <+0>: sub $0x8,%rsp
    0x0000000000400504 <+4>: callq 0x4004e0 __errno_location@plt

    (gdb) disass __errno_location
    Dump of assembler code for function __errno_location@plt:
    0x00000000004004e0 <+0>: jmpq *0x200b32(%rip) # 0x601018 __errno_location@got.plt
    0x00000000004004e6 <+6>: pushq $0x0
    0x00000000004004eb <+11>: jmpq 0x4004d0

    libc-2.28.so
    (gdb) disass __errno_location
    Dump of assembler code for function __errno_location:
    0x000000000003af80 <+0>: endbr64
    0x000000000003af84 <+4>: mov 0x383edd(%rip),%rax # 0x3bee68 0x3bee68-0x383edd=0x3af8b
    0x000000000003af8b <+11>: add %fs:0x0,%rax
    0x000000000003af94 <+20>: retq
    End of assembler dump.

  • 相关阅读:
    TypeScript 高级类型-详解
    【NLP】Transformer理论解读
    云呐|动环监控设备维护与常见故障处理
    vue框架之插槽,组件的自定义,网络代理配置,网络公共路径配置
    python解析xml遇到的问题分享(命名空间有关)
    字符串压缩(三)之短字符串压缩
    跨境电商背景下,DolphinScheduler 在 SHEIN 的二开实践
    探测工具nmap简介及使用说明
    纵目科技冲刺科创板上市:拟募资20亿元,股东阵容强大
    TypeScript - 枚举 - 常量枚举
  • 原文地址:https://blog.csdn.net/qq_36428903/article/details/127942949