This source file includes following definitions.
- get_vtable
- vl_exit
- vm_open
- vm_close
- vm_sym
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 #include "lt__private.h"
33 #include "lt_dlloader.h"
34
35
36
37
38
39 #define get_vtable load_add_on_LTX_get_vtable
40
41 LT_BEGIN_C_DECLS
42 LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
43 LT_END_C_DECLS
44
45
46
47
48 static int vl_exit (lt_user_data loader_data);
49 static lt_module vm_open (lt_user_data loader_data, const char *filename,
50 lt_dladvise advise);
51 static int vm_close (lt_user_data loader_data, lt_module module);
52 static void * vm_sym (lt_user_data loader_data, lt_module module,
53 const char *symbolname);
54
55 static lt_dlvtable *vtable = 0;
56
57
58
59
60 lt_dlvtable *
61 get_vtable (lt_user_data loader_data)
62 {
63 if (!vtable)
64 {
65 vtable = lt__zalloc (sizeof *vtable);
66 }
67
68 if (vtable && !vtable->name)
69 {
70 vtable->name = "lt_load_add_on";
71 vtable->module_open = vm_open;
72 vtable->module_close = vm_close;
73 vtable->find_sym = vm_sym;
74 vtable->dlloader_exit = vl_exit;
75 vtable->dlloader_data = loader_data;
76 vtable->priority = LT_DLLOADER_APPEND;
77 }
78
79 if (vtable && (vtable->dlloader_data != loader_data))
80 {
81 LT__SETERROR (INIT_LOADER);
82 return 0;
83 }
84
85 return vtable;
86 }
87
88
89
90
91
92
93 #include <kernel/image.h>
94
95
96
97 static int
98 vl_exit (lt_user_data LT__UNUSED loader_data)
99 {
100 vtable = NULL;
101 return 0;
102 }
103
104
105
106
107 static lt_module
108 vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
109 lt_dladvise LT__UNUSED advise)
110 {
111 image_id image = 0;
112
113 if (filename)
114 {
115 image = load_add_on (filename);
116 }
117 else
118 {
119 image_info info;
120 int32 cookie = 0;
121 if (get_next_image_info (0, &cookie, &info) == B_OK)
122 image = load_add_on (info.name);
123 }
124
125 if (image <= 0)
126 {
127 LT__SETERROR (CANNOT_OPEN);
128 image = 0;
129 }
130
131 return (lt_module) image;
132 }
133
134
135
136
137 static int
138 vm_close (lt_user_data LT__UNUSED loader_data, lt_module module)
139 {
140 int errors = 0;
141
142 if (unload_add_on ((image_id) module) != B_OK)
143 {
144 LT__SETERROR (CANNOT_CLOSE);
145 ++errors;
146 }
147
148 return errors;
149 }
150
151
152
153
154 static void *
155 vm_sym (lt_user_data LT__UNUSED loader_data, lt_module module, const char *name)
156 {
157 void *address = 0;
158 image_id image = (image_id) module;
159
160 if (get_image_symbol (image, name, B_SYMBOL_TYPE_ANY, address) != B_OK)
161 {
162 LT__SETERROR (SYMBOL_NOT_FOUND);
163 address = 0;
164 }
165
166 return address;
167 }