2
0

dso.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "fspr_arch_dso.h"
  17. #include "fspr_strings.h"
  18. #include "fspr_portable.h"
  19. #include <stdio.h>
  20. #include <string.h>
  21. #if APR_HAS_DSO
  22. static fspr_status_t dso_cleanup(void *thedso)
  23. {
  24. fspr_dso_handle_t *dso = thedso;
  25. int rc;
  26. if (dso->handle == 0)
  27. return APR_SUCCESS;
  28. rc = DosFreeModule(dso->handle);
  29. if (rc == 0)
  30. dso->handle = 0;
  31. return APR_FROM_OS_ERROR(rc);
  32. }
  33. APR_DECLARE(fspr_status_t) fspr_dso_load(fspr_dso_handle_t **res_handle, const char *path, fspr_pool_t *ctx)
  34. {
  35. char failed_module[200];
  36. HMODULE handle;
  37. int rc;
  38. *res_handle = fspr_pcalloc(ctx, sizeof(**res_handle));
  39. (*res_handle)->cont = ctx;
  40. (*res_handle)->load_error = APR_SUCCESS;
  41. (*res_handle)->failed_module = NULL;
  42. if ((rc = DosLoadModule(failed_module, sizeof(failed_module), path, &handle)) != 0) {
  43. (*res_handle)->load_error = APR_FROM_OS_ERROR(rc);
  44. (*res_handle)->failed_module = fspr_pstrdup(ctx, failed_module);
  45. return APR_FROM_OS_ERROR(rc);
  46. }
  47. (*res_handle)->handle = handle;
  48. fspr_pool_cleanup_register(ctx, *res_handle, dso_cleanup, fspr_pool_cleanup_null);
  49. return APR_SUCCESS;
  50. }
  51. APR_DECLARE(fspr_status_t) fspr_dso_unload(fspr_dso_handle_t *handle)
  52. {
  53. return fspr_pool_cleanup_run(handle->cont, handle, dso_cleanup);
  54. }
  55. APR_DECLARE(fspr_status_t) fspr_dso_sym(fspr_dso_handle_sym_t *ressym,
  56. fspr_dso_handle_t *handle,
  57. const char *symname)
  58. {
  59. PFN func;
  60. int rc;
  61. if (symname == NULL || ressym == NULL)
  62. return APR_ESYMNOTFOUND;
  63. if ((rc = DosQueryProcAddr(handle->handle, 0, symname, &func)) != 0) {
  64. handle->load_error = APR_FROM_OS_ERROR(rc);
  65. return handle->load_error;
  66. }
  67. *ressym = func;
  68. return APR_SUCCESS;
  69. }
  70. APR_DECLARE(const char *) fspr_dso_error(fspr_dso_handle_t *dso, char *buffer, fspr_size_t buflen)
  71. {
  72. char message[200];
  73. fspr_strerror(dso->load_error, message, sizeof(message));
  74. if (dso->failed_module != NULL) {
  75. strcat(message, " (");
  76. strcat(message, dso->failed_module);
  77. strcat(message, ")");
  78. }
  79. fspr_cpystrn(buffer, message, buflen);
  80. return buffer;
  81. }
  82. APR_DECLARE(fspr_status_t) fspr_os_dso_handle_put(fspr_dso_handle_t **aprdso,
  83. fspr_os_dso_handle_t osdso,
  84. fspr_pool_t *pool)
  85. {
  86. *aprdso = fspr_pcalloc(pool, sizeof **aprdso);
  87. (*aprdso)->handle = osdso;
  88. (*aprdso)->cont = pool;
  89. (*aprdso)->load_error = APR_SUCCESS;
  90. (*aprdso)->failed_module = NULL;
  91. return APR_SUCCESS;
  92. }
  93. APR_DECLARE(fspr_status_t) fspr_os_dso_handle_get(fspr_os_dso_handle_t *osdso,
  94. fspr_dso_handle_t *aprdso)
  95. {
  96. *osdso = aprdso->handle;
  97. return APR_SUCCESS;
  98. }
  99. #endif