Re: how sys_select, sys_fork, ... are defined for thread libraries?

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

The C standard specifies that namespace of identifiers starting with __ or
_ 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.


pgp6Dcyp1BXUr.pgp
Description: PGP signature


how sys_select, sys_fork, ... are defined for thread libraries?

2007-08-02 Thread Jin Guojun
I am trying to understand how these __sys_xxx functions are defined for 
thread libraries.
Following string search tells that all thread libraries are using these 
__sys_xxx functions,
for example, __sys_select(). However, the search also shows that these 
functions are not defined anywhere in the entire source tree.


/usr/src: findstring sys_select "*.[hcS]"
total files= 21687 : pattern= sys_select rootdir= /usr/src
regular mode: Thu Aug 2 13:31:40 PDT 2007
./lib/libc_r/uthread/uthread_fork.c
91:  * __sys_select:

./lib/libpthread/thread/thr_private.h
1264:int __sys_select(int, fd_set *, fd_set *, fd_set *, struct 
timeval *);


./lib/libpthread/thread/thr_select.c
61: ret = __sys_select(numfds, readfds, writefds, exceptfds, 
timeout);


./lib/libthr/thread/thr_private.h
805:int __sys_select(int, fd_set *, fd_set *, fd_set *, struct 
timeval *);


./lib/libthr/thread/thr_syscalls.c
435:ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);


By searching the usr/lib objects, I found them in libc, but they are not 
in libc source tree.
Can someone shed some light on how these system calls are built into 
libc and what is the

different between standard syscall APIs and these __sys_syscall APIs,
e.g., __sys_read() vs. read(), etc.

Thanks,

-Jin


nm /usr/lib/libc.a | grep __sys_
0008 T __sys_sigreturn
0008 T __sys_setlogin
0008 T __sys_reboot
... snapped
0008 T __sys_kse_release
0008 T __sys_kse_thr_interrupt
0008 T __sys_kse_create
0008 T __sys_kse_wakeup
... skipped
0008 T __sys_getdtablesize
0008 T __sys_select
0008 T __sys_ioctl
0008 T __sys_close
0008 T __sys_write
0008 T __sys_read
0008 T __sys___syscall

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"