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