简体   繁体   English

glibc 源代码中的系统调用在哪里

[英]Where are syscalls located in glibc source

So I was looking through the linux glibc source and I don't see where it actually does anything.因此,我正在查看 linux glibc 源代码,但看不到它实际上在哪里做任何事情。 The following is from io/chdir.c but it is indicative of many of the source files.以下来自io/chdir.c但它表示许多源文件。 What's going on here?这里发生了什么? Obviously I am missing something.显然我错过了一些东西。 What's the secret, where does it make a system call or actually do something?秘密是什么,它在哪里进行系统调用或实际做某事?

stub_warning is some legacy craziness. stub_warning是一些遗留的疯狂。 __set_errno seems to be a simple macro that sets errno . __set_errno似乎是一个设置errno的简单宏。 And while I find a million usages of weak_alias I don't see it defined anywhere.虽然我发现了weak_alias的一百万种用法,但我没有看到它在任何地方定义。

Is there a helpful guide to understanding how glibc works somewhere?是否有有用的指南来了解 glibc 如何在某处工作?

#include <errno.h>
#include <stddef.h>
#include <unistd.h>

/* Change the current directory to PATH.  */
int
__chdir (path)
     const char *path;
{
  if (path == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  __set_errno (ENOSYS);
  return -1;
}
stub_warning (chdir)

weak_alias (__chdir, chdir)
#include <stub-tag.h> 

What you've found is a stub function for systems it's not implemented on.您发现的是未在其上实现的系统的存根 function。 You need to look under the sysdeps tree for the actual implementation.您需要查看sysdeps树下的实际实现。 The following may be of interest:以下内容可能令人感兴趣:

  • sysdeps/unix/sysv/linux
  • sysdeps/posix
  • sysdeps/i386 (or x86_64 or whatever your cpu arch is) sysdeps/i386 (或x86_64或任何你的 cpu 架构)

The actual system call code for chdir() is auto-generated on most systems supported by glibc , by the script make-syscalls.sh . chdir()的实际系统调用代码是在glibc支持的大多数系统上由脚本make-syscalls.sh自动生成的。 That's why you can't find it in the source tree.这就是为什么您在源代码树中找不到它的原因。

That's a generic stub that is used if another definition doesn't exist;这是一个通用存根,如果不存在另一个定义,则使用该存根; weak_alias is a cpp macro which tells the linker that __chdir should be used when chdir is requested, but only if no other definition is found. weak_alias是一个cpp宏,它告诉__chdir在请求chdir时应该使用 __chdir,但前提是没有找到其他定义。 (See weak symbols for more details.) (有关详细信息,请参阅符号。)

chdir is actually a system call; chdir实际上是一个系统调用; there will be per-OS system call bindings in the gibc source tree, which will override the stub definition with a real one that calls into the kernel.gibc源代码树中将存在每个操作系统的系统调用绑定,这将使用调用 kernel 的真实定义覆盖存根定义。 This allows glibc to present a stable interface across systems which may not have all of the system calls that glibc knows about.这允许glibc提供跨系统的稳定接口,这些系统可能没有glibc知道的所有系统调用。

Note that the actual system calls aren't defined anywhere in the source tree - they're generated at build time from syscalls.list (linked is the one in sysdeps/unix, there are additional ones further down), a series of macros insysdep.h (linked linux/i386), and a script that actually generates the source files.请注意,实际的系统调用没有在源代码树中的任何地方定义——它们是在构建时从syscalls.list生成的(链接的是 sysdeps/unix 中的一个,还有更多的向下),一系列宏sysdep.h (链接 linux/i386)和一个实际生成源文件的脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM