aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0003-b9b2db2f-to-e94d0692.patch
blob: c13a5ffc8e0faa12e3ce3f3a2b7a57b7628f2c09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
diff --git a/arch/arm/atomic.h b/arch/arm/atomic.h
index 734d287..50ad947 100644
--- a/arch/arm/atomic.h
+++ b/arch/arm/atomic.h
@@ -22,7 +22,28 @@ static inline int a_ctz_64(uint64_t x)
 	return a_ctz_l(y);
 }
 
+#if __ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__ \
+ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ \
+ || __ARM_ARCH >= 7
+static inline int __k_cas(int t, int s, volatile int *p)
+{
+	int ret;
+	__asm__(
+		"	mcr p15,0,r0,c7,c10,5\n"
+		"1:	ldrex %0,%3\n"
+		"	subs %0,%0,%1\n"
+		"	strexeq %0,%2,%3\n"
+		"	teqeq %0,#1\n"
+		"	beq 1b\n"
+		"	mcr p15,0,r0,c7,c10,5\n"
+		: "=&r"(ret)
+		: "r"(t), "r"(s), "Q"(*p)
+		: "memory", "cc" );
+	return ret;
+}
+#else
 #define __k_cas ((int (*)(int, int, volatile int *))0xffff0fc0)
+#endif
 
 static inline int a_cas(volatile int *p, int t, int s)
 {
diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h
index 43a1c01..ec77a83 100644
--- a/arch/arm/pthread_arch.h
+++ b/arch/arm/pthread_arch.h
@@ -1,8 +1,22 @@
-typedef char *(*__ptr_func_t)(void) __attribute__((const));
+#if __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__ \
+ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ \
+ || __ARM_ARCH >= 7
+
+static inline __attribute__((const)) pthread_t __pthread_self()
+{
+	char *p;
+	__asm__( "mrc p15,0,%0,c13,c0,3" : "=r"(p) );
+	return (void *)(p+8-sizeof(struct pthread));
+}
+
+#else
 
+typedef char *(*__ptr_func_t)(void) __attribute__((const));
 #define __pthread_self() \
 	((pthread_t)(((__ptr_func_t)0xffff0fe0)()+8-sizeof(struct pthread)))
 
+#endif
+
 #define TLS_ABOVE_TP
 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
 
diff --git a/include/sys/auxv.h b/include/sys/auxv.h
new file mode 100644
index 0000000..6dcf9ad
--- /dev/null
+++ b/include/sys/auxv.h
@@ -0,0 +1,16 @@
+#ifndef _SYS_AUXV_H
+#define _SYS_AUXV_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <elf.h>
+
+unsigned long getauxval(unsigned long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index 8ac0036..89d081e 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -64,16 +64,6 @@ void *__tls_get_addr(size_t *v)
 	return (char *)__pthread_self()->dtv[1]+v[1];
 }
 
-static void *simple(void *p)
-{
-	*(void **)p = p;
-	return __set_thread_area(TP_ADJ(p)) ? 0 : p;
-}
-
-weak_alias(simple, __install_initial_tls);
-
-void *__mmap(void *, size_t, int, int, int, off_t);
-
 #if ULONG_MAX == 0xffffffff
 typedef Elf32_Phdr Phdr;
 #else
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 73d4932..ac37492 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -3,7 +3,6 @@
 
 void __init_tls(size_t *);
 void __init_security(size_t *);
-void __init_ldso_ctors(void);
 
 #ifndef SHARED
 static void dummy() {}
diff --git a/src/misc/getauxval.c b/src/misc/getauxval.c
new file mode 100644
index 0000000..5ac8b3d
--- /dev/null
+++ b/src/misc/getauxval.c
@@ -0,0 +1,12 @@
+#include <sys/auxv.h>
+#include <errno.h>
+#include "libc.h"
+
+unsigned long getauxval(unsigned long item)
+{
+	size_t *auxv = libc.auxv;
+	for (; *auxv; auxv+=2)
+		if (*auxv==item) return auxv[1];
+	errno = ENOENT;
+	return 0;
+}
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 31c3d5d..f6e7f38 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -308,8 +308,8 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
 			*d = x % 1000000000;
 			carry = x / 1000000000;
 		}
-		if (!z[-1] && z>a) z--;
 		if (carry) *--a = carry;
+		while (z>a && !z[-1]) z--;
 		e2-=sh;
 	}
 	while (e2<0) {
@@ -356,15 +356,15 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
 				*d = *d + i;
 				while (*d > 999999999) {
 					*d--=0;
+					if (d<a) *--a=0;
 					(*d)++;
 				}
-				if (d<a) a=d;
 				for (i=10, e=9*(r-a); *a>=i; i*=10, e++);
 			}
 		}
 		if (z>d+1) z=d+1;
-		for (; !z[-1] && z>a; z--);
 	}
+	for (; z>a && !z[-1]; z--);
 	
 	if ((t|32)=='g') {
 		if (!p) p++;