dso_locl.h 4.1 KB

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