From c4acabaa74314caf18871fc7d9106770439cca8e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Jan 2017 16:01:03 -0600 Subject: [PATCH] In dlopen(), use the basename of the file as the module name --- include/libgen.h | 4 +--- libc/dllfcn/lib_dlopen.c | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/libgen.h b/include/libgen.h index 73f01341bd..e7e2880852 100644 --- a/include/libgen.h +++ b/include/libgen.h @@ -40,9 +40,7 @@ * Included Files ****************************************************************************/ -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ +#include /**************************************************************************** * Public Function Prototypes diff --git a/libc/dllfcn/lib_dlopen.c b/libc/dllfcn/lib_dlopen.c index a66a6e5444..28df22d13d 100644 --- a/libc/dllfcn/lib_dlopen.c +++ b/libc/dllfcn/lib_dlopen.c @@ -39,7 +39,11 @@ #include +#include +#include +#include #include +#include #include @@ -150,6 +154,11 @@ FAR void *dlopen(FAR const char *file, int mode) { #if defined(CONFIG_BUILD_FLAT) + FAR void *handle; + FAR char *name; + + DEBUGASSERT(file != NULL); + /* In the FLAT build, a shared library is essentially the same as a kernel * module. * @@ -159,7 +168,23 @@ FAR void *dlopen(FAR const char *file, int mode) * - mode is ignored. */ - return insmod(file, file); + /* Use the basename of the file as the module name. + * REVISIT: This places an non-standard restriction. We cannot install + * two modules of the same name event though they lie in different + * directories. + */ + + name = strdup(file); + if (name == NULL) + { + return NULL; + } + + /* Then install the file using the basename of the file as the module name. */ + + handle = insmod(file, basename(name)); + free(name); + return handle; #elif defined(CONFIG_BUILD_PROTECTED) /* The PROTECTED build is equivalent to the FLAT build EXCEPT that there