2
0

dso.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_arch_dso.h"
  17. #include "apr_portable.h"
  18. #if APR_HAS_DSO
  19. static apr_status_t dso_cleanup(void *thedso)
  20. {
  21. apr_dso_handle_t *dso = thedso;
  22. if (dso->handle > 0 && unload_add_on(dso->handle) < B_NO_ERROR)
  23. return APR_EINIT;
  24. dso->handle = -1;
  25. return APR_SUCCESS;
  26. }
  27. APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
  28. const char *path, apr_pool_t *pool)
  29. {
  30. image_id newid = -1;
  31. *res_handle = apr_pcalloc(pool, sizeof(*res_handle));
  32. if((newid = load_add_on(path)) < B_NO_ERROR) {
  33. (*res_handle)->errormsg = strerror(newid);
  34. return APR_EDSOOPEN;
  35. }
  36. (*res_handle)->pool = pool;
  37. (*res_handle)->handle = newid;
  38. apr_pool_cleanup_register(pool, *res_handle, dso_cleanup, apr_pool_cleanup_null);
  39. return APR_SUCCESS;
  40. }
  41. APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
  42. {
  43. return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
  44. }
  45. APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym, apr_dso_handle_t *handle,
  46. const char *symname)
  47. {
  48. int err;
  49. if (symname == NULL)
  50. return APR_ESYMNOTFOUND;
  51. err = get_image_symbol(handle->handle, symname, B_SYMBOL_TYPE_ANY,
  52. ressym);
  53. if(err != B_OK)
  54. return APR_ESYMNOTFOUND;
  55. return APR_SUCCESS;
  56. }
  57. APR_DECLARE(const char *) apr_dso_error(apr_dso_handle_t *dso, char *buffer, apr_size_t buflen)
  58. {
  59. strncpy(buffer, strerror(errno), buflen);
  60. return buffer;
  61. }
  62. APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **aprdso,
  63. apr_os_dso_handle_t osdso,
  64. apr_pool_t *pool)
  65. {
  66. *aprdso = apr_pcalloc(pool, sizeof **aprdso);
  67. (*aprdso)->handle = osdso;
  68. (*aprdso)->pool = pool;
  69. return APR_SUCCESS;
  70. }
  71. APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *osdso,
  72. apr_dso_handle_t *aprdso)
  73. {
  74. *osdso = aprdso->handle;
  75. return APR_SUCCESS;
  76. }
  77. #endif