Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Aug 2007 12:05:30 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Jin Guojun <jin@george.lbl.gov>
Cc:        threads@freebsd.org, questions@freebsd.org
Subject:   Re: how sys_select, sys_fork, ... are defined for thread libraries?
Message-ID:  <20070803090530.GH2738@deviant.kiev.zoral.com.ua>
In-Reply-To: <46B245D5.1050606@george.lbl.gov>
References:  <46B245D5.1050606@george.lbl.gov>

next in thread | previous in thread | raw e-mail | index | archive | help

--zq44+AAfm4giZpo5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Aug 02, 2007 at 02:00:05PM -0700, Jin Guojun wrote:
> I am trying to understand how these __sys_xxx functions are defined for=
=20
> thread libraries.
> Following string search tells that all thread libraries are using these=
=20
> __sys_xxx functions,
> for example, __sys_select(). However, the search also shows that these=20
> functions are not defined anywhere in the entire source tree.
>=20
> /usr/src: findstring sys_select "*.[hcS]"
> total files=3D 21687 : pattern=3D sys_select rootdir=3D /usr/src
> regular mode: Thu Aug 2 13:31:40 PDT 2007
> ./lib/libc_r/uthread/uthread_fork.c
> 91:              * __sys_select:
>=20
> ./lib/libpthread/thread/thr_private.h
> 1264:int     __sys_select(int, fd_set *, fd_set *, fd_set *, struct=20
> timeval *);
>=20
> ./lib/libpthread/thread/thr_select.c
> 61:             ret =3D __sys_select(numfds, readfds, writefds, exceptfds=
,=20
> timeout);
>=20
> ./lib/libthr/thread/thr_private.h
> 805:int     __sys_select(int, fd_set *, fd_set *, fd_set *, struct=20
> timeval *);
>=20
> ./lib/libthr/thread/thr_syscalls.c
> 435:    ret =3D __sys_select(numfds, readfds, writefds, exceptfds, timeou=
t);
>=20
>=20
> By searching the usr/lib objects, I found them in libc, but they are not=
=20
> in libc source tree.
> Can someone shed some light on how these system calls are built into=20
> libc and what is the
> different between standard syscall APIs and these __sys_syscall APIs,
> e.g., __sys_read() vs. read(), etc.
>=20
> Thanks,
>=20
> -Jin
>=20
>=20
> nm /usr/lib/libc.a | grep __sys_
> 00000008 T __sys_sigreturn
> 00000008 T __sys_setlogin
> 00000008 T __sys_reboot
> ... snapped
> 00000008 T __sys_kse_release
> 00000008 T __sys_kse_thr_interrupt
> 00000008 T __sys_kse_create
> 00000008 T __sys_kse_wakeup
> ... skipped
> 00000008 T __sys_getdtablesize
> 00000008 T __sys_select
> 00000008 T __sys_ioctl
> 00000008 T __sys_close
> 00000008 T __sys_write
> 00000008 T __sys_read
> 00000008 T __sys___syscall

The C standard specifies that namespace of identifiers starting with __ or
_<UPPERCASE> is reserved for implementation. On the other hand, C standard
allows for the programs to use any symbol not reserved by standard.

The thread libraries (and libc) shall internally use the "right"
implementation of syscalls, as opposed to some symbol supplied by user
binary.

To achieve this, for each syscall x, libc defines the normal symbol __sys_x,
and two weak symbols _x and x. See, for instance, the file lib/libc/select.S
from the obj directory, and lib/libc/i386/SYS.h for corresponding include
file.

Definition of weak symbols is provided by ELF specification. Simplyfing,
weakness of the symbol mean that it is used only unless somebody provides
the same normal symbol. Normal symbols from text segment are marked by "T"
in nm output, and weak symbols has "t" mark.

--zq44+AAfm4giZpo5
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFGsu/ZC3+MBN1Mb4gRAvOlAJ9DDfdILBWswe7L9ul+iIwVGWpzJQCdF6JN
UWaFyV83spPuFSF9nMJqUqw=
=z14i
-----END PGP SIGNATURE-----

--zq44+AAfm4giZpo5--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070803090530.GH2738>