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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "apr_arch_dso.h"
18 #include "apr_strings.h"
19 #include "apr_portable.h"
24 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **aprdso,
25 apr_os_dso_handle_t osdso,
28 *aprdso = apr_pcalloc(pool, sizeof **aprdso);
29 (*aprdso)->handle = osdso;
30 (*aprdso)->pool = pool;
34 APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *osdso,
35 apr_dso_handle_t *aprdso)
37 *osdso = aprdso->handle;
41 static apr_status_t dso_cleanup(void *thedso)
43 apr_dso_handle_t *dso = thedso;
44 sym_list *symbol = NULL;
45 void *NLMHandle = getnlmhandle();
47 if (dso->handle == NULL)
50 if (dso->symbols != NULL) {
51 symbol = dso->symbols;
53 UnImportPublicObject(NLMHandle, symbol->symbol);
54 symbol = symbol->next;
58 if (dlclose(dso->handle) != 0)
68 APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
69 const char *path, apr_pool_t *pool)
72 void *os_handle = NULL;
73 char *fullpath = NULL;
76 if ((rv = apr_filepath_merge(&fullpath, NULL, path,
77 APR_FILEPATH_NATIVE, pool)) != APR_SUCCESS) {
81 os_handle = dlopen(fullpath, RTLD_NOW | RTLD_LOCAL);
83 *res_handle = apr_pcalloc(pool, sizeof(**res_handle));
85 if(os_handle == NULL) {
86 (*res_handle)->errormsg = dlerror();
90 (*res_handle)->handle = (void*)os_handle;
91 (*res_handle)->pool = pool;
92 (*res_handle)->errormsg = NULL;
93 (*res_handle)->symbols = NULL;
94 (*res_handle)->path = apr_pstrdup(pool, fullpath);
96 apr_pool_cleanup_register(pool, *res_handle, dso_cleanup, apr_pool_cleanup_null);
101 APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
103 return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
106 APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym,
107 apr_dso_handle_t *handle,
110 sym_list *symbol = NULL;
111 void *retval = dlsym(handle->handle, symname);
113 if (retval == NULL) {
114 handle->errormsg = dlerror();
115 return APR_ESYMNOTFOUND;
118 symbol = apr_pcalloc(handle->pool, sizeof(sym_list));
119 symbol->next = handle->symbols;
120 handle->symbols = symbol;
121 symbol->symbol = apr_pstrdup(handle->pool, symname);
128 APR_DECLARE(const char *) apr_dso_error(apr_dso_handle_t *dso, char *buffer,
132 apr_cpystrn(buffer, dso->errormsg, buflen);
133 return dso->errormsg;