diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index 77413d619d68..bbfd9e81c8d7 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -487,6 +487,7 @@ FBSDprivate_1.0 { _rtld_atfork_post; _rtld_error; /* for private use */ _rtld_get_stack_prot; + _rtld_is_dlopened; _rtld_thread_init; /* for private use */ __elf_phdr_match_addr; _err; diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c index ad24bb4914ca..5bdf4ab48e5b 100644 --- a/lib/libc/gen/dlfcn.c +++ b/lib/libc/gen/dlfcn.c @@ -233,3 +233,10 @@ _rtld_get_stack_prot(void) return (PROT_EXEC | PROT_READ | PROT_WRITE); } +#pragma weak _rtld_is_dlopened +int +_rtld_is_dlopened(void *arg) +{ + + return (0); +} diff --git a/libexec/rtld-elf/Symbol.map b/libexec/rtld-elf/Symbol.map index 5ea7d7e171f6..4adc2adcae61 100644 --- a/libexec/rtld-elf/Symbol.map +++ b/libexec/rtld-elf/Symbol.map @@ -30,5 +30,6 @@ FBSDprivate_1.0 { _rtld_atfork_post; _rtld_addr_phdr; _rtld_get_stack_prot; + _rtld_is_dlopened; _r_debug_postinit; }; diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 6bbb10c83a5e..1550da16fc2e 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -2222,6 +2222,7 @@ do_load_object(int fd, const char *name, char *path, struct stat *sbp, return (NULL); } + obj->dlopened = (flags & RTLD_LO_DLOPEN) != 0; *obj_tail = obj; obj_tail = &obj->next; obj_count++; @@ -4884,6 +4885,27 @@ _rtld_get_stack_prot(void) return (stack_prot); } +int +_rtld_is_dlopened(void *arg) +{ + Obj_Entry *obj; + RtldLockState lockstate; + int res; + + rlock_acquire(rtld_bind_lock, &lockstate); + obj = dlcheck(arg); + if (obj == NULL) + obj = obj_from_addr(arg); + if (obj == NULL) { + _rtld_error("No shared object contains address"); + lock_release(rtld_bind_lock, &lockstate); + return (-1); + } + res = obj->dlopened ? 1 : 0; + lock_release(rtld_bind_lock, &lockstate); + return (res); +} + static void map_stacks_exec(RtldLockState *lockstate) { diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index ace229feba19..e5391178d3b4 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -275,6 +275,7 @@ typedef struct Struct_Obj_Entry { bool crt_no_init : 1; /* Object' crt does not call _init/_fini */ bool valid_hash_sysv : 1; /* A valid System V hash hash tag is available */ bool valid_hash_gnu : 1; /* A valid GNU hash tag is available */ + bool dlopened : 1; /* dlopen()-ed (vs. load statically) */ struct link_map linkmap; /* For GDB and dlinfo() */ Objlist dldags; /* Object belongs to these dlopened DAGs (%) */ diff --git a/sys/sys/link_elf.h b/sys/sys/link_elf.h index 35fe68eb2927..c228f1d273d5 100644 --- a/sys/sys/link_elf.h +++ b/sys/sys/link_elf.h @@ -94,6 +94,7 @@ typedef int (*__dl_iterate_hdr_callback)(struct dl_phdr_info *, size_t, void *); extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void *); int _rtld_addr_phdr(const void *, struct dl_phdr_info *); int _rtld_get_stack_prot(void); +int _rtld_is_dlopened(void *); #ifdef __ARM_EABI__ void * dl_unwind_find_exidx(const void *, int *);