diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 22f42853f..0ef806876 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,76 @@ +2002-05-17 Jeff Johnston + + * Makefile.am: Copy and install headers from sys/machine/include + directory. Also pass $toollibdir to lower-level directories. + * Makefile.in: Regenerated. + * libc/include/stdio.h[!_REENT_ONLY]: Change stdin, stdout, and + stderr to use _REENT macro instead of _impure_ptr directly. + * libc/include/sys/config.h[__i386__][__linux__]: Define + __DYNAMIC_REENT__. + * libc/include/sys/reent.h[!_REENT_ONLY]: Change _REENT macro to be + call to __getreent() function if !__SINGLE_THREAD__ and + __DYNAMIC_REENT__ is set. + * libc/reent/Makefile.am: Add support for getreent.c. + * libc/reent/Makefile.in: Regenerated. + * libc/string/strerror.c: Add check if EOPNOTSUPP and ENOTSUP are same. + * libc/sys/linux/Makefile.am: Add support for new files. + * libc/sys/linux/configure.in: Add $EXTRA_DIRS variable. + * libc/sys/linux/Makefile.in: Regenerated. + * libc/sys/linux/configure: Ditto. + * libc/sys/linux/io.c: Add poll syscall. Also weak-alias + __close, __read, __write, __poll, __open, __lseek, __fcntl from + their __libc_ counterparts. + * libc/sys/linux/io64.c: Add __libc_ prefix to lseek64 and open64 + and weak-alias to regular names. + * libc/sys/linux/pread64.c: Rename to __libc_pread64 and weak-alias + to pread64 and __pread64. + * libc/sys/linux/process.c: Weak_alias __libc_getpid to __getpid. + * libc/sys/linux/pwrite64.c: Rename to __libc_pwrite64 and + weak-alias to pwrite64. + * libc/sys/linux/sched.c: Weak-alias __libc_sched_getparam, + __libc_sched_getscheduler, __libc_sched_get_priority_max, + __libc_sched_get_priority_min, and __libc_sched_setschedule to + name with __ instead of __libc_. + * libc/sys/linux/siglongjmp.c: Include . + Rename siglongjmp to __libc_siglongjmp and weak-alias to siglongjmp. + Call __libc_longjmp instead of longjmp, from __libc_siglongjmp. + * libc/sys/linux/signal.c: Rename raise to __libc_raise and weak-alias + to raise. + * libc/sys/linux/socket.c: Weak-alias __libc_connect to __connect and + __libc_send to __send. + * libc/sys/linux/time.c: Weak-alias __libc_gettimeofday to + __gettimeofday. + * libc/sys/linux/wait.c: Rename wait to __libc_wait and weak-alias + it to wait. Rename wait3 to __libc_wait3 and weak-alias it to wait3. + * libc/sys/linux/include/setjmp.h: Use __jmp_buf in sigjmp_buf + type and typedef __jmp_buf to jmp_buf. + * libc/sys/linux/machine/i386/Makefile.am: Add syscalls.c and + setjmp.S. + * libc/sys/linux/machine/i386/Makefile.in: Regenerated. + * libc/sys/linux/machine/i386/crt0.c: Add support to clear .bss + section. + * libc/sys/linux/machine/i386/socketcall.h: Change to use __libc_ + prefix for function macros and then use weak_alias() to regular names. + * libc/sys/linux/machine/i386/syscall.h: Ditto. + * libc/sys/linux/sys/errno.h: Define EOPNOTSUP to be ENOTSUP. + * libc/sys/linux/sys/stdio.h: Define _flockfile and _funlockfile + to be flockfile() and funlockfile() respectively. + * libc/sys/linux/sys/types.h + * libc/reent/getreent.c: New file. + * libc/sys/linux/flockfile.c: Ditto. + * libc/sys/linux/funlockfile.c: Ditto. + * libc/sys/linux/getreent.c: Ditto. + * libc/sys/linux/pread.c: Ditto. + * libc/sys/linux/pwrite.c: Ditto. + * libc/sys/linux/raise.c: Ditto. + * libc/sys/linux/system.c: Ditto. + * libc/sys/linux/tcdrain.c: Ditto. + * libc/sys/linux/machine/i386/i386mach.h: Ditto. + * libc/sys/linux/machine/i386/setjmp.S: Ditto. + * libc/sys/linux/machine/i386/syscalls.c: Ditto. + * libc/sys/linux/machine/i386/weakalias.h: Ditto. + * libc/sys/linux/machine/i386/include/setjmp.h: Ditto. + 2002-05-14 Dhananjay Deshpande * newlib/libc/sys/h8300hms/Makeile.am (lib_a_SOURCES): Add read.c. diff --git a/newlib/Makefile.am b/newlib/Makefile.am index d4c437f8d..38031f9ca 100644 --- a/newlib/Makefile.am +++ b/newlib/Makefile.am @@ -43,6 +43,7 @@ AM_MAKEFLAGS = \ "libdir=$(libdir)" \ "prefix=$(prefix)" \ "tooldir=$(tooldir)" \ + "toollibdir=$(toollibdir)" \ "AR=$(AR)" \ "AS=$(AS)" \ "CC=$(CC_FOR_NEWLIB)" \ @@ -205,6 +206,11 @@ stmp-targ-include: config.status cp $$i targ-include/machine/`basename $$i`; \ else true; fi ; \ done + -for i in $(srcdir)/libc/sys/$(sys_dir)/machine/$(machine_dir)/include/*.h; do \ + if [ -f $$i ]; then \ + cp $$i targ-include/machine/`basename $$i`; \ + else true; fi ; \ + done touch $@ CLEANFILES = targ-include stmp-targ-include @@ -244,6 +250,11 @@ endif $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \ else true; fi ; \ done ; \ + for i in $(srcdir)/libc/sys/$(sys_dir)/machine/$(machine_dir)/include/*.h; do \ + if [ -f $$i ]; then \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/machine/`basename $$i`; \ + else true; fi ; \ + done ; \ else true; fi # Force makedoc to be built before building info files. diff --git a/newlib/Makefile.in b/newlib/Makefile.in index cbb3d7ff2..c119be665 100644 --- a/newlib/Makefile.in +++ b/newlib/Makefile.in @@ -140,6 +140,7 @@ AM_MAKEFLAGS = \ "libdir=$(libdir)" \ "prefix=$(prefix)" \ "tooldir=$(tooldir)" \ + "toollibdir=$(toollibdir)" \ "AR=$(AR)" \ "AS=$(AS)" \ "CC=$(CC_FOR_NEWLIB)" \ @@ -731,6 +732,11 @@ stmp-targ-include: config.status cp $$i targ-include/machine/`basename $$i`; \ else true; fi ; \ done + -for i in $(srcdir)/libc/sys/$(sys_dir)/machine/$(machine_dir)/include/*.h; do \ + if [ -f $$i ]; then \ + cp $$i targ-include/machine/`basename $$i`; \ + else true; fi ; \ + done touch $@ install-data-local: install-toollibLIBRARIES @@ -765,6 +771,11 @@ install-data-local: install-toollibLIBRARIES $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \ else true; fi ; \ done ; \ + for i in $(srcdir)/libc/sys/$(sys_dir)/machine/$(machine_dir)/include/*.h; do \ + if [ -f $$i ]; then \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/machine/`basename $$i`; \ + else true; fi ; \ + done ; \ else true; fi # Force makedoc to be built before building info files. diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h index ccc048dec..73204cb72 100644 --- a/newlib/libc/include/stdio.h +++ b/newlib/libc/include/stdio.h @@ -131,9 +131,15 @@ typedef struct __sFILE FILE; #define TMP_MAX 26 +#ifndef _REENT_ONLY +#define stdin (_REENT->_stdin) +#define stdout (_REENT->_stdout) +#define stderr (_REENT->_stderr) +#else /* _REENT_ONLY */ #define stdin (_impure_ptr->_stdin) #define stdout (_impure_ptr->_stdout) #define stderr (_impure_ptr->_stderr) +#endif /* _REENT_ONLY */ #define _stdin_r(x) ((x)->_stdin) #define _stdout_r(x) ((x)->_stdout) diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index 05ba2681c..b5ecfb882 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -54,6 +54,10 @@ /* in other words, go32 */ #define _FLOAT_RET double #endif +#ifdef __linux__ +/* we want the reentrancy structure to be returned by a function */ +#define __DYNAMIC_REENT__ +#endif #endif #ifdef __M32R__ diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index 5303ed3dd..1edfad696 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -607,7 +607,14 @@ void _reclaim_reent _PARAMS ((struct _reent *)); /* #define _REENT_ONLY define this to get only reentrant routines */ #ifndef _REENT_ONLY -#define _REENT _impure_ptr + +#if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__) + struct _reent * _EXFUN(__getreent, (void)); +# define _REENT (__getreent()) +#else /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ +# define _REENT _impure_ptr +#endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ + #endif /* !_REENT_ONLY */ #ifdef __cplusplus diff --git a/newlib/libc/reent/Makefile.am b/newlib/libc/reent/Makefile.am index c01ffb593..0333eff03 100644 --- a/newlib/libc/reent/Makefile.am +++ b/newlib/libc/reent/Makefile.am @@ -10,6 +10,7 @@ LIB_SOURCES = \ impure.c \ execr.c \ fstatr.c \ + getreent.c \ linkr.c \ lseekr.c \ openr.c \ diff --git a/newlib/libc/reent/Makefile.in b/newlib/libc/reent/Makefile.in index 2f61b2fe3..38e1c693d 100644 --- a/newlib/libc/reent/Makefile.in +++ b/newlib/libc/reent/Makefile.in @@ -108,6 +108,7 @@ LIB_SOURCES = \ impure.c \ execr.c \ fstatr.c \ + getreent.c \ linkr.c \ lseekr.c \ openr.c \ @@ -164,15 +165,16 @@ CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ lib_a_LIBADD = @USE_LIBTOOL_FALSE@lib_a_OBJECTS = closer.o reent.o impure.o execr.o \ -@USE_LIBTOOL_FALSE@fstatr.o linkr.o lseekr.o openr.o readr.o signalr.o \ -@USE_LIBTOOL_FALSE@signgam.o sbrkr.o statr.o timer.o unlinkr.o writer.o +@USE_LIBTOOL_FALSE@fstatr.o getreent.o linkr.o lseekr.o openr.o readr.o \ +@USE_LIBTOOL_FALSE@signalr.o signgam.o sbrkr.o statr.o timer.o \ +@USE_LIBTOOL_FALSE@unlinkr.o writer.o LTLIBRARIES = $(noinst_LTLIBRARIES) libreent_la_LIBADD = @USE_LIBTOOL_TRUE@libreent_la_OBJECTS = closer.lo reent.lo impure.lo \ -@USE_LIBTOOL_TRUE@execr.lo fstatr.lo linkr.lo lseekr.lo openr.lo \ -@USE_LIBTOOL_TRUE@readr.lo signalr.lo signgam.lo sbrkr.lo statr.lo \ -@USE_LIBTOOL_TRUE@timer.lo unlinkr.lo writer.lo +@USE_LIBTOOL_TRUE@execr.lo fstatr.lo getreent.lo linkr.lo lseekr.lo \ +@USE_LIBTOOL_TRUE@openr.lo readr.lo signalr.lo signgam.lo sbrkr.lo \ +@USE_LIBTOOL_TRUE@statr.lo timer.lo unlinkr.lo writer.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/reent/getreent.c b/newlib/libc/reent/getreent.c new file mode 100644 index 000000000..b53ff26c8 --- /dev/null +++ b/newlib/libc/reent/getreent.c @@ -0,0 +1,10 @@ +/* default reentrant pointer when multithread enabled */ + +#include <_ansi.h> +#include + +struct _reent * +_DEFUN_VOID(__getreent) +{ + return _impure_ptr; +} diff --git a/newlib/libc/string/strerror.c b/newlib/libc/string/strerror.c index 209eeb9cc..8bea4b768 100644 --- a/newlib/libc/string/strerror.c +++ b/newlib/libc/string/strerror.c @@ -736,7 +736,7 @@ _DEFUN (strerror, (errnum), error = "Socket is already connected"; break; #endif -#ifdef EOPNOTSUPP +#if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP)) case EOPNOTSUPP: error = "Operation not supported on socket"; break; diff --git a/newlib/libc/sys/linux/Makefile.am b/newlib/libc/sys/linux/Makefile.am index dfac93b92..ad9aed813 100644 --- a/newlib/libc/sys/linux/Makefile.am +++ b/newlib/libc/sys/linux/Makefile.am @@ -4,14 +4,17 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -SUBDIRS = machine . +SUBDIRS = machine \ + . + SUBLIBS = $(LINUX_MACH_LIB) LIB_SOURCES = \ - brk.c getoptlong.c ids.c inode.c io.c io64.c linux.c mmap.c \ - pread64.c process.c pwrite64.c realpath.c sched.c \ - select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ - sysconf.c systat.c termios.c time.c \ + brk.c flockfile.c funlockfile.c getoptlong.c getreent.c ids.c \ + inode.c io.c io64.c linux.c mmap.c \ + pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \ + sched.c select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ + sysconf.c systat.c system.c tcdrain.c termios.c time.c \ usleep.c wait.c # This will handle both /usr/src/linux-2.4/include/asm/signal.h (in Red Hat Linux 7.1) diff --git a/newlib/libc/sys/linux/Makefile.in b/newlib/libc/sys/linux/Makefile.in index cec25fa0e..c158f2a8a 100644 --- a/newlib/libc/sys/linux/Makefile.in +++ b/newlib/libc/sys/linux/Makefile.in @@ -93,14 +93,18 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -SUBDIRS = machine . +SUBDIRS = machine \ + . + + SUBLIBS = $(LINUX_MACH_LIB) LIB_SOURCES = \ - brk.c getoptlong.c ids.c inode.c io.c io64.c linux.c mmap.c \ - pread64.c process.c pwrite64.c realpath.c sched.c \ - select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ - sysconf.c systat.c termios.c time.c \ + brk.c flockfile.c funlockfile.c getoptlong.c getreent.c ids.c \ + inode.c io.c io64.c linux.c mmap.c \ + pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \ + sched.c select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ + sysconf.c systat.c system.c tcdrain.c termios.c time.c \ usleep.c wait.c @@ -131,20 +135,24 @@ LIBRARIES = $(noinst_LIBRARIES) DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ -@USE_LIBTOOL_FALSE@lib_a_OBJECTS = brk.o getoptlong.o ids.o inode.o \ -@USE_LIBTOOL_FALSE@io.o io64.o linux.o mmap.o pread64.o process.o \ -@USE_LIBTOOL_FALSE@pwrite64.o realpath.o sched.o select.o signal.o \ -@USE_LIBTOOL_FALSE@siglongjmp.o socket.o sleep.o stack.o sysconf.o \ -@USE_LIBTOOL_FALSE@systat.o termios.o time.o usleep.o wait.o +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = brk.o flockfile.o funlockfile.o \ +@USE_LIBTOOL_FALSE@getoptlong.o getreent.o ids.o inode.o io.o io64.o \ +@USE_LIBTOOL_FALSE@linux.o mmap.o pread.o pread64.o process.o pwrite.o \ +@USE_LIBTOOL_FALSE@pwrite64.o raise.o realpath.o sched.o select.o \ +@USE_LIBTOOL_FALSE@signal.o siglongjmp.o socket.o sleep.o stack.o \ +@USE_LIBTOOL_FALSE@sysconf.o systat.o system.o tcdrain.o termios.o \ +@USE_LIBTOOL_FALSE@time.o usleep.o wait.o LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@liblinux_la_DEPENDENCIES = -@USE_LIBTOOL_TRUE@liblinux_la_OBJECTS = brk.lo getoptlong.lo ids.lo \ -@USE_LIBTOOL_TRUE@inode.lo io.lo io64.lo linux.lo mmap.lo pread64.lo \ -@USE_LIBTOOL_TRUE@process.lo pwrite64.lo realpath.lo sched.lo select.lo \ -@USE_LIBTOOL_TRUE@signal.lo siglongjmp.lo socket.lo sleep.lo stack.lo \ -@USE_LIBTOOL_TRUE@sysconf.lo systat.lo termios.lo time.lo usleep.lo \ -@USE_LIBTOOL_TRUE@wait.lo +@USE_LIBTOOL_TRUE@liblinux_la_OBJECTS = brk.lo flockfile.lo \ +@USE_LIBTOOL_TRUE@funlockfile.lo getoptlong.lo getreent.lo ids.lo \ +@USE_LIBTOOL_TRUE@inode.lo io.lo io64.lo linux.lo mmap.lo pread.lo \ +@USE_LIBTOOL_TRUE@pread64.lo process.lo pwrite.lo pwrite64.lo raise.lo \ +@USE_LIBTOOL_TRUE@realpath.lo sched.lo select.lo signal.lo \ +@USE_LIBTOOL_TRUE@siglongjmp.lo socket.lo sleep.lo stack.lo sysconf.lo \ +@USE_LIBTOOL_TRUE@systat.lo system.lo tcdrain.lo termios.lo time.lo \ +@USE_LIBTOOL_TRUE@usleep.lo wait.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/sys/linux/configure b/newlib/libc/sys/linux/configure index 17f3f54d0..977c145a8 100755 --- a/newlib/libc/sys/linux/configure +++ b/newlib/libc/sys/linux/configure @@ -2369,7 +2369,7 @@ if test -n "${machine_dir}"; then fi -subdirs="machine" +subdirs="machine $EXTRA_DIRS" trap '' 1 2 15 @@ -2704,7 +2704,7 @@ if test "$no_recursion" != yes; then esac done - for ac_config_dir in machine; do + for ac_config_dir in machine $EXTRA_DIRS; do # Do not complain, so a configure script can configure whichever # parts of a large source tree are present. diff --git a/newlib/libc/sys/linux/configure.in b/newlib/libc/sys/linux/configure.in index f77da62fa..4b9c305bb 100644 --- a/newlib/libc/sys/linux/configure.in +++ b/newlib/libc/sys/linux/configure.in @@ -29,6 +29,6 @@ if test -n "${machine_dir}"; then fi AC_SUBST(LINUX_MACH_LIB) -AC_CONFIG_SUBDIRS(machine) +AC_CONFIG_SUBDIRS(machine $EXTRA_DIRS) AC_OUTPUT(Makefile) diff --git a/newlib/libc/sys/linux/flockfile.c b/newlib/libc/sys/linux/flockfile.c new file mode 100644 index 000000000..4a6cbc461 --- /dev/null +++ b/newlib/libc/sys/linux/flockfile.c @@ -0,0 +1,9 @@ +/* stub to allow libpthread to override */ + +#include +#include + +void __libc_flockfile (FILE *fp) +{ +} +weak_alias(__libc_flockfile,flockfile) diff --git a/newlib/libc/sys/linux/funlockfile.c b/newlib/libc/sys/linux/funlockfile.c new file mode 100644 index 000000000..82466d30a --- /dev/null +++ b/newlib/libc/sys/linux/funlockfile.c @@ -0,0 +1,9 @@ +/* stub to allow libpthread to override */ + +#include +#include + +void __libc_funlockfile (FILE *fp) +{ +} +weak_alias(__libc_funlockfile,funlockfile) diff --git a/newlib/libc/sys/linux/getreent.c b/newlib/libc/sys/linux/getreent.c new file mode 100644 index 000000000..2d842073a --- /dev/null +++ b/newlib/libc/sys/linux/getreent.c @@ -0,0 +1,12 @@ +/* default function used by _REENT when not using multithreading */ + +#include +#include + +struct _reent * +__libc_getreent (void) +{ + return _impure_ptr; +} +weak_alias(__libc_getreent,__getreent) + diff --git a/newlib/libc/sys/linux/include/setjmp.h b/newlib/libc/sys/linux/include/setjmp.h index 04a9536ee..f07dbab6d 100644 --- a/newlib/libc/sys/linux/include/setjmp.h +++ b/newlib/libc/sys/linux/include/setjmp.h @@ -15,11 +15,13 @@ extern "C" { typedef struct __sigjmpbuf { - jmp_buf __buf; + __jmp_buf __buf; int __is_mask_saved; sigset_t __saved_mask; } sigjmp_buf; +typedef __jmp_buf jmp_buf; + void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval)); int _EXFUN(setjmp,(jmp_buf __jmpb)); void _EXFUN(siglongjmp,(sigjmp_buf __jmpb, int __retval)); diff --git a/newlib/libc/sys/linux/io.c b/newlib/libc/sys/linux/io.c index 11622a861..242c7cbf8 100644 --- a/newlib/libc/sys/linux/io.c +++ b/newlib/libc/sys/linux/io.c @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -32,6 +33,7 @@ _syscall2(int,dup2,int,oldfd,int,newfd) _syscall3(int,fcntl,int,fd,int,cmd,long,arg) _syscall1(int,fdatasync,int,fd) _syscall1(int,fsync,int,fd) +_syscall3(int,poll,struct pollfd *,fds,nfds_t,nfds,int,timeout) static _syscall2(long,__flock,unsigned int,fd,unsigned int,cmd) static _syscall3(int,__ioctl,int,fd,int,request,void *,arg) @@ -58,3 +60,12 @@ int mkfifo(const char *path, mode_t mode) dev_t dev = 0; return __mknod(path, mode | S_IFIFO, &dev); } + +weak_alias(__libc_close,__close); +weak_alias(__libc_fcntl,__fcntl); +weak_alias(__libc_lseek,__lseek); +weak_alias(__libc_open,__open); +weak_alias(__libc_read,__read); +weak_alias(__libc_write,__write); +weak_alias(__libc_poll,__poll); + diff --git a/newlib/libc/sys/linux/io64.c b/newlib/libc/sys/linux/io64.c index ea40dcb10..f54c40597 100644 --- a/newlib/libc/sys/linux/io64.c +++ b/newlib/libc/sys/linux/io64.c @@ -20,14 +20,15 @@ _syscall2(int,stat64,const char *,name,struct stat64 *,st) static _syscall5(void,_llseek,int,fd,off_t,hi,off_t,lo,loff_t *,pos,int,whence) -loff_t lseek64(int fd, loff_t offset, int whence) +loff_t __libc_lseek64(int fd, loff_t offset, int whence) { loff_t pos; - _llseek(fd, offset >> 32, offset & 0xffffffff, &pos, whence); + __libc__llseek(fd, offset >> 32, offset & 0xffffffff, &pos, whence); return pos; } +weak_alias(__libc_lseek64,lseek64); -int open64(const char *path, int oflag, ...) +int __libc_open64(const char *path, int oflag, ...) { mode_t mode = 0; if (oflag & O_CREAT) @@ -37,7 +38,9 @@ int open64(const char *path, int oflag, ...) mode = va_arg(list, int); va_end(list); } - return open(path, oflag | O_LARGEFILE, mode); + return __libc_open(path, oflag | O_LARGEFILE, mode); } +weak_alias(__libc_open64,open64); +weak_alias(__libc_open64,__open64); diff --git a/newlib/libc/sys/linux/machine/i386/Makefile.am b/newlib/libc/sys/linux/machine/i386/Makefile.am index 791c2e851..330a414c0 100644 --- a/newlib/libc/sys/linux/machine/i386/Makefile.am +++ b/newlib/libc/sys/linux/machine/i386/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = sigset.c +LIB_SOURCES = setjmp.S sigset.c syscalls.c liblinuxi386_la_LDFLAGS = -Xcompiler -nostdlib @@ -22,5 +22,6 @@ include $(srcdir)/../../../../../Makefile.shared all: crt0.o +AM_CFLAGS = -I$(srcdir)/../.. ACLOCAL_AMFLAGS = -I ../../../../.. CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host diff --git a/newlib/libc/sys/linux/machine/i386/Makefile.in b/newlib/libc/sys/linux/machine/i386/Makefile.in index d2c07bec6..c84ef686c 100644 --- a/newlib/libc/sys/linux/machine/i386/Makefile.in +++ b/newlib/libc/sys/linux/machine/i386/Makefile.in @@ -92,7 +92,7 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = sigset.c +LIB_SOURCES = setjmp.S sigset.c syscalls.c liblinuxi386_la_LDFLAGS = -Xcompiler -nostdlib @@ -103,6 +103,7 @@ liblinuxi386_la_LDFLAGS = -Xcompiler -nostdlib @USE_LIBTOOL_FALSE@noinst_LIBRARIES = @USE_LIBTOOL_FALSE@lib.a @USE_LIBTOOL_FALSE@lib_a_SOURCES = @USE_LIBTOOL_FALSE@$(LIB_SOURCES) +AM_CFLAGS = -I$(srcdir)/../.. ACLOCAL_AMFLAGS = -I ../../../../.. CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -115,11 +116,12 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ lib_a_LIBADD = -@USE_LIBTOOL_FALSE@lib_a_OBJECTS = sigset.o +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = setjmp.o sigset.o syscalls.o LTLIBRARIES = $(noinst_LTLIBRARIES) liblinuxi386_la_LIBADD = -@USE_LIBTOOL_TRUE@liblinuxi386_la_OBJECTS = sigset.lo +@USE_LIBTOOL_TRUE@liblinuxi386_la_OBJECTS = setjmp.lo sigset.lo \ +@USE_LIBTOOL_TRUE@syscalls.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/sys/linux/machine/i386/crt0.c b/newlib/libc/sys/linux/machine/i386/crt0.c index 01ae7a397..cc9cb9249 100644 --- a/newlib/libc/sys/linux/machine/i386/crt0.c +++ b/newlib/libc/sys/linux/machine/i386/crt0.c @@ -9,12 +9,15 @@ #include #include +#include extern char **environ; extern int main(int argc,char **argv,char **envp); +extern void *_end; +extern void *__bss_start; void _start(int args) { @@ -29,6 +32,10 @@ void _start(int args) char **argv = (char **) (params+1); environ = argv+argc+1; + + /* clear bss */ + memset(__bss_start,0,((char *)_end - (char *)__bss_start)); + tzset(); /* initialize timezone info */ exit(main(argc,argv,environ)); } diff --git a/newlib/libc/sys/linux/machine/i386/i386mach.h b/newlib/libc/sys/linux/machine/i386/i386mach.h new file mode 100644 index 000000000..23c32190d --- /dev/null +++ b/newlib/libc/sys/linux/machine/i386/i386mach.h @@ -0,0 +1,83 @@ +/* This file was based on the modified setjmp.S performed by + * Joel Sherill (joel@OARcorp.com) which specified the use + * of the __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ macros. + ** + ** This file is distributed WITHOUT ANY WARRANTY; without even the implied + ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* These are predefined by new versions of GNU cpp. */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#define __REG_PREFIX__ % + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a##b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1(__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1(__REG_PREFIX__, x) + +#define eax REG(eax) +#define ebx REG(ebx) +#define ecx REG(ecx) +#define edx REG(edx) +#define esi REG(esi) +#define edi REG(edi) +#define ebp REG(ebp) +#define esp REG(esp) + +#define st0 REG(st) +#define st1 REG(st(1)) +#define st2 REG(st(2)) +#define st3 REG(st(3)) +#define st4 REG(st(4)) +#define st5 REG(st(5)) +#define st6 REG(st(6)) +#define st7 REG(st(7)) + +#define ax REG(ax) +#define bx REG(bx) +#define cx REG(cx) +#define dx REG(dx) + +#define ah REG(ah) +#define bh REG(bh) +#define ch REG(ch) +#define dh REG(dh) + +#define al REG(al) +#define bl REG(bl) +#define cl REG(cl) +#define dl REG(dl) + +#define mm1 REG(mm1) +#define mm2 REG(mm2) +#define mm3 REG(mm3) +#define mm4 REG(mm4) +#define mm5 REG(mm5) +#define mm6 REG(mm6) +#define mm7 REG(mm7) + +#ifdef _I386MACH_NEED_SOTYPE_FUNCTION +#define SOTYPE_FUNCTION(sym) .type SYM(sym),@function +#else +#define SOTYPE_FUNCTION(sym) +#endif + +#ifdef _I386MACH_ALLOW_HW_INTERRUPTS +#define __CLI +#define __STI +#else +#define __CLI cli +#define __STI sti +#endif diff --git a/newlib/libc/sys/linux/machine/i386/include/setjmp.h b/newlib/libc/sys/linux/machine/i386/include/setjmp.h new file mode 100644 index 000000000..f080c3d9f --- /dev/null +++ b/newlib/libc/sys/linux/machine/i386/include/setjmp.h @@ -0,0 +1,6 @@ +#define _JBLEN 9 +typedef long __jmp_buf[_JBLEN]; + +#define SP_INDEX 7 +#define _JMPBUF_UNWINDS(buf, address) \ + ((void *)(address) < (void *)(buf)[SP_INDEX]) diff --git a/newlib/libc/sys/linux/machine/i386/setjmp.S b/newlib/libc/sys/linux/machine/i386/setjmp.S new file mode 100644 index 000000000..d276f55fb --- /dev/null +++ b/newlib/libc/sys/linux/machine/i386/setjmp.S @@ -0,0 +1,91 @@ +/* This is file is a merger of SETJMP.S and LONGJMP.S */ +/* + * This file was modified to use the __USER_LABEL_PREFIX__ and + * __REGISTER_PREFIX__ macros defined by later versions of GNU cpp by + * Joel Sherrill (joel@OARcorp.com) + * Slight change: now includes i386mach.h for this (Werner Almesberger) + * + * Copyright (C) 1991 DJ Delorie + * All rights reserved. + * + * Redistribution and use in source and binary forms is permitted + * provided that the above copyright notice and following paragraph are + * duplicated in all such forms. + * + * This file is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + /* + ** jmp_buf: + ** eax ebx ecx edx esi edi ebp esp eip + ** 0 4 8 12 16 20 24 28 32 + */ + + #include "i386mach.h" + + .global SYM (setjmp) + .global SYM (__libc_longjmp) + .weak SYM (longjmp) + SOTYPE_FUNCTION(setjmp) + SOTYPE_FUNCTION(longjmp) + SOTYPE_FUNCTION(__libc_longjmp) + +SYM (setjmp): + + pushl ebp + movl esp,ebp + + pushl edi + movl 8 (ebp),edi + + movl eax,0 (edi) + movl ebx,4 (edi) + movl ecx,8 (edi) + movl edx,12 (edi) + movl esi,16 (edi) + + movl -4 (ebp),eax + movl eax,20 (edi) + + movl 0 (ebp),eax + movl eax,24 (edi) + + movl esp,eax + addl $12,eax + movl eax,28 (edi) + + movl 4 (ebp),eax + movl eax,32 (edi) + + popl edi + movl $0,eax + leave + ret + +SYM (__libc_longjmp): +SYM (longjmp): + .weak longjmp + pushl ebp + movl esp,ebp + + movl 8(ebp),edi /* get jmp_buf */ + movl 12(ebp),eax /* store retval in j->eax */ + movl eax,0(edi) + + movl 24(edi),ebp + + __CLI + movl 28(edi),esp + + pushl 32(edi) + + movl 0(edi),eax + movl 4(edi),ebx + movl 8(edi),ecx + movl 12(edi),edx + movl 16(edi),esi + movl 20(edi),edi + __STI + + ret diff --git a/newlib/libc/sys/linux/machine/i386/socketcall.h b/newlib/libc/sys/linux/machine/i386/socketcall.h index 7c1973962..bd83d5175 100644 --- a/newlib/libc/sys/linux/machine/i386/socketcall.h +++ b/newlib/libc/sys/linux/machine/i386/socketcall.h @@ -6,6 +6,7 @@ #define _SOCKETCALL_H +#include #include #include #include "sockops.h" @@ -25,32 +26,38 @@ __syscall_return(type,__res); \ #undef _sockcall1 #define _sockcall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #undef _sockcall2 #define _sockcall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1, type2 arg2) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1, type2 arg2) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #undef _sockcall3 #define _sockcall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1, type2 arg2, type3 arg3) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1, type2 arg2, type3 arg3) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #undef _sockcall4 #define _sockcall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #undef _sockcall5 #define _sockcall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #undef _sockcall6 #define _sockcall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \ -__sockcall_base(type,name) +type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \ +__sockcall_base(type,name) \ +weak_alias(__libc_##name,name) #endif /* _SOCKETCALL_H */ diff --git a/newlib/libc/sys/linux/machine/i386/syscall.h b/newlib/libc/sys/linux/machine/i386/syscall.h index c8f265f68..b165f0442 100644 --- a/newlib/libc/sys/linux/machine/i386/syscall.h +++ b/newlib/libc/sys/linux/machine/i386/syscall.h @@ -5,6 +5,7 @@ #ifndef SYSCALL_H +#include #include #include @@ -22,6 +23,12 @@ * PIC uses %ebx, so we need to save it during system calls */ +#undef __inline_syscall0 +#define __inline_syscall0(name,ret) \ +__asm__ volatile ("int $0x80" \ + : "=a" (ret) \ + : "0" (__NR_##name)); + #undef __inline_syscall1 #define __inline_syscall1(name,ret,arg1) \ __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ @@ -61,61 +68,77 @@ __asm__ volatile ("push %%ebx; lea 8(%%ebp),%%ebx; int $0x80; pop %%ebx" \ : "=a" (ret) \ : "0" (__NR_##name)); +#undef _syscall0 +#define _syscall0(type,name) \ +type __libc_##name (void) \ +{ \ +long __res; \ +__inline_syscall0(name,__res) \ +__syscall_return(type,__res); \ +} \ +weak_alias(__libc_##name,name); + #undef _syscall1 #define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ +type __libc_##name (type1 arg1) \ { \ long __res; \ __inline_syscall1(name,__res,arg1) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #undef _syscall2 #define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ +type __libc_##name (type1 arg1,type2 arg2) \ { \ long __res; \ __inline_syscall2(name,__res,arg1,arg2) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #undef _syscall3 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ +type __libc_##name (type1 arg1,type2 arg2,type3 arg3) \ { \ long __res; \ __inline_syscall3(name,__res,arg1,arg2,arg3) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #undef _syscall4 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +type __libc_##name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ { \ long __res; \ __inline_syscall4(name,__res,arg1,arg2,arg3,arg4) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #undef _syscall5 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ type5,arg5) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +type __libc_##name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ { \ long __res; \ __inline_syscall5(name,__res,arg1,arg2,arg3,arg4,arg5) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #undef _syscall6 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ type5,arg5,type6,arg6) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ +type __libc_##name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ { \ long __res; \ __inline_syscall6(name,__res,arg1,arg2,arg3,arg4,arg5,arg6) \ __syscall_return(type,__res); \ -} +} \ +weak_alias(__libc_##name,name); #endif /* __PIC__ && __i386__ */ diff --git a/newlib/libc/sys/linux/machine/i386/syscalls.c b/newlib/libc/sys/linux/machine/i386/syscalls.c new file mode 100644 index 000000000..838dd73b3 --- /dev/null +++ b/newlib/libc/sys/linux/machine/i386/syscalls.c @@ -0,0 +1,11 @@ +/* miscellaneous i386-specific linux syscalls */ + +/* Copyright 2002, Red Hat Inc. */ + +#include +#include +#include + +_syscall2(int,getrlimit,int,resource,struct rlimit *,rlp); +_syscall2(int,setrlimit,int,resource,const struct rlimit *,rlp); + diff --git a/newlib/libc/sys/linux/machine/i386/weakalias.h b/newlib/libc/sys/linux/machine/i386/weakalias.h new file mode 100644 index 000000000..539ee4ae4 --- /dev/null +++ b/newlib/libc/sys/linux/machine/i386/weakalias.h @@ -0,0 +1,4 @@ +#define weak_alias(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); + + diff --git a/newlib/libc/sys/linux/pread.c b/newlib/libc/sys/linux/pread.c new file mode 100644 index 000000000..ff8371e15 --- /dev/null +++ b/newlib/libc/sys/linux/pread.c @@ -0,0 +1,46 @@ +/* Linux version of pread so we can have a weak_alias */ + +#include <_ansi.h> +#include +#include +#include + +ssize_t +_DEFUN (_pread_r, (rptr, fd, buf, n, off), + struct _reent *rptr _AND + int fd _AND + _PTR buf _AND + size_t n _AND + off_t off) +{ + off_t cur_pos; + _READ_WRITE_RETURN_TYPE num_read; + + if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1) + return -1; + + if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1) + return -1; + + num_read = _read_r (rptr, fd, buf, n); + + if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return (ssize_t)num_read; +} + +#ifndef _REENT_ONLY + +ssize_t +_DEFUN (__libc_pread, (fd, buf, n, off), + int fd _AND + _PTR buf _AND + size_t n _AND + off_t off) +{ + return _pread_r (_REENT, fd, buf, n, off); +} +weak_alias(__libc_pread,pread) + +#endif diff --git a/newlib/libc/sys/linux/pread64.c b/newlib/libc/sys/linux/pread64.c index c6273f3c9..c4bdca706 100644 --- a/newlib/libc/sys/linux/pread64.c +++ b/newlib/libc/sys/linux/pread64.c @@ -35,9 +35,10 @@ Supporting OS subroutine required: <>, <>. #include <_ansi.h> #include #include +#include ssize_t -_DEFUN (pread64, (fd, buf, n, off), +_DEFUN (__libc_pread64, (fd, buf, n, off), int fd _AND _PTR buf _AND size_t n _AND @@ -59,4 +60,6 @@ _DEFUN (pread64, (fd, buf, n, off), return (ssize_t)num_read; } +weak_alias(__libc_pread64,pread64); +weak_alias(__libc_pread64,__pread64); diff --git a/newlib/libc/sys/linux/process.c b/newlib/libc/sys/linux/process.c index 00a9ed7a4..0419ec7ef 100644 --- a/newlib/libc/sys/linux/process.c +++ b/newlib/libc/sys/linux/process.c @@ -19,6 +19,8 @@ _syscall0(pid_t,getppid) _syscall0(pid_t,getpgrp) _syscall0(pid_t,setsid) +weak_alias(__libc_getpid,__getpid); + /* FIXME: get rid of noreturn warning */ #define return for (;;) diff --git a/newlib/libc/sys/linux/pwrite.c b/newlib/libc/sys/linux/pwrite.c new file mode 100644 index 000000000..239463e59 --- /dev/null +++ b/newlib/libc/sys/linux/pwrite.c @@ -0,0 +1,46 @@ +/* Linux version of pwrite so we can have a weak alias */ + +#include <_ansi.h> +#include +#include +#include + +ssize_t +_DEFUN (_pwrite_r, (rptr, fd, buf, n, off), + struct _reent *rptr _AND + int fd _AND + _CONST _PTR buf _AND + size_t n _AND + off_t off) +{ + off_t cur_pos; + _READ_WRITE_RETURN_TYPE num_written; + + if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1) + return -1; + + if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1) + return -1; + + num_written = _write_r (rptr, fd, buf, n); + + if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return (ssize_t)num_written; +} + +#ifndef _REENT_ONLY + +ssize_t +_DEFUN (__libc_pwrite, (fd, buf, n, off), + int fd _AND + _CONST _PTR buf _AND + size_t n _AND + off_t off) +{ + return _pwrite_r (_REENT, fd, buf, n, off); +} +weak_alias(__libc_pwrite,pwrite) + +#endif diff --git a/newlib/libc/sys/linux/pwrite64.c b/newlib/libc/sys/linux/pwrite64.c index 145616f15..f1d678493 100644 --- a/newlib/libc/sys/linux/pwrite64.c +++ b/newlib/libc/sys/linux/pwrite64.c @@ -35,9 +35,10 @@ Supporting OS subroutine required: <>, <>. #include <_ansi.h> #include #include +#include ssize_t -_DEFUN (pwrite64, (fd, buf, n, off), +_DEFUN (__libc_pwrite64, (fd, buf, n, off), int fd _AND _PTR buf _AND size_t n _AND @@ -59,4 +60,5 @@ _DEFUN (pwrite64, (fd, buf, n, off), return (ssize_t)num_written; } +weak_alias(__libc_pwrite64,pwrite64) diff --git a/newlib/libc/sys/linux/raise.c b/newlib/libc/sys/linux/raise.c new file mode 100644 index 000000000..d69561be1 --- /dev/null +++ b/newlib/libc/sys/linux/raise.c @@ -0,0 +1,3 @@ +/* empty file so we override regular raise */ + + diff --git a/newlib/libc/sys/linux/sched.c b/newlib/libc/sys/linux/sched.c index 6a23260ba..b0df1a9e6 100644 --- a/newlib/libc/sys/linux/sched.c +++ b/newlib/libc/sys/linux/sched.c @@ -14,3 +14,9 @@ _syscall2(int,sched_rr_get_interval,pid_t,pid,struct timespec *,interval); _syscall2(int,sched_setparam,pid_t,pid,const struct sched_param *,sched); _syscall3(int,sched_setscheduler,pid_t,pid,int,policy,const struct sched_param *,sched); _syscall0(int,sched_yield); + +weak_alias(__libc_sched_getparam,__sched_getparam); +weak_alias(__libc_sched_getscheduler,__sched_getscheduler); +weak_alias(__libc_sched_get_priority_max,__sched_get_priority_max); +weak_alias(__libc_sched_get_priority_min,__sched_get_priority_min); +weak_alias(__libc_sched_setscheduler,__sched_setscheduler); diff --git a/newlib/libc/sys/linux/siglongjmp.c b/newlib/libc/sys/linux/siglongjmp.c index 075ed4421..bc3c5b79e 100644 --- a/newlib/libc/sys/linux/siglongjmp.c +++ b/newlib/libc/sys/linux/siglongjmp.c @@ -5,12 +5,14 @@ #include #include +#include void -siglongjmp (sigjmp_buf env, int val) +__libc_siglongjmp (sigjmp_buf env, int val) { if (env.__is_mask_saved) sigprocmask (SIG_SETMASK, &env.__saved_mask, NULL); - longjmp (env.__buf, val); + __libc_longjmp (env.__buf, val); } +weak_alias(__libc_siglongjmp,siglongjmp); diff --git a/newlib/libc/sys/linux/signal.c b/newlib/libc/sys/linux/signal.c index 7b8f0f4db..0855ed9e0 100644 --- a/newlib/libc/sys/linux/signal.c +++ b/newlib/libc/sys/linux/signal.c @@ -50,11 +50,11 @@ int sigblock(int mask) /* BSD */ return __ssetmask(mask | __sgetmask()); } - -int raise(int sig) +int __libc_raise(int sig) { return kill(getpid(),sig); } +weak_alias(__libc_raise,raise) int sigtimedwait(const sigset_t *set, siginfo_t *info, struct timespec *timeout) diff --git a/newlib/libc/sys/linux/socket.c b/newlib/libc/sys/linux/socket.c index 896530f3a..daba98934 100644 --- a/newlib/libc/sys/linux/socket.c +++ b/newlib/libc/sys/linux/socket.c @@ -28,3 +28,5 @@ _sockcall3(int,socket,int,domain,int,type,int,protocol) _sockcall4(int,socketpair,int,domain,int,type,int,protocol,int,fds[2]) _sockcall3(ssize_t,sendmsg,int,fd,const struct msghdr *,message,int,flags) +weak_alias(__libc_connect,__connect); +weak_alias(__libc_send,__send); diff --git a/newlib/libc/sys/linux/sys/errno.h b/newlib/libc/sys/linux/sys/errno.h index a1452bc9a..527a5f3a7 100644 --- a/newlib/libc/sys/linux/sys/errno.h +++ b/newlib/libc/sys/linux/sys/errno.h @@ -25,4 +25,6 @@ extern __IMPORT int _sys_nerr; #include +#define ENOTSUP EOPNOTSUPP + #endif diff --git a/newlib/libc/sys/linux/sys/stdio.h b/newlib/libc/sys/linux/sys/stdio.h index 859406f3f..5c51d3b0d 100644 --- a/newlib/libc/sys/linux/sys/stdio.h +++ b/newlib/libc/sys/linux/sys/stdio.h @@ -6,10 +6,10 @@ LinuxThreads. */ #if !defined(__SINGLE_THREAD__) # if !defined(_flockfile) -# define _flockfile(fp) /* FIXME: Uncomment when LinuxThreads is in: flockfile(fp) */ +# define _flockfile(fp) flockfile(fp) # endif # if !defined(_funlockfile) -# define _funlockfile(fp) /* FIXME: Uncomment when LinuxThreads is in: funlockfile(fp) */ +# define _funlockfile(fp) funlockfile(fp) # endif #endif /* __SINGLE_THREAD__ */ diff --git a/newlib/libc/sys/linux/sys/types.h b/newlib/libc/sys/linux/sys/types.h index 637463b06..e72a7017d 100644 --- a/newlib/libc/sys/linux/sys/types.h +++ b/newlib/libc/sys/linux/sys/types.h @@ -10,6 +10,7 @@ * libc/include/sys/types.h. Repeat those here and * skip the kernel's definitions. */ +#include #include #ifndef __time_t_defined @@ -30,6 +31,41 @@ typedef unsigned int __useconds_t; typedef __pid_t pid_t; typedef __off_t off_t; typedef __loff_t loff_t; +typedef __uint32_t uintptr_t; +typedef __int32_t intptr_t; + +#ifndef __u_char_defined +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; +#ifdef __GNUC__ +__extension__ typedef long long quad_t; +__extension__ typedef unsigned long long u_quad_t; +#else +typedef struct + { + long int __val[2]; + } quad_t; +typedef struct + { + unsigned long __val[2]; + } u_quad_t; +#endif +typedef struct + { + int __val[2]; + } fsid_t; +#define __u_char_defined +#endif + +#ifndef __daddr_t_defined +typedef int daddr_t; +typedef char *caddr_t; +# define __daddr_t_defined +#endif + +typedef int clockid_t; /* Time Value Specification Structures, P1003.1b-1993, p. 261 */ @@ -42,5 +78,6 @@ struct timespec { #endif /* !_STRUCT_TIMESPEC */ #include +#define __mode_t_defined #endif diff --git a/newlib/libc/sys/linux/system.c b/newlib/libc/sys/linux/system.c new file mode 100644 index 000000000..f8edfbf63 --- /dev/null +++ b/newlib/libc/sys/linux/system.c @@ -0,0 +1,158 @@ +/* Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifndef HAVE_GNU_LD +#define __environ environ +#endif + +#define SHELL_PATH "/bin/sh" /* Path of the shell. */ +#define SHELL_NAME "sh" /* Name to give it. */ + +/* Execute LINE as a shell command, returning its status. */ +int +__libc_system (const char *line) +{ + int status, save; + pid_t pid; + struct sigaction sa, intr, quit; +#ifndef WAITPID_CANNOT_BLOCK_SIGCHLD + sigset_t block, omask; +#endif + + if (line == NULL) + /* Check that we have a command processor available. It might + not be available after a chroot(), for example. */ + return __libc_system ("exit 0") == 0; + + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset (&sa.sa_mask); + + if (sigaction (SIGINT, &sa, &intr) < 0) + return -1; + if (sigaction (SIGQUIT, &sa, &quit) < 0) + { + save = errno; + (void) sigaction (SIGINT, &intr, (struct sigaction *) NULL); + errno = save; + return -1; + } + +#ifndef WAITPID_CANNOT_BLOCK_SIGCHLD + +/* SCO 3.2v4 has a bug where `waitpid' will never return if SIGCHLD is + blocked. This makes it impossible for `system' to be implemented in + compliance with POSIX.2-1992. They have acknowledged that this is a bug + but I have not seen nor heard of any forthcoming fix. */ + + sigemptyset (&block); + sigaddset (&block, SIGCHLD); + save = errno; + if (sigprocmask (SIG_BLOCK, &block, &omask) < 0) + { + if (errno == ENOSYS) + errno = save; + else + { + save = errno; + (void) sigaction (SIGINT, &intr, (struct sigaction *) NULL); + (void) sigaction (SIGQUIT, &quit, (struct sigaction *) NULL); + errno = save; + return -1; + } + } +# define UNBLOCK sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL) +#else +# define UNBLOCK 0 +#endif + + pid = fork (); + if (pid == (pid_t) 0) + { + /* Child side. */ + const char *new_argv[4]; + new_argv[0] = SHELL_NAME; + new_argv[1] = "-c"; + new_argv[2] = line; + new_argv[3] = NULL; + + /* Restore the signals. */ + (void) sigaction (SIGINT, &intr, (struct sigaction *) NULL); + (void) sigaction (SIGQUIT, &quit, (struct sigaction *) NULL); + (void) UNBLOCK; + + /* Exec the shell. */ + (void) execve (SHELL_PATH, (char *const *) new_argv, __environ); + _exit (127); + } + else if (pid < (pid_t) 0) + /* The fork failed. */ + status = -1; + else + /* Parent side. */ + { +#ifdef NO_WAITPID + pid_t child; + do + { + child = wait (&status); + if (child <= -1 && errno != EINTR) + { + status = -1; + break; + } + /* Note that pid cannot be <= -1 and therefore the loop continues + when wait returned with EINTR. */ + } + while (child != pid); +#else + int n; + + do + n = waitpid (pid, &status, 0); + while (n == -1 && errno == EINTR); + + if (n != pid) + status = -1; +#endif + } + + save = errno; + if ((sigaction (SIGINT, &intr, (struct sigaction *) NULL) | + sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) | + UNBLOCK) != 0) + { + if (errno == ENOSYS) + errno = save; + else + return -1; + } + + return status; +} +weak_alias (__libc_system, system) diff --git a/newlib/libc/sys/linux/tcdrain.c b/newlib/libc/sys/linux/tcdrain.c new file mode 100644 index 000000000..364fc035f --- /dev/null +++ b/newlib/libc/sys/linux/tcdrain.c @@ -0,0 +1,13 @@ +/* tcdrain - wait for transmission of output */ + +#include +#include +#include + +int +__libc_tcdrain (int fd) +{ + return ioctl (fd, TCSBRK, 1); +} +weak_alias (__libc_tcdrain, tcdrain) + diff --git a/newlib/libc/sys/linux/time.c b/newlib/libc/sys/linux/time.c index b53987353..a7ecc5adc 100644 --- a/newlib/libc/sys/linux/time.c +++ b/newlib/libc/sys/linux/time.c @@ -15,3 +15,4 @@ _syscall1(clock_t,times,struct tms *,buf) _syscall2(int,gettimeofday,struct timeval *,tv,struct timezone *,tz) _syscall2(int,nanosleep,const struct timespec *,req,struct timespec *,rem) +weak_alias(__libc_gettimeofday,__gettimeofday); diff --git a/newlib/libc/sys/linux/wait.c b/newlib/libc/sys/linux/wait.c index 70962a04e..bc2716342 100644 --- a/newlib/libc/sys/linux/wait.c +++ b/newlib/libc/sys/linux/wait.c @@ -11,13 +11,16 @@ _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options) _syscall4(pid_t,wait4,pid_t,pid,int *,status,int,options,struct rusage *,rusage) -pid_t wait3(int *status,int options,struct rusage *rusage) +pid_t __libc_wait3(int *status,int options,struct rusage *rusage) { - return wait4(-1,status,options,rusage); + return __libc_wait4(-1,status,options,rusage); +} +weak_alias(__libc_wait3,wait3) + +pid_t __libc_wait(int *status) +{ + return __libc_waitpid(-1,status,0); } - -pid_t wait(int *status) -{ - return waitpid(-1,status,0); -} +weak_alias(__libc_wait,__wait); +weak_alias(__libc_wait,wait);