4 #include "pthread_impl.h"
10 pthread_t self = __pthread_self();
11 if (!self->dlerror_flag) return 0;
12 self->dlerror_flag = 0;
13 char *s = self->dlerror_buf;
15 return "Dynamic linker failed to allocate memory for error message";
20 static volatile int freebuf_queue_lock[1];
21 static void **freebuf_queue;
23 void __dl_thread_cleanup(void)
25 pthread_t self = __pthread_self();
26 if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
27 LOCK(freebuf_queue_lock);
28 void **p = (void **)self->dlerror_buf;
31 UNLOCK(freebuf_queue_lock);
35 hidden void __dl_vseterr(const char *fmt, va_list ap)
37 LOCK(freebuf_queue_lock);
38 while (freebuf_queue) {
39 void **p = freebuf_queue;
43 UNLOCK(freebuf_queue_lock);
47 pthread_t self = __pthread_self();
48 if (self->dlerror_buf != (void *)-1)
49 free(self->dlerror_buf);
50 size_t len = vsnprintf(0, 0, fmt, ap2);
51 if (len < sizeof(void *)) len = sizeof(void *);
53 char *buf = malloc(len+1);
55 vsnprintf(buf, len+1, fmt, ap);
59 self->dlerror_buf = buf;
60 self->dlerror_flag = 1;
63 hidden void __dl_seterr(const char *fmt, ...)
67 __dl_vseterr(fmt, ap);
71 static int stub_invalid_handle(void *h)
73 __dl_seterr("Invalid library handle %p", (void *)h);
77 weak_alias(stub_invalid_handle, __dl_invalid_handle);