【问题标题】:Different ways to call system calls调用系统调用的不同方式
【发布时间】:2014-10-30 09:36:50
【问题描述】:

我观察到系统调用“stat”的行为与调用不同

stat()

syscall(__NR_stat) 

我不明白为什么同一个系统调用的行为不同 因为调用它的方式改变了?

【问题讨论】:

  • 具体有什么区别?

标签: linux linux-kernel system system-calls


【解决方案1】:

今天Linux上的C库提供的stat()通常是在内核的sys_stat64()之上实现的。

这是man page 应该是您的第一个参考的众多情况之一:

  Underlying kernel interface

   Over time, increases in the size of the stat structure have led to
   three successive versions of stat(): sys_stat() (slot __NR_oldstat),
   sys_newstat() (slot __NR_stat), and sys_stat64() (new in kernel 2.4;
   slot __NR_stat64).  The glibc stat() wrapper function hides these
   details from applications, invoking the most recent version of the
   system call provided by the kernel, and repacking the returned
   information if required for old binaries.  Similar remarks apply for
   fstat() and lstat().

您可能还想获取已安装的 C 库的源代码包,并通过它查看包装器的实际实现。

【讨论】:

    【解决方案2】:

    如果是 C 代码,那么你应该意识到你有一些语法错误。 但无论如何,在平台上可能会有不同的 __NR_stat 宏值。要找出这一点,您必须查看 /usr/include/unistd.h 文件。谁知道调用这些函数的顺序是什么? 请给我们更多信息。

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 2014-12-25
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      相关资源
      最近更新 更多