[英]Different ways to call system calls
I observed that system call "stat" is behaving differently with calls 我观察到系统调用“ stat”与调用的行为有所不同
stat()
syscall(__NR_stat)
I do not understand why same system call is behaving differently just because way to call it is changed? 我不明白为什么同一系统调用的行为方式不同,仅仅是因为调用方式发生了变化?
The stat()
provided by a C library on Linux today is usually implemented on top of the kernel 's sys_stat64()
. 今天,Linux上的C库提供的stat()
通常在内核的sys_stat64()
之上实现。
This is one of the many cases where the man page should be your first reference: 在许多情况下, 手册页应该是您的第一个参考:
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().
You may also want to obtain the source package for your installed C library and look through it for the actual implementation of the wrapper. 您可能还需要获取已安装的C库的源程序包,并仔细查看它以寻找包装程序的实际实现。
If it is C code, then you should realize, that you have some syntax errors. 如果是C代码,那么您应该意识到自己有一些语法错误。 But anyway, on platforms there may be different values of __NR_stat marcro. 但是无论如何,在平台上,__ NR_stat marcro的值可能不同。 To find out this, you have to see /usr/include/unistd.h file. 要找出这一点,您必须查看/usr/include/unistd.h文件。 And who knows what's the sequencies of calling these functions? 谁知道调用这些函数的顺序是什么? Please, give us more information. 请给我们更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.