1 /* 2 * Copyright 2011 Red Hat, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 /* Determines if a symbol is present in a given module. 26 * 27 * @param modname The name of the module. 28 * @param symbname The name of the symbol. 29 * @return Non-zero if found, zero if not found. 30 */ 31 int 32 module_symbol_is_present(const char *modname, const char *symbname); 33 34 /* Finds the file for a given symbol. 35 * 36 * If filename is non-null, the name of the file will be stored. This must 37 * be freed with free(). 38 * 39 * @param addr The address to resolve. 40 * @param filename Where to store the name of the file. 41 * @return 0 on error, non-zero on success. 42 */ 43 int 44 module_get_filename_for_symbol(void *addr, char **filename); 45 46 /* Closes a module. 47 * 48 * Does nothing if dll is NULL. 49 * 50 * @param dll The module to close. 51 */ 52 void 53 module_close(void *dll); 54 55 56 /* Loads a module and extracts the given symbol. 57 * 58 * This function loads the module specified by filename, but does not resolve 59 * any of its symbol dependencies. Next is gets the symbol symbname and calls 60 * shouldload(). If shouldload() returns non-zero, the module is reloaded 61 * with full symbol resolution and stores the results in dll and symb. 62 * 63 * The job of shouldload() is to determine, based on the metadata in the 64 * symbol fetched, if the module should be fully loaded. The shouldload() 65 * callback MUST NOT attempt to call any functions in the module. This will 66 * crash on WIN32. 67 * 68 * If an error occurs, an error string will be allocated and returned. If 69 * allocation of this string fails, NULL will be returned. Since this is the 70 * same as the non-error case, you should additionally check if dll or symb 71 * is NULL. 72 * 73 * @param filename Path to the module 74 * @param symbname Symbol name to load from the file and pass to shouldload() 75 * @param shouldload Callback to determine whether to fullly load the module 76 * @param misc Opaque pointer to pass to shouldload() 77 * @param dll Where the module will be stored (can be NULL) 78 * @param symb Where the symbol will be stored (can be NULL) 79 * @return An error string. 80 */ 81 char * 82 module_load(const char *filename, const char *symbname, 83 int (*shouldload)(void *symb, void *misc, char **err), void *misc, 84 void **dll, void **symb); 85