static int runtime;
static int ldd_mode;
static int ldso_fail;
+static int noload;
static jmp_buf rtld_fail;
static pthread_rwlock_t lock;
static struct debug debug;
char buf[2*NAME_MAX+2];
const char *pathname;
unsigned char *map;
- size_t map_len;
struct dso *p, temp_dso = {0};
int fd;
struct stat st;
return p;
}
}
- map = map_library(fd, &temp_dso);
+ map = noload ? 0 : map_library(fd, &temp_dso);
close(fd);
if (!map) return 0;
}
p = calloc(1, alloc_size);
if (!p) {
- munmap(map, map_len);
+ munmap(map, temp_dso.map_len);
return 0;
}
memcpy(p, &temp_dso, sizeof temp_dso);
if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
if (p->tls_image) {
if (runtime && !__pthread_self_init()) {
+ munmap(map, p->map_len);
free(p);
- munmap(map, map_len);
return 0;
}
p->tls_id = ++tls_cnt;
orig_tls_offset = tls_offset;
orig_tls_align = tls_align;
orig_tail = tail;
+ noload = mode & RTLD_NOLOAD;
if (setjmp(rtld_fail)) {
/* Clean up anything new that was (partially) loaded */
} else p = load_library(file);
if (!p) {
- snprintf(errbuf, sizeof errbuf,
- "Error loading shared library %s: %m", file);
+ snprintf(errbuf, sizeof errbuf, noload ?
+ "Library %s is not already loaded" :
+ "Error loading shared library %s: %m",
+ file);
errflag = 1;
goto end;
}
return p;
}
-static int invalid_dso_handle(struct dso *h)
+static int invalid_dso_handle(void *h)
{
struct dso *p;
for (p=head; p; p=p->next) if (h==p) return 0;
return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
return def.dso->base + def.sym->st_value;
}
- if (invalid_dso_handle(p)) return 0;
+ if (p != RTLD_DEFAULT && p != RTLD_NEXT && invalid_dso_handle(p))
+ return 0;
if (p->ghashtab) {
gh = gnu_hash(s);
sym = gnu_lookup(s, gh, p);
return ret;
}
#else
-static int invalid_dso_handle(struct dso *h)
+static int invalid_dso_handle(void *h)
{
snprintf(errbuf, sizeof errbuf, "Invalid library handle %p", (void *)h);
errflag = 1;