Browse Source

sync with psm: update errno handling to be the same on all arches

Mike Frysinger 17 years ago
parent
commit
190da1cd0c

+ 9 - 7
include/errno.h

@@ -43,30 +43,32 @@ __BEGIN_DECLS
    variable.  This redeclaration using the macro still works, but it
    will be a function declaration without a prototype and may trigger
    a -Wstrict-prototypes warning.  */
-# ifndef __ASSEMBLER__
-#  ifndef	errno
+#ifndef	errno
 extern int errno;
-#  endif
+#endif
 
-#  if defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+#if defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
 
 /* The full and simple forms of the name with which the program was
    invoked.  These variables are set up automatically at startup based on
    the value of ARGV[0] (this works only if you use GNU ld).  */
 extern char *program_invocation_name, *program_invocation_short_name;
-#  endif /* __USE_GNU */
-# endif /* __ASSEMBLER__ */
+#endif /* __USE_GNU */
 #endif /* _ERRNO_H */
 
 __END_DECLS
 
+#if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
+#include <bits/uClibc_errno.h>
+#endif
+
 #endif /* _ERRNO_H */
 
 /* The Hurd <bits/errno.h> defines `error_t' as an enumerated type so
    that printing `error_t' values in the debugger shows the names.  We
    might need this definition sometimes even if this file was included
    before.  */
-#if ( defined __USE_GNU || defined __need_error_t ) && !defined __ASSEMBLER__
+#if defined __USE_GNU || defined __need_error_t
 # ifndef __error_t_defined
 typedef int error_t;
 #  define __error_t_defined	1

+ 8 - 0
libc/misc/internals/__errno_location.c

@@ -1,8 +1,16 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
 #include <errno.h>
 #undef errno
+extern int errno;
 libc_hidden_proto(errno)
 
 /* psm: moved to bits/errno.h: libc_hidden_proto(__errno_location) */
