ioctl的调用流程

本文详细介绍了在用户态到内核态中ioctl调用的完整流程,从用户态的int 0x80陷入内核,到内核中的系统调用处理,再到sys_ioctl的定义和vfs_ioctl的调用。通过对关键代码段的分析,揭示了如何通过系统调用号进入相应的内核函数,以及在文件操作中的ioctl处理方式。
摘要由CSDN通过智能技术生成

用户态:最终通过int 0x80陷入内核


在arch\x86\include\asm\unistd_32.h中 
#define __NR_ioctl         54

 
ioctl 
==》 __ioctl 
==》INLINE_SYSCALL (ioctl, 3, fd, request, arg);  //每种cpu架构都有自己的定义,下面是X86的定义:
#define INLINE_SYSCALL(name, nr, args...) \
  ({      \
    unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args);     \
    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))     \
      {      \
__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));     \
resultvar = 0xffffffff;     \
      }      \
    (int) resultvar; })


/* Define a macro which expands inline into the wrapper code for a system
   call.  This use is for internal calls that do not need to handle errors
   normally.  It will never touch errno.  This returns just what the kernel
   gave back.
   The _NCS variant allows non-constant syscall numbers but it is not
   possible to use more than four parameters.  */
# define INTERNAL_SYSCALL(name, err, nr, args...) \
  ({      \
    register unsigned int resultvar;      \
    EXTRAVAR_##nr      \
    asm volatile (      \
    LOADARGS_##nr      \
    "movl %1, %%eax\n\t"      \
    "int $0x80\n\t"      \
    RESTOREARGS_##nr      \
    : "=a" (resultvar)      \
    : 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值