4 #include "pthread_impl.h"
9 #define malloc __libc_malloc
10 #define calloc __libc_calloc
11 #define realloc __libc_realloc
12 #define free __libc_free
16 pthread_t self = __pthread_self();
17 if (!self->dlerror_flag) return 0;
18 self->dlerror_flag = 0;
19 char *s = self->dlerror_buf;
21 return "Dynamic linker failed to allocate memory for error message";
26 static volatile int freebuf_queue_lock[1];
27 static void **freebuf_queue;
28 volatile int *const __dlerror_lockptr = freebuf_queue_lock;
30 void __dl_thread_cleanup(void)
32 pthread_t self = __pthread_self();
33 if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
34 LOCK(freebuf_queue_lock);
35 void **p = (void **)self->dlerror_buf;
38 UNLOCK(freebuf_queue_lock);
42 hidden void __dl_vseterr(const char *fmt, va_list ap)
44 LOCK(freebuf_queue_lock);
45 void **q = freebuf_queue;
47 UNLOCK(freebuf_queue_lock);
57 pthread_t self = __pthread_self();
58 if (self->dlerror_buf != (void *)-1)
59 free(self->dlerror_buf);
60 size_t len = vsnprintf(0, 0, fmt, ap2);
61 if (len < sizeof(void *)) len = sizeof(void *);
63 char *buf = malloc(len+1);
65 vsnprintf(buf, len+1, fmt, ap);
69 self->dlerror_buf = buf;
70 self->dlerror_flag = 1;
73 hidden void __dl_seterr(const char *fmt, ...)
77 __dl_vseterr(fmt, ap);
81 static int stub_invalid_handle(void *h)
83 __dl_seterr("Invalid library handle %p", (void *)h);
87 weak_alias(stub_invalid_handle, __dl_invalid_handle);