Browse Source

Add a local '_dl_errno' to be used by syscalls in ldso, allowing
useful syscall failure diagnostics.

Eric Andersen 21 years ago
parent
commit
b8361e2e12

+ 4 - 5
ldso/ldso/arm/dl-syscalls.h

@@ -1,7 +1,6 @@
-/* Define the __set_errno macro as nothing so that INLINE_SYSCALL
- * won't set errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
-
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 

+ 4 - 6
ldso/ldso/cris/dl-syscalls.h

@@ -1,7 +1,5 @@
-/* 
- * Define the __set_errno macro as nothing so that INLINE_SYSCALL
- * won't set errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. 
- */
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"

+ 4 - 5
ldso/ldso/frv/dl-syscalls.h

@@ -17,12 +17,11 @@ You should have received a copy of the GNU Lesser General Public
 License along with uClibc; see the file COPYING.LIB.  If not, write to
 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 USA.  */
-	
-/* Define the __set_errno macro as nothing so that INLINE_SYSCALL
- * won't set errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
 
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 #include <sys/mman.h>
 

+ 4 - 5
ldso/ldso/i386/dl-syscalls.h

@@ -1,7 +1,6 @@
-/* Define the __set_errno macro as nothing so that INLINE_SYSCALL
- * won't set errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
-
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 

+ 1 - 0
ldso/ldso/ldso.c

@@ -46,6 +46,7 @@ unsigned char *_dl_mmap_zero   = 0;		/* Also used by _dl_malloc */
 unsigned long *_dl_brkp        = 0;		/* The end of the data segment for brk and sbrk */
 unsigned long *_dl_envp        = 0;		/* The environment address */
 int _dl_secure                 = 1;		/* Are we dealing with setuid stuff? */
+int _dl_errno                  = 0;     /* We can't use the real errno in ldso */
 size_t _dl_pagesize            = 0;		/* Store the page size for use later */
 
 

+ 17 - 14
ldso/ldso/m68k/dl-syscalls.h

@@ -18,6 +18,9 @@
 #define __NR_stat		106
 #define __NR_mprotect		125
 
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
 
 /* Here are the macros which define how this platform makes
  * system calls.  This particular variant does _not_ set 
@@ -31,8 +34,8 @@ do { \
 	if ((unsigned long)(res) >= (unsigned long)(-125)) { \
 	/* avoid using res which is declared to be in register d0; \
 	   errno might expand to a function call and clobber it.  */ \
-		/* int __err = -(res); \
-		errno = __err; */ \
+		int __err = -(res); \
+		_dl_errno = __err; \
 		res = -1; \
 	} \
 	return (type) (res); \
@@ -48,8 +51,8 @@ type name(void)								\
 			: "=g" (__res)					\
 			: "i" (__NR_##name)				\
 			: "cc", "%d0");					\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\
@@ -67,8 +70,8 @@ type name(atype a)							\
 			: "i" (__NR_##name),				\
 			  "g" ((long)a)					\
 			: "cc", "%d0", "%d1");				\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\
@@ -88,8 +91,8 @@ type name(atype a, btype b)						\
 			  "a" ((long)a),				\
 			  "g" ((long)b)					\
 			: "cc", "%d0", "%d1", "%d2");			\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\
@@ -111,8 +114,8 @@ type name(atype a, btype b, ctype c)					\
 			  "a" ((long)b),				\
 			  "g" ((long)c)					\
 			: "cc", "%d0", "%d1", "%d2", "%d3");		\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\
@@ -137,8 +140,8 @@ type name(atype a, btype b, ctype c, dtype d)				\
 			  "g" ((long)d)					\
 			: "cc", "%d0", "%d1", "%d2", "%d3",		\
 			  "%d4");					\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\
@@ -165,8 +168,8 @@ type name(atype a, btype b, ctype c, dtype d, etype e)			\
 			  "g" ((long)e)					\
 			: "cc", "%d0", "%d1", "%d2", "%d3",		\
 			  "%d4", "%d5");				\
