-/* $OpenBSD: dlfcn.c,v 1.110 2022/01/08 17:28:49 deraadt Exp $ */
+/* $OpenBSD: dlfcn.c,v 1.111 2022/08/20 14:11:31 sthen Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
static lock_cb *_dl_thread_fnc = NULL;
static elf_object_t *obj_from_addr(const void *addr);
+#define OK_FLAGS (0 \
+ | RTLD_TRACE \
+ | RTLD_LAZY \
+ | RTLD_NOW \
+ | RTLD_GLOBAL \
+ | RTLD_NODELETE \
+ | RTLD_NOLOAD \
+ )
+
void *
dlopen(const char *libname, int flags)
{
int failed = 0;
int obj_flags;
- if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE)) {
+ if (flags & ~OK_FLAGS) {
_dl_errno = DL_INVALID_MODE;
return NULL;
}
_dl_loading_object = NULL;
obj_flags = (flags & RTLD_NOW ? DF_1_NOW : 0)
- | (flags & RTLD_GLOBAL ? DF_1_GLOBAL : 0);
+ | (flags & RTLD_GLOBAL ? DF_1_GLOBAL : 0)
+ | (flags & RTLD_NOLOAD ? DF_1_NOOPEN : 0)
+ ;
object = _dl_load_shlib(libname, _dl_objects, OBJTYPE_DLO, obj_flags);
if (object == 0) {
DL_DEB(("dlopen: failed to open %s\n", libname));
-/* $OpenBSD: library.c,v 1.86 2022/01/08 06:49:41 guenther Exp $ */
+/* $OpenBSD: library.c,v 1.87 2022/08/20 14:11:31 sthen Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
for (object = _dl_objects; object != NULL; object = object->next) {
if (object->dev == sb.st_dev &&
object->inode == sb.st_ino) {
- object->obj_flags |= flags & DF_1_GLOBAL;
_dl_close(libfile);
- if (_dl_loading_object == NULL)
- _dl_loading_object = object;
- if (object->load_object != _dl_objects &&
- object->load_object != _dl_loading_object) {
- _dl_link_grpref(object->load_object,
- _dl_loading_object);
- }
+ _dl_handle_already_loaded(object, flags);
return(object);
}
}
+ if (flags & DF_1_NOOPEN) {
+ _dl_close(libfile);
+ return NULL;
+
+ }
_dl_read(libfile, hbuf, sizeof(hbuf));
ehdr = (Elf_Ehdr *)hbuf;
-/* $OpenBSD: library_mquery.c,v 1.66 2022/01/08 06:49:41 guenther Exp $ */
+/* $OpenBSD: library_mquery.c,v 1.67 2022/08/20 14:11:31 sthen Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
for (object = _dl_objects; object != NULL; object = object->next) {
if (object->dev == sb.st_dev &&
object->inode == sb.st_ino) {
- object->obj_flags |= flags & DF_1_GLOBAL;
_dl_close(libfile);
- if (_dl_loading_object == NULL)
- _dl_loading_object = object;
- if (object->load_object != _dl_objects &&
- object->load_object != _dl_loading_object) {
- _dl_link_grpref(object->load_object,
- _dl_loading_object);
- }
+ _dl_handle_already_loaded(object, flags);
return(object);
}
}
+ if (flags & DF_1_NOOPEN) {
+ _dl_close(libfile);
+ return NULL;
+ }
_dl_read(libfile, hbuf, sizeof(hbuf));
ehdr = (Elf_Ehdr *)hbuf;
-/* $OpenBSD: library_subr.c,v 1.51 2022/01/08 06:49:41 guenther Exp $ */
+/* $OpenBSD: library_subr.c,v 1.52 2022/08/20 14:11:31 sthen Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
return(NULL);
}
+void
+_dl_handle_already_loaded(elf_object_t *object, int flags)
+{
+ object->obj_flags |= flags & DF_1_GLOBAL;
+ if (_dl_loading_object == NULL)
+ _dl_loading_object = object;
+ if (object->load_object != _dl_objects &&
+ object->load_object != _dl_loading_object) {
+ _dl_link_grpref(object->load_object, _dl_loading_object);
+ }
+}
+
static elf_object_t *
_dl_find_loaded_shlib(const char *req_name, struct sod req_sod, int flags)
{
req_sod.sod_minor, orig_minor);
}
- if (object) { /* Already loaded */
- object->obj_flags |= flags & DF_1_GLOBAL;
- if (_dl_loading_object == NULL)
- _dl_loading_object = object;
- if (object->load_object != _dl_objects &&
- object->load_object != _dl_loading_object) {
- _dl_link_grpref(object->load_object, _dl_loading_object);
- }
- }
+ if (object)
+ _dl_handle_already_loaded(object, flags);
return (object);
}
-/* $OpenBSD: resolve.h,v 1.100 2022/01/28 05:01:28 guenther Exp $ */
+/* $OpenBSD: resolve.h,v 1.101 2022/08/20 14:11:31 sthen Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
void _dl_remove_object(elf_object_t *object);
void _dl_cleanup_objects(void);
+void _dl_handle_already_loaded(elf_object_t *_object, int _flags);
elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int, int);
elf_object_t *_dl_tryload_shlib(const char *libname, int type, int flags);