mailing list of musl libc
 help / color / mirror / code / Atom feed
009beecb071563563515063cd38b31810841de13 blob 1705 bytes (raw)

 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
 
#include <dlfcn.h>
#include <stdlib.h>
#include <stdarg.h>
#include "pthread_impl.h"
#include "dynlink.h"
#include "lock.h"
#include "fork_impl.h"

char *dlerror()
{
	pthread_t self = __pthread_self();
	if (!self->dlerror_flag) return 0;
	self->dlerror_flag = 0;
	char *s = self->dlerror_buf;
	if (s == (void *)-1)
		return "Dynamic linker failed to allocate memory for error message";
	else
		return s;
}

static volatile int freebuf_queue_lock[1];
static void **freebuf_queue;
volatile int *const __dlerror_lockptr = freebuf_queue_lock;

void __dl_thread_cleanup(void)
{
	pthread_t self = __pthread_self();
	if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
		LOCK(freebuf_queue_lock);
		void **p = (void **)self->dlerror_buf;
		*p = freebuf_queue;
		freebuf_queue = p;
		UNLOCK(freebuf_queue_lock);
	}
}

hidden void __dl_vseterr(const char *fmt, va_list ap)
{
	LOCK(freebuf_queue_lock);
	while (freebuf_queue) {
		void **p = freebuf_queue;
		freebuf_queue = *p;
		free(p);
	}
	UNLOCK(freebuf_queue_lock);

	va_list ap2;
	va_copy(ap2, ap);
	pthread_t self = __pthread_self();
	if (self->dlerror_buf != (void *)-1)
		free(self->dlerror_buf);
	size_t len = vsnprintf(0, 0, fmt, ap2);
	if (len < sizeof(void *)) len = sizeof(void *);
	va_end(ap2);
	char *buf = malloc(len+1);
	if (buf) {
		vsnprintf(buf, len+1, fmt, ap);
	} else {
		buf = (void *)-1;	
	}
	self->dlerror_buf = buf;
	self->dlerror_flag = 1;
}

hidden void __dl_seterr(const char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	__dl_vseterr(fmt, ap);
	va_end(ap);
}

static int stub_invalid_handle(void *h)
{
	__dl_seterr("Invalid library handle %p", (void *)h);
	return 1;
}

weak_alias(stub_invalid_handle, __dl_invalid_handle);
debug log:

solving 009beecb ...
found 009beecb in https://inbox.vuxu.org/musl/20201028185608.GG534@brightrain.aerifal.cx/ ||
	https://inbox.vuxu.org/musl/20201026005912.GJ534@brightrain.aerifal.cx/
found 3fcc7779 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 3fcc7779530234fa7734c464876a70b8f2e9bab4	src/ldso/dlerror.c

applying [1/2] https://inbox.vuxu.org/musl/20201028185608.GG534@brightrain.aerifal.cx/
diff --git a/src/ldso/dlerror.c b/src/ldso/dlerror.c
index 3fcc7779..009beecb 100644

Checking patch src/ldso/dlerror.c...
Applied patch src/ldso/dlerror.c cleanly.

skipping https://inbox.vuxu.org/musl/20201026005912.GJ534@brightrain.aerifal.cx/ for 009beecb
index at:
100644 009beecb071563563515063cd38b31810841de13	src/ldso/dlerror.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).