2
0

dso.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "apr_portable.h"
  17. #include "apr_strings.h"
  18. #include "apr_arch_dso.h"
  19. #include <errno.h>
  20. #include <string.h>
  21. #if APR_HAS_DSO
  22. APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **aprdso,
  23. apr_os_dso_handle_t osdso,
  24. apr_pool_t *pool)
  25. {
  26. *aprdso = apr_pcalloc(pool, sizeof **aprdso);
  27. (*aprdso)->handle = osdso;
  28. (*aprdso)->pool = pool;
  29. return APR_SUCCESS;
  30. }
  31. APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *osdso,
  32. apr_dso_handle_t *aprdso)
  33. {
  34. *osdso = aprdso->handle;
  35. return APR_SUCCESS;
  36. }
  37. static apr_status_t dso_cleanup(void *thedso)
  38. {
  39. apr_dso_handle_t *dso = thedso;
  40. int rc;
  41. if (dso->handle == 0)
  42. return APR_SUCCESS;
  43. rc = dllfree(dso->handle);
  44. if (rc == 0) {
  45. dso->handle = 0;
  46. return APR_SUCCESS;
  47. }
  48. dso->failing_errno = errno;
  49. return errno;
  50. }
  51. APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
  52. const char *path, apr_pool_t *ctx)
  53. {
  54. dllhandle *handle;
  55. int rc;
  56. *res_handle = apr_pcalloc(ctx, sizeof(*res_handle));
  57. (*res_handle)->pool = ctx;
  58. if ((handle = dllload(path)) != NULL) {
  59. (*res_handle)->handle = handle;
  60. apr_pool_cleanup_register(ctx, *res_handle, dso_cleanup, apr_pool_cleanup_null);
  61. return APR_SUCCESS;
  62. }
  63. (*res_handle)->failing_errno = errno;
  64. return errno;
  65. }
  66. APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
  67. {
  68. return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
  69. }
  70. APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym,
  71. apr_dso_handle_t *handle,
  72. const char *symname)
  73. {
  74. void *func_ptr;
  75. void *var_ptr;
  76. if ((var_ptr = dllqueryvar(handle->handle, symname)) != NULL) {
  77. *ressym = var_ptr;
  78. return APR_SUCCESS;
  79. }
  80. if ((func_ptr = (void *)dllqueryfn(handle->handle, symname)) != NULL) {
  81. *ressym = func_ptr;
  82. return APR_SUCCESS;
  83. }
  84. handle->failing_errno = errno;
  85. return errno;
  86. }
  87. APR_DECLARE(const char *) apr_dso_error(apr_dso_handle_t *handle, char *buffer,
  88. apr_size_t buflen)
  89. {
  90. apr_cpystrn(buffer, strerror(handle->failing_errno), buflen);
  91. return buffer;
  92. }
  93. #endif