1 diff --git a/libc/bionic/__errno.c b/libc/bionic/__errno.c
2 index 8f33cce..34664c6 100644
3 --- a/libc/bionic/__errno.c
4 +++ b/libc/bionic/__errno.c
7 #include <bionic_tls.h>
9 -volatile int* __errno( void )
11 - return &((volatile int*)__get_tls())[TLS_SLOT_ERRNO];
14 diff --git a/libc/bionic/__set_errno.c b/libc/bionic/__set_errno.c
15 index c72d4f7..529a4ef 100644
16 --- a/libc/bionic/__set_errno.c
17 +++ b/libc/bionic/__set_errno.c
23 -int __set_errno(int n)
30 * this function is called from syscall stubs,
31 * (tail-called in the case of 0-4 arg versions)
32 diff --git a/libc/bionic/pthread-rwlocks.c b/libc/bionic/pthread-rwlocks.c
33 index ca3e95c..1494523 100644
34 --- a/libc/bionic/pthread-rwlocks.c
35 +++ b/libc/bionic/pthread-rwlocks.c
36 @@ -69,6 +69,8 @@ static int __get_thread_id(void)
38 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
45 @@ -77,8 +79,9 @@ int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
48 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
57 @@ -87,6 +90,7 @@ int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
59 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
65 @@ -102,6 +106,8 @@ int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
67 int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *attr, int *pshared)
71 if (!attr || !pshared)
74 @@ -111,6 +117,7 @@ int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *attr, int *pshared)
76 int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
79 pthread_mutexattr_t* lock_attr = NULL;
80 pthread_condattr_t* cond_attr = NULL;
81 pthread_mutexattr_t lock_attr0;
82 @@ -150,6 +157,10 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *at
84 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
93 @@ -209,11 +220,14 @@ static void _pthread_rwlock_pulse(pthread_rwlock_t *rwlock)
95 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
98 return pthread_rwlock_timedrdlock(rwlock, NULL);
101 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
108 @@ -231,6 +245,7 @@ int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
110 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout)
113 int thread_id, ret = 0;
116 @@ -256,11 +271,14 @@ EXIT:
118 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
122 return pthread_rwlock_timedwrlock(rwlock, NULL);
125 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
128 int thread_id, ret = 0;
131 @@ -280,6 +298,7 @@ int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
133 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout)
136 int thread_id, ret = 0;
139 @@ -310,6 +329,8 @@ EXIT:
141 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
148 diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
149 index 6b01830..490c39f 100644
150 --- a/libc/bionic/pthread.c
151 +++ b/libc/bionic/pthread.c
152 @@ -177,7 +177,8 @@ __get_stack_base(int *p_stack_size)
154 void __init_tls(void** tls, void* thread)
160 ((pthread_internal_t*)thread)->tls = tls;
162 @@ -188,7 +189,7 @@ void __init_tls(void** tls, void* thread)
163 for (nn = TLS_SLOT_ERRNO; nn < BIONIC_TLS_SLOTS; nn++)
166 - __set_tls( (void*)tls );
167 + __set_tls( (void*)tls ); */
171 @@ -1662,6 +1663,7 @@ static int tlsmap_alloc(tlsmap_t* m, tls_dtor_t dtor)
173 int pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *))
176 uint32_t err = ENOMEM;
177 tlsmap_t* map = tlsmap_lock();
178 int k = tlsmap_alloc(map, destructor_function);
179 @@ -1686,6 +1688,7 @@ int pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *))
181 int pthread_key_delete(pthread_key_t key)
185 pthread_internal_t* thr;
187 @@ -1730,6 +1733,7 @@ err1:
189 int pthread_setspecific(pthread_key_t key, const void *ptr)
195 @@ -1747,6 +1751,7 @@ int pthread_setspecific(pthread_key_t key, const void *ptr)
197 void * pthread_getspecific(pthread_key_t key)
200 if (!TLSMAP_VALIDATE_KEY(key)) {
203 @@ -1775,6 +1780,7 @@ void * pthread_getspecific(pthread_key_t key)
205 static void pthread_key_clean_all(void)
209 void** tls = (void**)__get_tls();
210 int rounds = PTHREAD_DESTRUCTOR_ITERATIONS;
211 @@ -1830,6 +1836,7 @@ extern int tkill(int tid, int sig);
213 int pthread_kill(pthread_t tid, int sig)
217 int old_errno = errno;
218 pthread_internal_t * thread = (pthread_internal_t *)tid;
219 @@ -1847,6 +1854,7 @@ extern int __rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
221 int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
224 /* pthread_sigmask must return the error code, but the syscall
225 * will set errno instead and return 0/-1
227 @@ -1863,6 +1871,7 @@ int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
229 int pthread_getcpuclockid(pthread_t tid, clockid_t *clockid)
232 const int CLOCK_IDTYPE_BITS = 3;
233 pthread_internal_t* thread = (pthread_internal_t*)tid;
235 @@ -1879,6 +1888,7 @@ int pthread_getcpuclockid(pthread_t tid, clockid_t *clockid)
237 int pthread_once( pthread_once_t* once_control, void (*init_routine)(void) )
240 static pthread_mutex_t once_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
242 if (*once_control == PTHREAD_ONCE_INIT) {
243 @@ -1898,6 +1908,7 @@ int pthread_once( pthread_once_t* once_control, void (*init_routine)(void) )
245 int pthread_setname_np(pthread_t thid, const char *thname)
249 int saved_errno, ret;
251 diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
252 index 94a81cd..81c5e16 100644
253 --- a/libc/private/bionic_tls.h
254 +++ b/libc/private/bionic_tls.h
255 @@ -55,17 +55,17 @@ __BEGIN_DECLS
256 /* Well known TLS slots */
257 #define TLS_SLOT_SELF 0
258 #define TLS_SLOT_THREAD_ID 1
259 -#define TLS_SLOT_ERRNO 2
260 +#define TLS_SLOT_ERRNO 4
262 -#define TLS_SLOT_OPENGL_API 3
263 -#define TLS_SLOT_OPENGL 4
264 +#define TLS_SLOT_OPENGL_API 5
265 +#define TLS_SLOT_OPENGL 6
267 /* this slot is only used to pass information from the dynamic linker to
268 * libc.so when the C library is loaded in to memory. The C runtime init
269 * function will then clear it. Since its use is extremely temporary,
270 * we reuse an existing location.
272 -#define TLS_SLOT_BIONIC_PREINIT (TLS_SLOT_ERRNO+1)
273 +#define TLS_SLOT_BIONIC_PREINIT 3
275 /* small technical note: it is not possible to call pthread_setspecific
276 * on keys that are <= TLS_SLOT_MAX_WELL_KNOWN, which is why it is set to
277 @@ -76,7 +76,7 @@ __BEGIN_DECLS
278 * pthread_key_create() to initialize them. on the other hand, there is
279 * no destructor associated to them (we might need to implement this later)
281 -#define TLS_SLOT_MAX_WELL_KNOWN TLS_SLOT_ERRNO
282 +#define TLS_SLOT_MAX_WELL_KNOWN 2
284 #define TLS_DEFAULT_ALLOC_MAP 0x0000001F
286 diff --git a/libdl/libdl.c b/libdl/libdl.c
287 index b36af16..ad6d4b4 100644
290 @@ -24,6 +24,8 @@ void *dlsym(void *handle, const char *symbol) { return 0; }
291 int dladdr(void *addr, Dl_info *info) { return 0; }
292 int dlclose(void *handle) { return 0; }
294 +int *__errno() { return 0; };
295 +void __set_errno(int f) {};
297 void *dl_unwind_find_exidx(void *pc, int *pcount) { return 0; }
298 #elif defined(__i386__) || defined(__sh__)