-  if ((unsigned long)(__res) >= (unsigned long)(-125)) {			\
-    /* errno = -__res; */							\
+  if ((unsigned long)(__res) >= (unsigned long)(-125)) {		\
+    _dl_errno = -__res; 						\
     __res = -1;								\
   }									\
   return (type)__res;							\

+ 4 - 5
ldso/ldso/mips/dl-syscalls.h

@@ -1,7 +1,6 @@
-/* Define the __set_errno macro as nothing so that we don't bother
- * setting errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
-
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 

+ 6 - 1
ldso/ldso/powerpc/dl-syscalls.h

@@ -19,6 +19,11 @@
 #define __NR_stat		106
 #define __NR_mprotect		125
 
+
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+
 /* Here are the macros which define how this platform makes
  * system calls.  This particular variant does _not_ set 
  * errno (note how it is disabled in __syscall_return) since
@@ -27,7 +32,7 @@
 
 #undef __syscall_return
 #define __syscall_return(type) \
-	return (__sc_err & 0x10000000 ? /*errno = __sc_ret,*/ __sc_ret = -1 : 0), \
+	return (__sc_err & 0x10000000 ? _dl_errno = __sc_ret, __sc_ret = -1 : 0), \
 	       (type) __sc_ret
 
 #undef __syscall_clobbers

+ 4 - 5
ldso/ldso/sh/dl-syscalls.h

@@ -1,7 +1,6 @@
-/* Define the __set_errno macro as nothing so that we don't bother
- * setting errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
-
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 

+ 4 - 7
ldso/ldso/sh64/dl-syscalls.h

@@ -1,9 +1,6 @@
-/* Define the __set_errno macro as nothing so that we don't bother
- * setting errno, which is important since we make system calls
- * before the errno symbol is dynamicly linked. */
-
-#include <errno.h>
-#undef __set_errno
-#define __set_errno(X) {(void)(X);}
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+#define __set_errno(X) {(_dl_errno) = (X);}
 #include "sys/syscall.h"
 

+ 10 - 6
ldso/ldso/sparc/dl-syscalls.h

@@ -19,6 +19,10 @@
 #define __NR_stat		 38
 #define __NR_mprotect		 74
 
+/* We can't use the real errno in ldso, since it has not yet
+ * been dynamicly linked in yet. */
+extern int _dl_errno;
+
 /* Here are the macros which define how this platform makes
  * system calls.  This particular variant does _not_ set 
  * errno (note how it is disabled in __syscall_return) since
@@ -40,7 +44,7 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "o0", "cc"); \
 if (__res < -255 || __res >= 0) \
     return (type) __res; \
-/*errno = -__res; */\
+_dl_errno = -__res; \
 return -1; \
 }
 
@@ -60,7 +64,7 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "cc"); \
 if (__res < -255 || __res >= 0) \
 	return (type) __res; \
-/*errno = -__res;*/ \
+_dl_errno = -__res; \
 return -1; \
 }
 
@@ -81,7 +85,7 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "cc"); \
 if (__res < -255 || __res >= 0) \
 	return (type) __res; \
-/*errno = -__res;*/ \
+_dl_errno = -__res; \
 return -1; \
 }
 
@@ -103,7 +107,7 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "cc"); \
 if (__res < -255 || __res>=0) \
 	return (type) __res; \
-/*errno = -__res;*/ \
+_dl_errno = -__res; \
 return -1; \
 }
 
@@ -126,7 +130,7 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "cc"); \
 if (__res < -255 || __res>=0) \
 	return (type) __res; \
-/*errno = -__res;*/ \
+_dl_errno = -__res; \
 return -1; \
 } 
 
@@ -151,6 +155,6 @@ __asm__ __volatile__ ("t 0x10\n\t" \
 		      : "cc"); \
 if (__res < -255 || __res>=0) \
 	return (type) __res; \
-/*errno = -__res; */\
+_dl_errno = -__res; \
 return -1; \
 }