summaryrefslogtreecommitdiff
path: root/components/libc/libdl
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2016-05-10 09:22:01 +0800
committerBernard Xiong <[email protected]>2016-05-10 09:22:01 +0800
commit64feef0dde9d8353ffe4a3f257ab17848ccf6f53 (patch)
treedd3f096b8a3c249e5327cc34a0c105c5125099e1 /components/libc/libdl
parenteb320a0104bbaa6c1235fe899b6d099fdabe8c25 (diff)
[LIBC] mv pthreads/libdl to libc and rename dfs_lwip to dfs_net
Diffstat (limited to 'components/libc/libdl')
-rw-r--r--components/libc/libdl/SConscript9
-rw-r--r--components/libc/libdl/dlclose.c36
-rw-r--r--components/libc/libdl/dlerror.c24
-rw-r--r--components/libc/libdl/dlfcn.h18
-rw-r--r--components/libc/libdl/dlopen.c55
-rw-r--r--components/libc/libdl/dlsym.c37
6 files changed, 179 insertions, 0 deletions
diff --git a/components/libc/libdl/SConscript b/components/libc/libdl/SConscript
new file mode 100644
index 0000000000..f7f588858a
--- /dev/null
+++ b/components/libc/libdl/SConscript
@@ -0,0 +1,9 @@
+from building import *
+
+src = Glob('*.c')
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+
+group = DefineGroup('libdl', src, depend = ['RT_USING_MODULE', 'RT_USING_LIBDL'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/libdl/dlclose.c b/components/libc/libdl/dlclose.c
new file mode 100644
index 0000000000..af070891fc
--- /dev/null
+++ b/components/libc/libdl/dlclose.c
@@ -0,0 +1,36 @@
+/*
+ * File : dlclose.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 yi.qiu first version
+ */
+
+#include <rtthread.h>
+#include <rtm.h>
+
+int dlclose (void *handle)
+{
+ rt_module_t module;
+
+ RT_ASSERT(handle != RT_NULL);
+
+ module = (rt_module_t)handle;
+ module->nref--;
+
+ if(module->nref <= 0)
+ {
+ rt_module_unload(module);
+ }
+
+ return RT_TRUE;
+}
+
+RTM_EXPORT(dlclose)
+
diff --git a/components/libc/libdl/dlerror.c b/components/libc/libdl/dlerror.c
new file mode 100644
index 0000000000..dd076412fe
--- /dev/null
+++ b/components/libc/libdl/dlerror.c
@@ -0,0 +1,24 @@
+/*
+ * File : dlerror.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 yi.qiu first version
+ */
+
+#include <rtthread.h>
+#include <rtm.h>
+
+const char *dlerror(void)
+{
+ return "TODO";
+}
+
+RTM_EXPORT(dlerror)
+
diff --git a/components/libc/libdl/dlfcn.h b/components/libc/libdl/dlfcn.h
new file mode 100644
index 0000000000..069f0d9c46
--- /dev/null
+++ b/components/libc/libdl/dlfcn.h
@@ -0,0 +1,18 @@
+#ifndef __DLFCN_H_
+#define __DLFCN_H_
+
+#define RTLD_LAZY 0x00000
+#define RTLD_NOW 0x00001
+
+#define RTLD_LOCAL 0x00000
+#define RTLD_GLOBAL 0x10000
+
+#define RTLD_DEFAULT ((void*)1)
+#define RTLD_NEXT ((void*)2)
+
+void *dlopen (const char *filename, int flag);
+const char *dlerror(void);
+void *dlsym(void *handle, const char *symbol);
+int dlclose (void *handle);
+
+#endif
diff --git a/components/libc/libdl/dlopen.c b/components/libc/libdl/dlopen.c
new file mode 100644
index 0000000000..5e063eed96
--- /dev/null
+++ b/components/libc/libdl/dlopen.c
@@ -0,0 +1,55 @@
+/*
+ * File : dlopen.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 yi.qiu first version
+ */
+
+#include <rtthread.h>
+#include <rtm.h>
+#include <string.h>
+
+#define MODULE_ROOT_DIR "/module/lib"
+
+void* dlopen(const char *filename, int flags)
+{
+ rt_module_t module;
+ char *fullpath;
+ const char*def_path = MODULE_ROOT_DIR;
+
+ /* check parameters */
+ RT_ASSERT(filename != RT_NULL);
+
+ if (filename[0] != '/') /* it's a absolute path, use it directly */
+ {
+ fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);
+
+ /* join path and file name */
+ rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2,
+ "%s/%s", def_path, filename);
+ }
+ else
+ {
+ rt_kprintf("use absolute path\n");
+ return RT_NULL;
+ }
+
+ /* find in module list */
+ module = rt_module_find(fullpath);
+
+ if(module != RT_NULL) module->nref++;
+ else module = rt_module_open(fullpath);
+
+ rt_free(fullpath);
+ return (void*)module;
+}
+
+RTM_EXPORT(dlopen)
+
diff --git a/components/libc/libdl/dlsym.c b/components/libc/libdl/dlsym.c
new file mode 100644
index 0000000000..36c7b01fce
--- /dev/null
+++ b/components/libc/libdl/dlsym.c
@@ -0,0 +1,37 @@
+/*
+ * File : dlsym.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 yi.qiu first version
+ */
+
+#include <rtthread.h>
+#include <rtm.h>
+
+void* dlsym(void *handle, const char* symbol)
+{
+ int i;
+ rt_module_t module;
+
+ RT_ASSERT(handle != RT_NULL);
+
+ module = (rt_module_t)handle;
+
+ for(i=0; i<module->nsym; i++)
+ {
+ if (rt_strcmp(module->symtab[i].name, symbol) == 0)
+ return (void*)module->symtab[i].addr;
+ }
+
+ return RT_NULL;
+}
+
+RTM_EXPORT(dlsym)
+