+libc_hidden_proto(__errno_location)
 int * weak_const_function __errno_location (void)
 {
     return &errno;

+ 7 - 0
libc/misc/internals/__h_errno_location.c

@@ -1,7 +1,14 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
 #define __FORCE_GLIBC
 #include <features.h>
 #include <netdb.h>
 #undef h_errno
+extern int h_errno;
 
 libc_hidden_proto(h_errno)
 

+ 4 - 4
libc/sysdeps/linux/alpha/bits/syscalls.h

@@ -9,12 +9,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 #define _syscall_return(type)						\
 	return (_sc_err ? __set_errno(_sc_ret), _sc_ret = -1L : 0), (type) _sc_ret
 

+ 5 - 7
libc/sysdeps/linux/arm/bits/syscalls.h

@@ -9,19 +9,17 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)	(__NR_##syscall_name)
-#endif
-
 /*
    Some of the sneaky macros in the code were taken from 
    glibc-2.3.2/sysdeps/unix/sysv/linux/arm/sysdep.h
 */
 
 #ifdef __ASSEMBLER__
+
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 /* Call a given syscall, with arguments loaded.  For EABI, we must
    save and restore r7 for the syscall number.  Unlike the DO_CALL
    macro in glibc, this macro does not load syscall arguments.  */

+ 3 - 7
libc/sysdeps/linux/bfin/bits/syscalls.h

@@ -9,15 +9,11 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) ((*__errno_location ()) = (val))
-#endif
+#ifndef __ASSEMBLER__
 
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)  (__NR_##syscall_name)
-#endif
+#include <errno.h>
 
-#ifndef __ASSEMBLER__
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
 
 /* user-visible error numbers are in the range -1 - -4095: see <asm-frv/errno.h> */
 #if defined _LIBC && !defined __set_errno

+ 29 - 23
libc/sysdeps/linux/common/bits/errno.h

@@ -1,5 +1,5 @@
 /* Error constants.  Linux specific version.
-   Copyright (C) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 1999, 2005 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
@@ -19,35 +19,41 @@
 
 #ifdef _ERRNO_H
 
-#include <bits/errno_values.h>
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <bits/errno_values.h>
 
-#ifndef ENOTSUP
+/* Linux has no ENOTSUP error code.  */
 # define ENOTSUP EOPNOTSUPP
-#endif
 
-#ifndef ECANCELED
-# define ECANCELED	125
-#endif
-
-#ifndef __ASSEMBLER__
+/* Older Linux versions also had no ECANCELED error code.  */
+# ifndef ECANCELED
+#  define ECANCELED	125
+# endif
 
-/* We now need a declaration of the `errno' variable.  */
-extern int errno;
+/* Support for error codes to support robust mutexes was added later, too.  */
+# ifndef EOWNERDEAD
+#  define EOWNERDEAD		130
+#  define ENOTRECOVERABLE	131
+# endif
 
+# ifndef __ASSEMBLER__
 /* Function to get address of global `errno' variable.  */
 extern int *__errno_location (void) __THROW __attribute__ ((__const__));
 
-# if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
-libc_hidden_proto(__errno_location)
-/* We wouldn't need a special macro anymore but it is history.  */
-#  define __set_errno(val) ((errno) = (val))
-# endif /* _LIBC */
-
-# ifdef __UCLIBC_HAS_THREADS__
+#  ifdef __UCLIBC_HAS_THREADS__
 /* When using threads, errno is a per-thread value.  */
-#  define errno (*__errno_location ())
-# endif
-
-#endif /* !__ASSEMBLER__ */
-
+#   define errno (*__errno_location ())
+#  endif
+# endif /* !__ASSEMBLER__ */
 #endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough.  We must
+   define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+   defined.  */
+# define EDOM	33	/* Math argument out of domain of function.  */
+# define EILSEQ	84	/* Illegal byte sequence.  */
+# define ERANGE	34	/* Math result not representable.  */
+#endif /* !_ERRNO_H && __need_Emath */

+ 1 - 3
libc/sysdeps/linux/common/bits/syscalls.h

@@ -5,6 +5,4 @@
  * forbidden.  Don't do it.  It is bad for you. 
  */ 
 
-
-#error You have not provided architecture specific _syscall[0-5] macros
-
+#error You have not provided architecture specific _syscall[0-6] macros

+ 46 - 0
libc/sysdeps/linux/common/bits/uClibc_errno.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+#ifndef _BITS_UCLIBC_ERRNO_H
+#define _BITS_UCLIBC_ERRNO_H 1
+
+#ifdef IS_IN_rtld
+# undef errno
+# define errno _dl_errno
+extern int _dl_errno; // attribute_hidden;
+#elif defined __UCLIBC_HAS_THREADS__
+# include <tls.h>
+# if USE___THREAD
+#  undef errno
+#  ifndef NOT_IN_libc
+#   define errno __libc_errno
+#  else
+#   define errno errno
+#  endif
+extern __thread int errno __attribute_tls_model_ie;
+# endif /* USE___THREAD */
+#endif /* IS_IN_rtld */
+
+#define __set_errno(val) (errno = (val))
+
+#ifndef __ASSEMBLER__
+extern int *__errno_location (void) __THROW __attribute__ ((__const__))
+# ifdef IS_IN_rtld
+	attribute_hidden
+# endif
+;
+#include <tls.h>
+#if USE___THREAD
+libc_hidden_proto(__errno_location)
+#endif
+
+/* We now need a declaration of the `errno' variable.  */
+# ifndef __UCLIBC_HAS_THREADS__
+/*extern int errno;*/
+libc_hidden_proto(errno)
+# endif
+#endif /* !__ASSEMBLER__ */
+
+#endif

+ 3 - 8
libc/sysdeps/linux/cris/bits/syscalls.h

@@ -8,16 +8,11 @@
 /* Include the __NR_<name> definitions. */
 #include <bits/sysnum.h>
 
-#if 0
-#ifndef __set_errno
-#define __set_errno(val) (*__errno_location()) = (val)
-#endif
-#endif
+#ifndef __ASSEMBLER__
 
-#undef SYS_ify
-#define SYS_ify(syscall_name)   (__NR_##syscall_name)
+#include <errno.h>
 
-#ifndef __ASSEMBLER__
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
 
 #undef _syscall0
 #define _syscall0(type,name) \

+ 4 - 4
libc/sysdeps/linux/frv/bits/syscalls.h

@@ -9,12 +9,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)  (__NR_##syscall_name)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 /* user-visible error numbers are in the range -1 - -4095: see <asm-frv/errno.h> */
 #if defined _LIBC && !defined __set_errno
 # define __syscall_return(type, res) \

+ 2 - 4
libc/sysdeps/linux/hppa/bits/syscalls.h

@@ -9,12 +9,10 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
 #define SYS_ify(syscall_name)   __NR_##syscall_name
 
 /* Assume all syscalls are done from PIC code just to be

+ 4 - 2
libc/sysdeps/linux/i386/bits/syscalls.h

@@ -4,8 +4,6 @@
 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
 #endif
 
-#include <errno.h>
-
 /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  * header files.  It also defines the traditional `SYS_<name>' macros for older
  * programs.  */
@@ -18,6 +16,10 @@
 
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 /* We need some help from the assembler to generate optimal code.  We
    define some macros here which later will be used.  */
 

+ 3 - 6
libc/sysdeps/linux/ia64/bits/syscalls.h

@@ -31,17 +31,14 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
+#ifndef __ASSEMBLER__
 
+#include <errno.h>
 
-#ifndef __ASSEMBLER__
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
 
 #undef IA64_USE_NEW_STUB
 
-#define SYS_ify(syscall_name)   __NR_##syscall_name
-
 /* taken from asm-ia64/break.h */
 #define __IA64_BREAK_SYSCALL	0x100000
 #define ___IA64_BREAK_SYSCALL	"0x100000"

+ 4 - 7
libc/sysdeps/linux/mips/bits/syscalls.h

@@ -9,15 +9,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)  (__NR_##syscall_name)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
 	"$14", "$15", "$24", "$25", "memory"
 

+ 7 - 3
libc/sysdeps/linux/powerpc/bits/syscalls.h

@@ -5,13 +5,13 @@
 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
 #endif
 
-#include <errno.h>
-
 /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  * header files.  It also defines the traditional `SYS_<name>' macros for older
  * programs.  */
 #include <bits/sysnum.h>
 
+#ifndef __ASSEMBLER__
+
 /* Define a macro which expands inline into the wrapper code for a system
    call. This use is for internal calls that do not need to handle errors
    normally. It will never touch errno.
@@ -20,6 +20,10 @@
    "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
    an error return status).  */
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 # undef INLINE_SYSCALL
 #if 1
 # define INLINE_SYSCALL(name, nr, args...)				\
@@ -164,5 +168,5 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6
   return (type) INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6); \
 }
 
+#endif /* __ASSEMBLER__ */
 #endif /* _BITS_SYSCALLS_H */
-

+ 4 - 7
libc/sysdeps/linux/sh/bits/syscalls.h

@@ -9,15 +9,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)  (__NR_##syscall_name)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 /* user-visible error numbers are in the range -1 - -125: see <asm-sh/errno.h> */
 #define __syscall_return(type, res) \
 do { \

+ 4 - 7
libc/sysdeps/linux/sh64/bits/syscalls.h

@@ -9,15 +9,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-#ifndef SYS_ify
-# define SYS_ify(syscall_name)  (__NR_##syscall_name)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 /* user-visible error numbers are in the range -1 - -125: see <asm-sh64/errno.h> */
 #define __syscall_return(type, res) \
 do { \

+ 4 - 4
libc/sysdeps/linux/sparc/bits/syscalls.h

@@ -11,12 +11,12 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 #undef __SYSCALL_STRING
 #if __WORDSIZE == 32
 # define __SYSCALL_STRING \

+ 5 - 6
libc/sysdeps/linux/vax/bits/syscalls.h

@@ -9,13 +9,11 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location())=(val)
-#endif
+#ifndef __ASSEMBLER__
 
-#ifndef SYS_ify
-# define SYS_ify(syscall_name) (__NR_##syscall_name)
-#endif
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
 
 #undef _syscall_return
 #define _syscall_return(type)							\
@@ -261,4 +259,5 @@ type name (type1 arg1,							\
 	_syscall_return (type);						\
 }
 
+#endif /* __ASSEMBLER__ */
 #endif /* _BITS_SYSCALLS_H */

+ 4 - 4
libc/sysdeps/linux/x86_64/bits/syscalls.h

@@ -9,10 +9,6 @@
  * programs.  */
 #include <bits/sysnum.h>
 
-#ifndef __set_errno
-# define __set_errno(val) (*__errno_location ()) = (val)
-#endif
-
 /*
    Some of the sneaky macros in the code were taken from 
    glibc-2.2.5/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -20,6 +16,10 @@
 
 #ifndef __ASSEMBLER__
 
+#include <errno.h>
+
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
 #undef _syscall0
 #define _syscall0(type,name) \
 type name(void) \