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