]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ldso/ldso/vfs.cc
update
[l4.git] / l4 / pkg / ldso / ldso / vfs.cc
1 // we do better not export anything from LDSO
2
3 #define L4_EXPORT
4
5 #include <l4/crtn/initpriorities.h>
6 #include <l4/util/util.h>
7
8 #include <l4/re/env>
9 #include <l4/re/util/bitmap_cap_alloc>
10
11 #include <stddef.h>
12 #include <dlfcn.h>
13
14 extern "C"
15 void *memset(void *dst, int v, size_t s)
16 {
17   char *d = (char*)dst;
18   for (; s > 0; --s, ++d)
19     *d = v;
20
21   return dst;
22 }
23
24 extern "C"
25 void *memcpy(void *dst, void const *src, size_t si)
26 {
27   char *d = (char *)dst;
28   char const *s = (char const *)src;
29   for (; si > 0; --si, ++s, ++d)
30     *d = *s;
31
32   return d;
33 }
34
35 inline
36 void l4_sleep(int)
37 {}
38 extern "C"
39 inline
40 size_t strlen(char const *s)
41 {
42   long i = 0;
43   for (; *s; ++s, ++i)
44     ;
45
46   return i;
47 }
48
49
50 #include <l4/re/impl/dataspace_impl.h>
51 #include <l4/re/impl/rm_impl.h>
52 #include <l4/re/impl/namespace_impl.h>
53 #include <l4/re/impl/mem_alloc_impl.h>
54
55 // must correspond to dl-elf.h
56 #define ELF_RTYPE_CLASS_PLT (0x1)
57
58 // must correspond to dl-hash.h
59 struct dyn_elf {
60   struct elf_resolve * dyn;
61 #if 0
62   struct dyn_elf * next_handle;  /* Used by dlopen et al. */
63   struct init_fini init_fini;
64   struct dyn_elf * next;
65   struct dyn_elf * prev;
66 #endif
67 };
68
69 extern struct dyn_elf *_dl_symbol_tables;
70 extern "C" char * _dl_find_hash(const char * name, struct dyn_elf * rpnt,
71                                   struct elf_resolve *mytpnt, int type_class,
72                                   struct elf_resolve **tpntp);
73
74 extern "C" attribute_hidden void *__rtld_l4re_global_env;
75 extern "C" void _dl_dprintf(int, const char *, ...);
76 namespace Vfs_config {
77
78   using ::memcpy;
79   typedef void *Dl_open(const char *libname, int flag);
80   static Dl_open *_dl_open;
81
82   namespace
83   {
84     L4Re::Util::Cap_alloc<256> __attribute__((init_priority(INIT_PRIO_L4RE_UTIL_CAP_ALLOC))) __cap_alloc(256); //L4Re::Env::env()->first_free_cap() - 256);
85   };
86   L4Re::Util::Cap_alloc_base &cap_alloc = __cap_alloc;
87
88
89   inline
90   L4::Cap<L4Re::Mem_alloc> allocator()
91   {
92     return reinterpret_cast<L4Re::Env const *>(__rtld_l4re_global_env)->mem_alloc();
93   }
94
95   inline int
96   load_module(char const *fstype)
97   {
98     if (!_dl_open)
99       {
100         _dl_open = (Dl_open*)_dl_find_hash("dlopen", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL);
101         if (!_dl_open)
102           return -1;
103       }
104
105     char const prefix[] = "libl4revfs-fs-";
106     char const suffix[] = ".so";
107     char name[80];
108     memcpy(name, prefix, sizeof(prefix) - 1);
109     memcpy(name + sizeof(prefix) - 1, fstype, strlen(fstype));
110     memcpy(name + sizeof(prefix) + strlen(fstype) - 1, suffix, sizeof(suffix));
111     return _dl_open(name, RTLD_LOCAL | RTLD_LAZY) ? 0 : -1;
112   }
113
114 }
115
116
117 extern "C" void __cxa_pure_virtual(void)
118 {
119   l4_sleep_forever();
120 }
121
122 extern "C" void __cxa_atexit(void)
123 {}
124
125 #ifdef __ARM_EABI__
126 extern "C" void __aeabi_atexit(void)
127 {}
128 #endif
129
130 #include <l4/l4re_vfs/impl/ns_fs_impl.h>
131 #include <l4/l4re_vfs/impl/ro_file_impl.h>
132 #include <l4/l4re_vfs/impl/fd_store_impl.h>
133 #include <l4/l4re_vfs/impl/vcon_stream_impl.h>
134 #include <l4/l4re_vfs/impl/vfs_api_impl.h>
135 #include <l4/l4re_vfs/impl/vfs_impl.h>