Move dso.h to internal
[openssl.git] / crypto / dso / dso_locl.h
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  * Licensed under the OpenSSL licenses, (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *      https://www.openssl.org/source/license.html
7  * or in the file LICENSE in the source distribution.
8  */
9 #include <stdio.h>
10 #include "internal/cryptlib.h"
11 #include "internal/dso.h"
12 #include "internal/dso_conf.h"
13
14 /**********************************************************************/
15 /* The low-level handle type used to refer to a loaded shared library */
16
17 struct dso_st {
18     DSO_METHOD *meth;
19     /*
20      * Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS doesn't use
21      * anything but will need to cache the filename for use in the dso_bind
22      * handler. All in all, let each method control its own destiny.
23      * "Handles" and such go in a STACK.
24      */
25     STACK_OF(void) *meth_data;
26     int references;
27     int flags;
28     /*
29      * For use by applications etc ... use this for your bits'n'pieces, don't
30      * touch meth_data!
31      */
32     CRYPTO_EX_DATA ex_data;
33     /*
34      * If this callback function pointer is set to non-NULL, then it will be
35      * used in DSO_load() in place of meth->dso_name_converter. NB: This
36      * should normally set using DSO_set_name_converter().
37      */
38     DSO_NAME_CONVERTER_FUNC name_converter;
39     /*
40      * If this callback function pointer is set to non-NULL, then it will be
41      * used in DSO_load() in place of meth->dso_merger. NB: This should
42      * normally set using DSO_set_merger().
43      */
44     DSO_MERGER_FUNC merger;
45     /*
46      * This is populated with (a copy of) the platform-independent filename
47      * used for this DSO.
48      */
49     char *filename;
50     /*
51      * This is populated with (a copy of) the translated filename by which
52      * the DSO was actually loaded. It is NULL iff the DSO is not currently
53      * loaded. NB: This is here because the filename translation process may
54      * involve a callback being invoked more than once not only to convert to
55      * a platform-specific form, but also to try different filenames in the
56      * process of trying to perform a load. As such, this variable can be
57      * used to indicate (a) whether this DSO structure corresponds to a
58      * loaded library or not, and (b) the filename with which it was actually
59      * loaded.
60      */
61     char *loaded_filename;
62     CRYPTO_RWLOCK *lock;
63 };
64
65 struct dso_meth_st {
66     const char *name;
67     /*
68      * Loads a shared library, NB: new DSO_METHODs must ensure that a
69      * successful load populates the loaded_filename field, and likewise a
70      * successful unload OPENSSL_frees and NULLs it out.
71      */
72     int (*dso_load) (DSO *dso);
73     /* Unloads a shared library */
74     int (*dso_unload) (DSO *dso);
75     /*
76      * Binds a function - assumes a return type of DSO_FUNC_TYPE. This should
77      * be cast to the real function prototype by the caller. Platforms that
78      * don't have compatible representations for different prototypes (this
79      * is possible within ANSI C) are highly unlikely to have shared
80      * libraries at all, let alone a DSO_METHOD implemented for them.
81      */
82     DSO_FUNC_TYPE (*dso_bind_func) (DSO *dso, const char *symname);
83     /*
84      * The generic (yuck) "ctrl()" function. NB: Negative return values
85      * (rather than zero) indicate errors.
86      */
87     long (*dso_ctrl) (DSO *dso, int cmd, long larg, void *parg);
88     /*
89      * The default DSO_METHOD-specific function for converting filenames to a
90      * canonical native form.
91      */
92     DSO_NAME_CONVERTER_FUNC dso_name_converter;
93     /*
94      * The default DSO_METHOD-specific function for converting filenames to a
95      * canonical native form.
96      */
97     DSO_MERGER_FUNC dso_merger;
98     /* [De]Initialisation handlers. */
99     int (*init) (DSO *dso);
100     int (*finish) (DSO *dso);
101     /* Perform global symbol lookup, i.e. among *all* modules */
102     void *(*globallookup) (const char *symname);
103 };