Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 2 | * xmlmodule.c : basic API for dynamic module loading added 2.6.17 |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
| 6 | * joelwreed@comcast.net |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 7 | * |
| 8 | * http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #define IN_LIBXML |
| 12 | #include "libxml.h" |
| 13 | |
| 14 | #include <string.h> |
| 15 | #include <libxml/xmlmemory.h> |
| 16 | #include <libxml/xmlerror.h> |
| 17 | #include <libxml/xmlmodule.h> |
| 18 | #include <libxml/globals.h> |
| 19 | |
| 20 | #ifdef LIBXML_MODULES_ENABLED |
| 21 | |
| 22 | struct _xmlModule { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 23 | unsigned char *name; |
| 24 | void *handle; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 27 | static void *xmlModulePlatformOpen(const char *name); |
| 28 | static int xmlModulePlatformClose(void *handle); |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 29 | static int xmlModulePlatformSymbol(void *handle, const char *name, void **result); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 30 | |
| 31 | /************************************************************************ |
| 32 | * * |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 33 | * module memory error handler * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 34 | * * |
| 35 | ************************************************************************/ |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 36 | |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 37 | /** |
| 38 | * xmlModuleErrMemory: |
| 39 | * @extra: extra information |
| 40 | * |
| 41 | * Handle an out of memory condition |
| 42 | */ |
| 43 | static void |
| 44 | xmlModuleErrMemory(xmlModulePtr module, const char *extra) |
| 45 | { |
| 46 | const char *name = NULL; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 47 | |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 48 | if (module != NULL) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 49 | name = (const char *) module->name; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 53 | XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra, |
| 54 | name, NULL, 0, 0, |
| 55 | "Memory allocation failed : %s\n", extra); |
| 56 | } |
| 57 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 58 | /** |
| 59 | * xmlModuleOpen: |
| 60 | * @name: the module name |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 61 | * @options: a set of xmlModuleOption |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 62 | * |
| 63 | * Opens a module/shared library given its name or path |
Patrick Gansterer | 5a82e48 | 2012-08-13 17:39:06 +0800 | [diff] [blame] | 64 | * NOTE: that due to portability issues, behaviour can only be |
| 65 | * guaranteed with @name using ASCII. We canot guarantee that |
| 66 | * an UTF-8 string would work, which is why name is a const char * |
| 67 | * and not a const xmlChar * . |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 68 | * TODO: options are not yet implemented. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 69 | * |
| 70 | * Returns a handle for the module or NULL in case of error |
| 71 | */ |
| 72 | xmlModulePtr |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 73 | xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 74 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 75 | xmlModulePtr module; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 76 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 77 | module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule)); |
| 78 | if (module == NULL) { |
| 79 | xmlModuleErrMemory(NULL, "creating module"); |
| 80 | return (NULL); |
| 81 | } |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 82 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 83 | memset(module, 0, sizeof(xmlModule)); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 84 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 85 | module->handle = xmlModulePlatformOpen(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 86 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 87 | if (module->handle == NULL) { |
| 88 | xmlFree(module); |
| 89 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 90 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
| 91 | name, NULL, 0, 0, "failed to open %s\n", name); |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 92 | return(NULL); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | module->name = xmlStrdup((const xmlChar *) name); |
| 96 | return (module); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * xmlModuleSymbol: |
| 101 | * @module: the module |
| 102 | * @name: the name of the symbol |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 103 | * @symbol: the resulting symbol address |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 104 | * |
| 105 | * Lookup for a symbol address in the given module |
Patrick Gansterer | 5a82e48 | 2012-08-13 17:39:06 +0800 | [diff] [blame] | 106 | * NOTE: that due to portability issues, behaviour can only be |
| 107 | * guaranteed with @name using ASCII. We canot guarantee that |
| 108 | * an UTF-8 string would work, which is why name is a const char * |
| 109 | * and not a const xmlChar * . |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 110 | * |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 111 | * Returns 0 if the symbol was found, or -1 in case of error |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 112 | */ |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 113 | int |
| 114 | xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol) |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 115 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 116 | int rc = -1; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 117 | |
Gaurav | 085b997 | 2014-02-18 11:47:43 +0800 | [diff] [blame] | 118 | if ((NULL == module) || (symbol == NULL) || (name == NULL)) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 119 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 120 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 121 | NULL, NULL, 0, 0, "null parameter\n"); |
| 122 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 125 | rc = xmlModulePlatformSymbol(module->handle, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 126 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 127 | if (rc == -1) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 128 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 129 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 130 | name, NULL, 0, 0, |
| 131 | "failed to find symbol: %s\n", |
| 132 | (name == NULL ? "NULL" : name)); |
| 133 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 136 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * xmlModuleClose: |
| 141 | * @module: the module handle |
| 142 | * |
| 143 | * The close operations unload the associated module and free the |
| 144 | * data associated to the module. |
| 145 | * |
| 146 | * Returns 0 in case of success, -1 in case of argument error and -2 |
| 147 | * if the module could not be closed/unloaded. |
| 148 | */ |
| 149 | int |
| 150 | xmlModuleClose(xmlModulePtr module) |
| 151 | { |
| 152 | int rc; |
| 153 | |
| 154 | if (NULL == module) { |
| 155 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 156 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
| 157 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | rc = xmlModulePlatformClose(module->handle); |
| 162 | |
| 163 | if (rc != 0) { |
| 164 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 165 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 166 | (const char *) module->name, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 167 | "failed to close: %s\n", module->name); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 168 | return -2; |
| 169 | } |
| 170 | |
| 171 | rc = xmlModuleFree(module); |
| 172 | return (rc); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * xmlModuleFree: |
| 177 | * @module: the module handle |
| 178 | * |
| 179 | * The free operations free the data associated to the module |
| 180 | * but does not unload the associated shared library which may still |
| 181 | * be in use. |
| 182 | * |
| 183 | * Returns 0 in case of success, -1 in case of argument error |
| 184 | */ |
| 185 | int |
| 186 | xmlModuleFree(xmlModulePtr module) |
| 187 | { |
| 188 | if (NULL == module) { |
| 189 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 190 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 191 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 192 | return -1; |
| 193 | } |
| 194 | |
| 195 | xmlFree(module->name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 196 | xmlFree(module); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 197 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 198 | return (0); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Daniel Veillard | 643fb5d | 2008-02-08 10:49:46 +0000 | [diff] [blame] | 201 | #if defined(HAVE_DLOPEN) && !defined(_WIN32) |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 202 | #ifdef HAVE_DLFCN_H |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 203 | #include <dlfcn.h> |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 204 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 205 | |
Daniel Veillard | 9b693b4 | 2005-10-28 14:54:17 +0000 | [diff] [blame] | 206 | #ifndef RTLD_GLOBAL /* For Tru64 UNIX 4.0 */ |
| 207 | #define RTLD_GLOBAL 0 |
| 208 | #endif |
| 209 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 210 | /** |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 211 | * xmlModulePlatformOpen: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 212 | * @name: path to the module |
| 213 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 214 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 215 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 216 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 217 | static void * |
| 218 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 219 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 220 | return dlopen(name, RTLD_GLOBAL | RTLD_NOW); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* |
| 224 | * xmlModulePlatformClose: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 225 | * @handle: handle to the module |
| 226 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 227 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 228 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 229 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 230 | static int |
| 231 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 232 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 233 | return dlclose(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 238 | * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html |
| 239 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 240 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 241 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 242 | static int |
| 243 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 244 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 245 | *symbol = dlsym(handle, name); |
| 246 | if (dlerror() != NULL) { |
| 247 | return -1; |
| 248 | } |
| 249 | return 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Daniel Veillard | ff4c185 | 2005-03-10 10:37:28 +0000 | [diff] [blame] | 252 | #else /* ! HAVE_DLOPEN */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 253 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 254 | #ifdef HAVE_SHLLOAD /* HAVE_SHLLOAD */ |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 255 | #ifdef HAVE_DL_H |
| 256 | #include <dl.h> |
| 257 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 258 | /* |
| 259 | * xmlModulePlatformOpen: |
| 260 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 261 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 262 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 263 | static void * |
| 264 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 265 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 266 | return shl_load(name, BIND_IMMEDIATE, 0L); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | * xmlModulePlatformClose: |
| 271 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 272 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 273 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 274 | static int |
| 275 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 276 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 277 | return shl_unload(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* |
| 281 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 282 | * http://docs.hp.com/en/B2355-90683/shl_load.3X.html |
| 283 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 284 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 285 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 286 | static int |
| 287 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 288 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 289 | int rc; |
| 290 | |
| 291 | errno = 0; |
Daniel Veillard | 9b693b4 | 2005-10-28 14:54:17 +0000 | [diff] [blame] | 292 | rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol); |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 293 | return rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | #endif /* HAVE_SHLLOAD */ |
Daniel Veillard | ff4c185 | 2005-03-10 10:37:28 +0000 | [diff] [blame] | 297 | #endif /* ! HAVE_DLOPEN */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 298 | |
| 299 | #ifdef _WIN32 |
| 300 | |
| 301 | #include <windows.h> |
| 302 | |
| 303 | /* |
| 304 | * xmlModulePlatformOpen: |
| 305 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 306 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 307 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 308 | static void * |
| 309 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 310 | { |
Patrick Gansterer | 5a82e48 | 2012-08-13 17:39:06 +0800 | [diff] [blame] | 311 | return LoadLibraryA(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* |
| 315 | * xmlModulePlatformClose: |
| 316 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 317 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 318 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 319 | static int |
| 320 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 321 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 322 | int rc; |
| 323 | |
| 324 | rc = FreeLibrary(handle); |
| 325 | return (0 == rc); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
| 329 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 330 | * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocaddress.asp |
| 331 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 332 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 333 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 334 | static int |
| 335 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 336 | { |
Daniel Veillard | dfc0aa0 | 2012-08-17 11:04:24 +0800 | [diff] [blame] | 337 | #ifdef _WIN32_WCE |
| 338 | /* |
| 339 | * GetProcAddressA seems only available on WinCE |
| 340 | */ |
Patrick Gansterer | 5a82e48 | 2012-08-13 17:39:06 +0800 | [diff] [blame] | 341 | *symbol = GetProcAddressA(handle, name); |
Daniel Veillard | dfc0aa0 | 2012-08-17 11:04:24 +0800 | [diff] [blame] | 342 | #else |
| 343 | *symbol = GetProcAddress(handle, name); |
| 344 | #endif |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 345 | return (NULL == *symbol) ? -1 : 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | #endif /* _WIN32 */ |
| 349 | |
| 350 | #ifdef HAVE_BEOS |
| 351 | |
| 352 | #include <kernel/image.h> |
| 353 | |
| 354 | /* |
| 355 | * xmlModulePlatformOpen: |
| 356 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 357 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 358 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 359 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 360 | static void * |
| 361 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 362 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 363 | return (void *) load_add_on(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* |
| 367 | * xmlModulePlatformClose: |
| 368 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 369 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 370 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 371 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 372 | static int |
| 373 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 374 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 375 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 376 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 377 | rc = unload_add_on((image_id) handle); |
| 378 | |
| 379 | if (rc == B_OK) |
| 380 | return 0; |
| 381 | else |
| 382 | return -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* |
| 386 | * xmlModulePlatformSymbol: |
| 387 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 388 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 389 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 390 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 391 | static int |
| 392 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 393 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 394 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 395 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 396 | rc = get_image_symbol((image_id) handle, name, B_SYMBOL_TYPE_ANY, symbol); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 397 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 398 | return (rc == B_OK) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | #endif /* HAVE_BEOS */ |
| 402 | |
| 403 | #ifdef HAVE_OS2 |
| 404 | |
| 405 | #include <os2.h> |
| 406 | |
| 407 | /* |
| 408 | * xmlModulePlatformOpen: |
| 409 | * os2 api info: http://www.edm2.com/os2api/Dos/DosLoadModule.html |
| 410 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 411 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 412 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 413 | static void * |
| 414 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 415 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 416 | char errbuf[256]; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 417 | void *handle; |
| 418 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 419 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 420 | rc = DosLoadModule(errbuf, sizeof(errbuf) - 1, name, &handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 421 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 422 | if (rc) |
| 423 | return 0; |
| 424 | else |
| 425 | return (handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* |
| 429 | * xmlModulePlatformClose: |
| 430 | * os2 api info: http://www.edm2.com/os2api/Dos/DosFreeModule.html |
| 431 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 432 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 433 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 434 | static int |
| 435 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 436 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 437 | return DosFreeModule(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* |
| 441 | * xmlModulePlatformSymbol: |
| 442 | * os2 api info: http://www.edm2.com/os2api/Dos/DosQueryProcAddr.html |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 443 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 444 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 445 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 446 | static int |
| 447 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 448 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 449 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 450 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 451 | rc = DosQueryProcAddr(handle, 0, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 452 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 453 | return (rc == NO_ERROR) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | #endif /* HAVE_OS2 */ |
| 457 | |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 458 | #define bottom_xmlmodule |
| 459 | #include "elfgcchack.h" |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 460 | #endif /* LIBXML_MODULES_ENABLED */ |