4 #include "pthread_impl.h"
8 #define malloc __libc_malloc
9 #define calloc __libc_calloc
10 #define realloc __libc_realloc
11 #define free __libc_free
15 pthread_t self = __pthread_self();
16 if (!self->dlerror_flag) return 0;
17 self->dlerror_flag = 0;
18 char *s = self->dlerror_buf;
20 return "Dynamic linker failed to allocate memory for error message";
25 static volatile int freebuf_queue_lock[1];
26 static void **freebuf_queue;
28 void __dl_thread_cleanup(void)
30 pthread_t self = __pthread_self();
31 if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
32 LOCK(freebuf_queue_lock);
33 void **p = (void **)self->dlerror_buf;
36 UNLOCK(freebuf_queue_lock);
40 hidden void __dl_vseterr(const char *fmt, va_list ap)
42 LOCK(freebuf_queue_lock);
43 void **q = freebuf_queue;
45 UNLOCK(freebuf_queue_lock);
55 pthread_t self = __pthread_self();
56 if (self->dlerror_buf != (void *)-1)
57 free(self->dlerror_buf);
58 size_t len = vsnprintf(0, 0, fmt, ap2);
59 if (len < sizeof(void *)) len = sizeof(void *);
61 char *buf = malloc(len+1);
63 vsnprintf(buf, len+1, fmt, ap);
67 self->dlerror_buf = buf;
68 self->dlerror_flag = 1;
71 hidden void __dl_seterr(const char *fmt, ...)
75 __dl_vseterr(fmt, ap);
79 static int stub_invalid_handle(void *h)
81 __dl_seterr("Invalid library handle %p", (void *)h);
85 weak_alias(stub_invalid_handle, __dl_invalid_handle);