Fix __errno for LP64 and clean up __get_tls.
If __get_tls has the right type, a lot of confusing casting can disappear.
It was probably a mistake that __get_tls was exposed as a function for mips
and x86 (but not arm), so let's (a) ensure that the __get_tls function
always matches the macro, (b) that we have the function for arm too, and
(c) that we don't have the function for any 64-bit architecture.
Change-Id: Ie9cb989b66e2006524ad7733eb6e1a65055463be
diff --git a/libc/private/__get_tls.h b/libc/private/__get_tls.h
new file mode 100644
index 0000000..5f9451d
--- /dev/null
+++ b/libc/private/__get_tls.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __BIONIC_PRIVATE_GET_TLS_H_
+#define __BIONIC_PRIVATE_GET_TLS_H_
+
+#if defined(__arm__)
+# define __get_tls() \
+ ({ void** __val; \
+ __asm__("mrc p15, 0, %0, c13, c0, 3" : "=r"(__val)); \
+ __val; })
+#elif defined(__mips__)
+# define __get_tls() \
+ /* On mips32r1, this goes via a kernel illegal instruction trap that's optimized for v1. */ \
+ ({ register void** __val asm("v1"); \
+ __asm__(".set push\n" \
+ ".set mips32r2\n" \
+ "rdhwr %0,$29\n" \
+ ".set pop\n" : "=r"(__val)); \
+ __val; })
+#elif defined(__i386__)
+# define __get_tls() \
+ ({ void** __val; \
+ __asm__("movl %%gs:0, %0" : "=r"(__val)); \
+ __val; })
+#elif defined(__x86_64__)
+# define __get_tls() \
+ ({ void** __val; \
+ __asm__("mov %%fs:0, %0" : "=r"(__val)); \
+ __val; })
+#else
+#error unsupported architecture
+#endif
+
+#endif /* __BIONIC_PRIVATE_GET_TLS_H_ */
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index 2e20364..a14bd3c 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -25,10 +25,12 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-#ifndef _SYS_TLS_H
-#define _SYS_TLS_H
+
+#ifndef __BIONIC_PRIVATE_BIONIC_TLS_H_
+#define __BIONIC_PRIVATE_BIONIC_TLS_H_
#include <sys/cdefs.h>
+#include "__get_tls.h"
__BEGIN_DECLS
@@ -83,39 +85,6 @@
#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
#define BIONIC_TLS_SLOTS BIONIC_ALIGN(128 + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT, 4)
-/* syscall only, do not call directly */
-extern int __set_tls(void* ptr);
-
-/* get the TLS */
-#if defined(__arm__)
-# define __get_tls() \
- ({ unsigned int __val; \
- asm ("mrc p15, 0, %0, c13, c0, 3" : "=r"(__val)); \
- (volatile void*) __val; })
-#elif defined(__mips__)
-# define __get_tls() \
- /* On mips32r1, this goes via a kernel illegal instruction trap that's optimized for v1. */ \
- ({ register unsigned int __val asm("v1"); \
- asm (" .set push\n" \
- " .set mips32r2\n" \
- " rdhwr %0,$29\n" \
- " .set pop\n" : "=r"(__val)); \
- (volatile void*) __val; })
-#elif defined(__i386__)
-# define __get_tls() \
- ({ void* __val; \
- asm ("movl %%gs:0, %0" : "=r"(__val)); \
- (volatile void*) __val; })
-
-#elif defined(__x86_64__)
-# define __get_tls() \
- ({ void* __val; \
- asm ("mov %%fs:0, %0" : "=r"(__val)); \
- (volatile void*) __val; })
-#else
-#error unsupported architecture
-#endif
-
__END_DECLS
#if defined(__cplusplus)
@@ -123,4 +92,4 @@
extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
#endif
-#endif /* _SYS_TLS_H */
+#endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */