3 * Written by Marcin Konicki (ahwayakchih@neoni.net) for the OpenSSL project
6 /* ====================================================================
7 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
35 * 6. Redistributions of any form whatsoever must retain the following
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
63 #include <openssl/dso.h>
65 #if !defined(OPENSSL_SYS_BEOS)
66 DSO_METHOD *DSO_METHOD_beos(void)
72 # include <kernel/image.h>
74 static int beos_load(DSO *dso);
75 static int beos_unload(DSO *dso);
76 static void *beos_bind_var(DSO *dso, const char *symname);
77 static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname);
79 static int beos_unbind_var(DSO *dso, char *symname, void *symptr);
80 static int beos_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
81 static int beos_init(DSO *dso);
82 static int beos_finish(DSO *dso);
83 static long beos_ctrl(DSO *dso, int cmd, long larg, void *parg);
85 static char *beos_name_converter(DSO *dso, const char *filename);
87 static DSO_METHOD dso_meth_beos = {
88 "OpenSSL 'beos' shared library method",
93 /* For now, "unbind" doesn't exist */
95 NULL, /* unbind_var */
96 NULL, /* unbind_func */
104 DSO_METHOD *DSO_METHOD_beos(void)
106 return (&dso_meth_beos);
110 * For this DSO_METHOD, our meth_data STACK will contain; (i) a pointer to
111 * the handle (image_id) returned from load_add_on().
114 static int beos_load(DSO *dso)
117 /* See applicable comments from dso_dl.c */
118 char *filename = DSO_convert_filename(dso, NULL);
120 if (filename == NULL) {
121 DSOerr(DSO_F_BEOS_LOAD, DSO_R_NO_FILENAME);
124 id = load_add_on(filename);
126 DSOerr(DSO_F_BEOS_LOAD, DSO_R_LOAD_FAILED);
127 ERR_add_error_data(3, "filename(", filename, ")");
130 if (!sk_push(dso->meth_data, (char *)id)) {
131 DSOerr(DSO_F_BEOS_LOAD, DSO_R_STACK_ERROR);
135 dso->loaded_filename = filename;
139 if (filename != NULL)
140 OPENSSL_free(filename);
146 static int beos_unload(DSO *dso)
150 DSOerr(DSO_F_BEOS_UNLOAD, ERR_R_PASSED_NULL_PARAMETER);
153 if (sk_num(dso->meth_data) < 1)
155 id = (image_id) sk_pop(dso->meth_data);
157 DSOerr(DSO_F_BEOS_UNLOAD, DSO_R_NULL_HANDLE);
160 if (unload_add_on(id) != B_OK) {
161 DSOerr(DSO_F_BEOS_UNLOAD, DSO_R_UNLOAD_FAILED);
163 * We should push the value back onto the stack in case of a retry.
165 sk_push(dso->meth_data, (char *)id);
171 static void *beos_bind_var(DSO *dso, const char *symname)
176 if ((dso == NULL) || (symname == NULL)) {
177 DSOerr(DSO_F_BEOS_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER);
180 if (sk_num(dso->meth_data) < 1) {
181 DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_STACK_ERROR);
184 id = (image_id) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
186 DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_NULL_HANDLE);
189 if (get_image_symbol(id, symname, B_SYMBOL_TYPE_DATA, &sym) != B_OK) {
190 DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_SYM_FAILURE);
191 ERR_add_error_data(3, "symname(", symname, ")");
197 static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname)
202 if ((dso == NULL) || (symname == NULL)) {
203 DSOerr(DSO_F_BEOS_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
206 if (sk_num(dso->meth_data) < 1) {
207 DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_STACK_ERROR);
210 id = (image_id) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
212 DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_NULL_HANDLE);
215 if (get_image_symbol(id, symname, B_SYMBOL_TYPE_TEXT, &sym) != B_OK) {
216 DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_SYM_FAILURE);
217 ERR_add_error_data(3, "symname(", symname, ")");
220 return ((DSO_FUNC_TYPE)sym);
223 /* This one is the same as the one in dlfcn */
224 static char *beos_name_converter(DSO *dso, const char *filename)
227 int len, rsize, transform;
229 len = strlen(filename);
231 transform = (strstr(filename, "/") == NULL);
233 /* We will convert this to "%s.so" or "lib%s.so" */
234 rsize += 3; /* The length of ".so" */
235 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
236 rsize += 3; /* The length of "lib" */
238 translated = OPENSSL_malloc(rsize);
239 if (translated == NULL) {
240 DSOerr(DSO_F_BEOS_NAME_CONVERTER, DSO_R_NAME_TRANSLATION_FAILED);
244 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
245 sprintf(translated, "lib%s.so", filename);
247 sprintf(translated, "%s.so", filename);
249 sprintf(translated, "%s", filename);