首页 > 解决方案 > 基于 libc 程序集的 32 位 socketcall 系统调用如何工作?

问题描述

我试图通过阅读套接字 API 中的汇编代码和 Libc 库中的其他一些代码来了解 32 位套接字调用的工作原理。

   000ed9f0 <socket>:
   ed9f0: 89 da                 mov    %ebx,%edx
   ed9f2: b8 66 00 00 00        mov    $0x66,%eax   # socketcall syscall number
   ed9f7: bb 01 00 00 00        mov    $0x1,%ebx    # SYS_SOCKET value
   ed9fc: 8d 4c 24 04           lea    0x4(%esp),%ecx # pointer to the *arg structure
   eda00: 65 ff 15 10 00 00 00  call   *%gs:0x10  # invokes syscall? but this is not sysenter or int 0x80
   eda07: 89 d3                 mov    %edx,%ebx
   eda09: 83 f8 83              cmp    $0xffffff83,%eax
   eda0c: 73 01                 jae    eda0f <socket+0x1f>
   eda0e: c3                    ret
   eda0f: e8 cb 8d 03 00        call   1267df <__frame_state_for+0x35f>
   eda14: 81 c1 ec d5 0b 00     add    $0xbd5ec,%ecx
   eda1a: 8b 89 24 ff ff ff     mov    -0xdc(%ecx),%ecx
   eda20: f7 d8                 neg    %eax
   eda22: 65 03 0d 00 00 00 00  add    %gs:0x0,%ecx
   eda29: 89 01                 mov    %eax,(%ecx)
   eda2b: 83 c8 ff              or     $0xffffffff,%eax
   eda2e: c3                    ret
   eda2f: 90                    nop

请参阅上面的代码注释 (#)。这对我来说是有意义的,直到这一行:

   eda00: 65 ff 15 10 00 00 00  call   *%gs:0x10  # invokes syscall? but this is not Sysenter or int 0x80

我以为我们使用 int 0x80 或 Sysenter 调用 syscall。但是这个使用段寄存器的调用是如何调用 socketcall 系统调用的呢?

标签: linuxassemblysystem-callslibc

解决方案


推荐阅读