diff options
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/misc/internals/__errno_location.c | 10 | ||||
| -rw-r--r-- | libc/misc/internals/errno.c | 21 | ||||
| -rw-r--r-- | libc/sysdeps/linux/common/bits/errno.h | 12 | ||||
| -rw-r--r-- | libc/sysdeps/linux/mips/bits/syscalls.h | 6 |
4 files changed, 35 insertions, 14 deletions
diff --git a/libc/misc/internals/__errno_location.c b/libc/misc/internals/__errno_location.c index 10b97753f..c0b1532b9 100644 --- a/libc/misc/internals/__errno_location.c +++ b/libc/misc/internals/__errno_location.c @@ -1,7 +1,15 @@ #include <errno.h> + +#ifndef __UCLIBC_HAS_THREADS_NATIVE__ #undef errno +extern int errno; +#endif -int * weak_const_function __errno_location (void) +int * +#ifndef __UCLIBC_HAS_THREADS_NATIVE__ +weak_const_function +#endif +__errno_location (void) { return &errno; } diff --git a/libc/misc/internals/errno.c b/libc/misc/internals/errno.c index f2424eae0..107b61403 100644 --- a/libc/misc/internals/errno.c +++ b/libc/misc/internals/errno.c @@ -1,6 +1,24 @@ #include <features.h> -#undef errno +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +__thread int errno; +__thread int h_errno; + +#ifdef SHARED +/* + * FIXME: Add usage of hidden attribute for both of these when used in + * the shared library. It currently crashes the linker when doing + * section relocations. + */ +extern __thread int __libc_errno __attribute__ ((alias ("errno"))); +extern __thread int __libc_h_errno __attribute__ ((alias ("h_errno"))); +#else +extern __thread int __libc_errno __attribute__ ((alias ("errno"))); +extern __thread int __libc_h_errno __attribute__ ((alias ("h_errno"))); +#endif +#define h_errno __libc_h_errno + +#else extern int errno; extern int h_errno; @@ -15,3 +33,4 @@ int _h_errno = 0; weak_alias (_errno, errno) weak_alias(_h_errno, h_errno); +#endif diff --git a/libc/sysdeps/linux/common/bits/errno.h b/libc/sysdeps/linux/common/bits/errno.h index bf73a8fe1..03d4729f6 100644 --- a/libc/sysdeps/linux/common/bits/errno.h +++ b/libc/sysdeps/linux/common/bits/errno.h @@ -31,20 +31,10 @@ # ifndef __ASSEMBLER__ -/* We now need a declaration of the `errno' variable. */ -extern int errno; - /* Function to get address of global `errno' variable. */ extern int *__errno_location (void) __THROW __attribute__ ((__const__)); -# if defined _LIBC -/* We wouldn't need a special macro anymore but it is history. */ -# ifndef __set_errno -# define __set_errno(val) ((errno) = (val)) -# endif -# endif /* _LIBC */ - -# if defined __UCLIBC_HAS_THREADS__ +# if !defined _LIBC || defined __UCLIBC_HAS_THREADS__ /* When using threads, errno is a per-thread value. */ # define errno (*__errno_location ()) # endif diff --git a/libc/sysdeps/linux/mips/bits/syscalls.h b/libc/sysdeps/linux/mips/bits/syscalls.h index 8645d9d75..09688dd1b 100644 --- a/libc/sysdeps/linux/mips/bits/syscalls.h +++ b/libc/sysdeps/linux/mips/bits/syscalls.h @@ -10,7 +10,11 @@ #include <bits/sysnum.h> #ifndef __set_errno -# define __set_errno(val) (*__errno_location ()) = (val) +# ifdef __UCLIBC_HAS_THREADS__ +# define __set_errno(val) (*__errno_location ()) = (val) +# else +# define __set_errno(val) (errno = (val)) +# endif #endif #ifndef SYS_ify # define SYS_ify(syscall_name) (__NR_##syscall_name) |
