diff --git a/libc/dllfcn/Kconfig b/libc/dllfcn/Kconfig index 7e86a0e22f..e83d6d0616 100644 --- a/libc/dllfcn/Kconfig +++ b/libc/dllfcn/Kconfig @@ -7,7 +7,8 @@ config LIBC_DLLFCN bool "Shared library support" default n select LIBC_ARCH_ELF - depends on EXPERIMENTAL + select MODULE if BUILD_FLAT + depends on EXPERIMENTAL || BUILD_FLAT ---help--- Enabled support for user-space shared libraries. diff --git a/libc/dllfcn/lib_dlclose.c b/libc/dllfcn/lib_dlclose.c index 7eb4ed7966..32e46fc73a 100644 --- a/libc/dllfcn/lib_dlclose.c +++ b/libc/dllfcn/lib_dlclose.c @@ -41,6 +41,8 @@ #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -88,6 +90,37 @@ int dlclose(FAR void *handle) { +#if defined(CONFIG_BUILD_FLAT) + /* In the FLAT build, a shared library is essentially the same as a kernel + * module. + */ + + return rmmod(handle); + +#elif defined(CONFIG_BUILD_PROTECTED) + /* The PROTECTED build is equivalent to the FLAT build EXCEPT that there + * must be two copies of the the module logic: One residing in kernel + * space and using the kernel symbol table and one residing in user space + * using the user space symbol table. + * + * The brute force way to accomplish this is by just copying the kernel + * module code into libc/module. + */ + #warning Missing logic - return 1; + return -ENOSYS; + +#else /* if defined(CONFIG_BUILD_KERNEL) */ + /* The KERNEL build is considerably more complex: In order to be shared, + * the .text portion of the module must be (1) build for PIC/PID operation + * and (2) must like in a shared memory region accessible from all + * processes. The .data/.bss portion of the module must be allocated in + * the user space of each process, but must lie at the same virtual address + * so that it can be referenced from the one copy of the text in the shared + * memory region. + */ + +#warning Missing logic + return -ENOSYS; +#endif } \ No newline at end of file diff --git a/libc/dllfcn/lib_dlopen.c b/libc/dllfcn/lib_dlopen.c index 95a97d05f5..a66a6e5444 100644 --- a/libc/dllfcn/lib_dlopen.c +++ b/libc/dllfcn/lib_dlopen.c @@ -41,6 +41,8 @@ #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -147,6 +149,42 @@ FAR void *dlopen(FAR const char *file, int mode) { +#if defined(CONFIG_BUILD_FLAT) + /* In the FLAT build, a shared library is essentially the same as a kernel + * module. + * + * REVIST: Missing functionality: + * - No automatic binding of symbols + * - No dependencies + * - mode is ignored. + */ + + return insmod(file, file); + +#elif defined(CONFIG_BUILD_PROTECTED) + /* The PROTECTED build is equivalent to the FLAT build EXCEPT that there + * must be two copies of the the module logic: One residing in kernel + * space and using the kernel symbol table and one residing in user space + * using the user space symbol table. + * + * The brute force way to accomplish this is by just copying the kernel + * module code into libc/module. + */ + #warning Missing logic return NULL; -} \ No newline at end of file + +#else /* if defined(CONFIG_BUILD_KERNEL) */ + /* The KERNEL build is considerably more complex: In order to be shared, + * the .text portion of the module must be (1) build for PIC/PID operation + * and (2) must like in a shared memory region accessible from all + * processes. The .data/.bss portion of the module must be allocated in + * the user space of each process, but must lie at the same virtual address + * so that it can be referenced from the one copy of the text in the shared + * memory region. + */ + +#warning Missing logic + return NULL; +#endif +} diff --git a/libc/dllfcn/lib_dlsym.c b/libc/dllfcn/lib_dlsym.c index bf4f133727..85ed522565 100644 --- a/libc/dllfcn/lib_dlsym.c +++ b/libc/dllfcn/lib_dlsym.c @@ -41,6 +41,8 @@ #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -78,6 +80,37 @@ FAR void *dlsym(FAR void *handle, FAR const char *name) { +#if defined(CONFIG_BUILD_FLAT) + /* In the FLAT build, a shared library is essentially the same as a kernel + * module. + */ + + return (FAR void *)modsym(handle, name); + +#elif defined(CONFIG_BUILD_PROTECTED) + /* The PROTECTED build is equivalent to the FLAT build EXCEPT that there + * must be two copies of the the module logic: One residing in kernel + * space and using the kernel symbol table and one residing in user space + * using the user space symbol table. + * + * The brute force way to accomplish this is by just copying the kernel + * module code into libc/module. + */ + #warning Missing logic return NULL; + +#else /* if defined(CONFIG_BUILD_KERNEL) */ + /* The KERNEL build is considerably more complex: In order to be shared, + * the .text portion of the module must be (1) build for PIC/PID operation + * and (2) must like in a shared memory region accessible from all + * processes. The .data/.bss portion of the module must be allocated in + * the user space of each process, but must lie at the same virtual address + * so that it can be referenced from the one copy of the text in the shared + * memory region. + */ + +#warning Missing logic + return NULL; +#endif } \ No newline at end of file