Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

c - 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. The following is from io/chdir.c but it is indicative of many of the source files. 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. __set_errno seems to be a simple macro that sets errno. And while I find a million usages of weak_alias I don't see it defined anywhere.

Is there a helpful guide to understanding how glibc works somewhere?

#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> 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What you've found is a stub function for systems it's not implemented on. You need to look under the sysdeps tree for the actual implementation. The following may be of interest:

  • sysdeps/unix/sysv/linux
  • sysdeps/posix
  • sysdeps/i386 (or x86_64 or whatever your cpu arch is)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...