edf5b2d716
Sat Sep 7 05:15:45 1996 Ulrich Drepper <drepper@cygnus.com> * libio/iofdopen: Initialize _lock field only if _IO_MTSAFE_IO. * libio/iofopen: Likewise. * libio/iofopncook.c: Likewise. * libio/iopopen.c: Likewise. * libio/iovsprintf.c: Likewise. * libio/iovsscanf.c: Likewise. * libio/memstream.c: Likewise. * libio/vasprintf.c: Likewise. * libio/vdprintf.c: Likewise. * libio/vsnprintf.c: Likewise. Sat Sep 7 03:55:47 1996 Ulrich Drepper <drepper@cygnus.com> * Makeconfig (soversions.mk): Also use shlib-versions files in add-on directories. * config.make.in (config-defines): Remove. Not used anymore. (defines): New variable. Initiliazed by @DEFINES@. * configure.in: Add AC_SUBST(DEFINES). * libio/Makefile (routines): When compiling reentrant libc add clearerr_u, feof_u, ferror_u, fputc_u, getc_u, getchar_u, iofflush_u, putc_u, putchar_u, ioflockfile. (CPPFLAGS): Add -D_IO_MTSAFE_IO for reentrant libc. * sysdeps/stub/libc-lock.h: Add stubs for __libc_cleanup_region_start and __libc_cleanup_region_end. * sysdeps/unix/i386/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. * sysdeps/unix/sysv/linux/i386/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. (__errno_location): New function. * sysdeps/unix/sysv/linux/i386/sysdep.h [PIC]: Add second syscall_error handler for reentrant libc. * sysdeps/unix/opendir.c: Remove unneeded `;'. * libio.h [_IO_MTSAFE_IO]: Include <pthread.h>. [!_IO_MTSAFE_IO]: Define _IO_flockfile and _IO_funlockfile as empty macros. * libioP.h: Include <libc-lock.h>. * libio/stdio.h: Add prototypes for *_locked and *_unlocked functions. * libio/clearerr.c: Use _IO_ protected versions of flockfile and funlockfile to be namespace clean. * libio/genops.c: Use __libc_lock_* macros for handling lock. * libio/iofdopen: Add initialization of _lock in _IO_FILE. * libio/iofopen: Likewise. * libio/iofopncook.c: Likewise. * libio/iopopen.c: Likewise. * libio/iovsprintf.c: Likewise. * libio/iovsscanf.c: Likewise. * libio/memstream.c: Likewise. * libio/vasprintf.c: Likewise. * libio/vdprintf.c: Likewise. * libio/vsnprintf.c: Likewise. * libio/fgetc.c: Use __libc_cleanup_region_* macros instead of flockfile etc. * libio/fputc.c: Likewise. * libio/freopen.c: Likewise. * libio/fseek.c: Likewise. * libio/getc.c: Likewise. * libio/getchar.c: Likewise. * libio/iofclose.c: Likewise. * libio/iofflush.c: Likewise. * libio/iofgetpos.c: Likewise. * libio/iofgets.c: Likewise. * libio/iofputs.c: Likewise. * libio/iofread.c: Likewise. * libio/iofsetpos.c: Likewise. * libio/ioftell.c: Likewise. * libio/iofwrite.c: Likewise. * libio/iogetdelim.c: Likewise. * libio/iogets.c: Likewise. * libio/ioputs.c: Likewise. * libio/iosetbuffer.c: Likewise. * libio/iosetvbuf.c: Likewise. * libio/ioungetc.c: Likewise. * libio/putc.c: Likewise. * libio/putchar.c: Likewise. * libio/rewind.c: Likewise. * stdio-common/vfprintf.c: Likewise. * stdio-common/vfscanf.c: Likewise. * libio/clearerr_u.c: Correct alias name. * libio/ferror_u.c: Likewise. * libio/fileno.c: Likewise. * libio/fputc_u.c: Likewise. * libio/getc.c: Likewise. * libio/getc_u.c: Likewise. * libio/getchar.c: Likewise. * libio/getchar_u.c: Likewise. * libio/putc.c: Likewise. * libio/putchar.c: Likewise. * libio/feof_u.c: Undefine macro with name of function before definition of function itself. * libio/ioflockfile.c: New file. Implementation of flockfile and funlockfile. * libio/putchar_u.c: Fix typo. Use stdout instead of fp. * malloc/malloc.h: Don't include <libc-lock.h> and don't declare _malloc_loc. * malloc/free.c: Include <libc-lock.h>. * malloc/realloc.c: Likewise. * malloc/malloc-find.c: Likewise. * malloc/malloc-size.c: Likewise. * malloc/malloc-walk.c: Likewise. * malloc/memalign.c: Likewise. * malloc/malloc.c: Likewise. * sysdeps/i386/dl-machine.h: Correct clearing of _dl_starting_up. Fri Sep 6 19:38:49 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/stub/libc-lock.h: Define __libc_lock_critical_start and __libc_lock_critical_end as empty macros. * malloc/malloc.h: Don't include <libc-lock.h> and don't declare __libc_malloc_lock. * malloc/free.c: Include <libc-lock.h>. * malloc/malloc-find.c: Likewise. * malloc/malloc-size.c: Likewise. * malloc/malloc-walk.c: Likewise. * malloc/malloc.c: Likewise. * malloc/memalign.c: Likewise. * malloc/realloc.c: Likewise. * Makefile: Undo change from Mon Sep 2 22:15:14 1996. No more extra_solibs pass. * Rules: Likewise. * extra-lib.mk: Likewise. * manual/Makefile: Likewise. * db/Makefile (makedb): Choose dependecies based on build-shared. Patch by Andres Schwab. * sysdeps/posix/sysconf.c: Don't use PTHREAD_DESTRUCTOR_ITERATIONS but _POSIX_THREAD_DESTRUCTOR_ITERATIONS. * sysdeps/unix/sysv/linux/errnos.h: New file. * sysdeps/unix/sysv/linux/schedbits.h: New file. * sysdeps/unix/sysv/linux/waitflags.h: New file. * sysdeps/unix/sysv/linux/gnu/types.h: Add definition of `key_t'. Fri Sep 6 08:26:31 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * rpm/template: Fix typo in %build section. Fri Sep 6 03:31:07 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/errnos.h: Don't define errno macro when building libc without thread support. * resolv/netdb.h: Likewise for h_errno macro. Thu Sep 5 23:01:48 1996 Ulrich Drepper <drepper@cygnus.com> * libc-symbols.h: Add new macro weak_const_function. It's like weak_function, but the function is additionally marked as const. * features.h: Only include <sys/cdefs.h> if !__ASSEMBLER__. Thu Sep 5 22:55:49 1996 Richard Henderson <rth@tamu.edu> * inet/herrno.c (__h_errno_location): New function. (h_errno): Make strong_alias __h_errno so that we can access the variable even if `h_errno' is a macro. * resolv/netdb.h: Define macro h_errno to access thread specific version of h_errno variable. Declare alias __h_errno for h_errno. * resolv/res_query (h_errno): Remove definition. * sysdeps/unix/sysv/linux/errnos.h [!__ASSEMBLER__ && __USE_REENTRANT]: Add macro `errno' to get thread specific variable. * sysdeps/unix/alpha/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. (__errno_location): New function. Thu Sep 5 21:08:44 1996 Ulrich Drepper <drepper@cygnus.com> * posix/gnu/types.h: Remove definition of key_t. * sysdeps/generic/gnu/types.h: Move it to here. * sysdeps/unix/sysv/linux/gnu/types.h: Add Linux specific definition of key_t. * sysdeps/unix/sysv/linux/waitflags.h: New file. Linux specific definitions. * sysdeps/unix/sysv/linux/schedbits.h: New file. Include clone prototypes and associated flags. Thu Sep 5 08:58:47 1996 Richard Henderson <rth@tamu.edu> * sysdeps/alpha/elf/start.S: Make _start global again. hertz. here. Wed Sep 4 16:16:13 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/mach/hurd/send.c (__send): De-ANSI-fy. * sysdeps/mach/hurd/sendto.c (sendto): Likewise.
182 lines
6.1 KiB
C
182 lines
6.1 KiB
C
/* Copyright (C) 1992, 93, 95, 96 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
|
Cambridge, MA 02139, USA. */
|
|
|
|
/* There is some commonality. */
|
|
#include <sysdeps/unix/i386/sysdep.h>
|
|
|
|
/* For Linux we can use the system call table in the header file
|
|
/usr/include/asm/unistd.h
|
|
of the kernel. But these symbols do not follow the SYS_* syntax
|
|
so we have to redefine the `SYS_ify' macro here. */
|
|
#undef SYS_ify
|
|
#ifdef __STDC__
|
|
# define SYS_ify(syscall_name) __NR_##syscall_name
|
|
#else
|
|
# define SYS_ify(syscall_name) __NR_/**/syscall_name
|
|
#endif
|
|
|
|
|
|
#ifdef ASSEMBLER
|
|
|
|
/* Linux uses a negative return value to indicate syscall errors, unlike
|
|
most Unices, which use the condition codes' carry flag. */
|
|
#undef PSEUDO
|
|
#define PSEUDO(name, syscall_name, args) \
|
|
.text; \
|
|
SYSCALL_ERROR_HANDLER \
|
|
ENTRY (name) \
|
|
DO_CALL (args, syscall_name); \
|
|
testl %eax, %eax; \
|
|
jl syscall_error;
|
|
|
|
#ifndef PIC
|
|
#define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
|
|
#else
|
|
/* Store (- %eax) into errno through the GOT. */
|
|
#ifdef _LIBC_REENTRANT
|
|
#define SYSCALL_ERROR_HANDLER \
|
|
.type syscall_error,@function; \
|
|
syscall_error: \
|
|
pushl %ebx; \
|
|
call 0f; \
|
|
0:popl %ebx; \
|
|
xorl %edx, %edx; \
|
|
addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx; \
|
|
subl %eax, %edx; \
|
|
movl errno@GOT(%ebx), %ecx; \
|
|
movl %edx, (%ecx); \
|
|
pushl %edx; \
|
|
call __errno_location@PLT; \
|
|
popl %ecx; \
|
|
popl %ebx; \
|
|
movl %ecx, (%eax); \
|
|
movl $-1, %eax; \
|
|
ret;
|
|
#else
|
|
#define SYSCALL_ERROR_HANDLER \
|
|
.type syscall_error,@function; \
|
|
syscall_error: \
|
|
call 0f; \
|
|
0:popl %ecx; \
|
|
xorl %edx, %edx; \
|
|
addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ecx; \
|
|
subl %eax, %edx; \
|
|
movl errno@GOT(%ecx), %ecx; \
|
|
movl %edx, (%ecx); \
|
|
movl $-1, %eax; \
|
|
ret;
|
|
#endif /* _LIBC_REENTRANT */
|
|
#endif /* PIC */
|
|
|
|
/* Linux takes system call arguments in registers:
|
|
|
|
syscall number %eax call-clobbered
|
|
arg 1 %ebx call-saved
|
|
arg 2 %ecx call-clobbered
|
|
arg 3 %edx call-clobbered
|
|
arg 4 %esi call-saved
|
|
arg 5 %edi call-saved
|
|
|
|
The stack layout upon entering the function is:
|
|
|
|
20(%esp) Arg# 5
|
|
16(%esp) Arg# 4
|
|
12(%esp) Arg# 3
|
|
8(%esp) Arg# 2
|
|
4(%esp) Arg# 1
|
|
(%esp) Return address
|
|
|
|
(Of course a function with say 3 arguments does not have entries for
|
|
arguments 4 and 5.)
|
|
|
|
The following code tries hard to be optimal. A general assuption
|
|
(which is true according to the data books I have) is that
|
|
|
|
2 * xchg is more expensive than pushl + movl + popl
|
|
|
|
Beside this a neat trick is used. The calling conventions for Linux
|
|
tell that among the registers used for parameters %ecx and %edx need
|
|
not be saved. Beside this we may clobber this registers even when
|
|
they are not used for parameter passing.
|
|
|
|
As a result one can see below that we save the content of the %ebx
|
|
register in the %edx register when we have less than 3 arguments
|
|
(2 * movl is less expensive than pushl + popl).
|
|
|
|
Second unlike for the other registers we don't save the content of
|
|
%ecx and %edx when we have than 1 and 2 registers resp.
|
|
|
|
The code below might look a bit long but we have to take care for
|
|
the pipelined processors (i586 and up). Here the `pushl' and `popl'
|
|
instructions are marked as NP (not pairable) but the exception is
|
|
two consecutive of these instruction. This gives no penalty on
|
|
i386 and i486 processors though. */
|
|
|
|
#undef DO_CALL
|
|
#define DO_CALL(args, syscall_name) \
|
|
PUSHARGS_##args \
|
|
DOARGS_##args \
|
|
movl $SYS_ify (syscall_name), %eax; \
|
|
int $0x80 \
|
|
POPARGS_##args
|
|
|
|
#define PUSHARGS_0 /* No arguments to push. */
|
|
#define DOARGS_0 /* No arguments to frob. */
|
|
#define POPARGS_0 /* No arguments to pop. */
|
|
#define _PUSHARGS_0 /* No arguments to push. */
|
|
#define _DOARGS_0(n) /* No arguments to frob. */
|
|
#define _POPARGS_0 /* No arguments to pop. */
|
|
|
|
#define PUSHARGS_1 movl %ebx, %edx; PUSHARGS_0
|
|
#define DOARGS_1 _DOARGS_1 (4)
|
|
#define POPARGS_1 POPARGS_0; movl %edx, %ebx
|
|
#define _PUSHARGS_1 pushl %ebx; _PUSHARGS_0
|
|
#define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
|
|
#define _POPARGS_1 _POPARGS_0; popl %ebx
|
|
|
|
#define PUSHARGS_2 PUSHARGS_1
|
|
#define DOARGS_2 _DOARGS_2 (8)
|
|
#define POPARGS_2 POPARGS_1
|
|
#define _PUSHARGS_2 _PUSHARGS_1
|
|
#define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
|
|
#define _POPARGS_2 _POPARGS_1
|
|
|
|
#define PUSHARGS_3 _PUSHARGS_2
|
|
#define DOARGS_3 _DOARGS_3 (16)
|
|
#define POPARGS_3 _POPARGS_3
|
|
#define _PUSHARGS_3 _PUSHARGS_2
|
|
#define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
|
|
#define _POPARGS_3 _POPARGS_2
|
|
|
|
#define PUSHARGS_4 _PUSHARGS_4
|
|
#define DOARGS_4 _DOARGS_4 (24)
|
|
#define POPARGS_4 _POPARGS_4
|
|
#define _PUSHARGS_4 pushl %esi; _PUSHARGS_3
|
|
#define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
|
|
#define _POPARGS_4 _POPARGS_3; popl %esi
|
|
|
|
#define PUSHARGS_5 _PUSHARGS_5
|
|
#define DOARGS_5 _DOARGS_5 (32)
|
|
#define POPARGS_5 _POPARGS_5
|
|
#define _PUSHARGS_5 pushl %edi; _PUSHARGS_4
|
|
#define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
|
|
#define _POPARGS_5 _POPARGS_4; popl %edi
|
|
|
|
#endif /* ASSEMBLER */
|