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