1 /* loader-load_add_on.c -- dynamic linking for BeOS
3 Copyright (C) 1998, 1999, 2000, 2004, 2006,
4 2007, 2008 Free Software Foundation, Inc.
5 Written by Thomas Tanner, 1998
7 NOTE: The canonical source of this file is maintained with the
8 GNU Libtool package. Report bugs to bug-libtool@gnu.org.
10 GNU Libltdl is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 As a special exception to the GNU Lesser General Public License,
16 if you distribute this file as part of a program or library that
17 is built using GNU Libtool, you may include this file under the
18 same distribution terms that you use for the rest of that program.
20 GNU Libltdl is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public
26 License along with GNU Libltdl; see the file COPYING.LIB. If not, a
27 copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
28 or obtained by writing to the Free Software Foundation, Inc.,
29 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include "lt__private.h"
33 #include "lt_dlloader.h"
35 /* Use the preprocessor to rename non-static symbols to avoid namespace
36 collisions when the loader code is statically linked into libltdl.
37 Use the "<module_name>_LTX_" prefix so that the symbol addresses can
38 be fetched from the preloaded symbol list by lt_dlsym(): */
39 #define get_vtable load_add_on_LTX_get_vtable
42 LT_SCOPE lt_dlvtable
*get_vtable (lt_user_data loader_data
);
46 /* Boilerplate code to set up the vtable for hooking this loader into
47 libltdl's loader list: */
48 static int vl_exit (lt_user_data loader_data
);
49 static lt_module
vm_open (lt_user_data loader_data
, const char *filename
,
51 static int vm_close (lt_user_data loader_data
, lt_module module
);
52 static void * vm_sym (lt_user_data loader_data
, lt_module module
,
53 const char *symbolname
);
55 static lt_dlvtable
*vtable
= 0;
57 /* Return the vtable for this loader, only the name and sym_prefix
58 attributes (plus the virtual function implementations, obviously)
59 change between loaders. */
61 get_vtable (lt_user_data loader_data
)
65 vtable
= lt__zalloc (sizeof *vtable
);
68 if (vtable
&& !vtable
->name
)
70 vtable
->name
= "lt_load_add_on";
71 vtable
->module_open
= vm_open
;
72 vtable
->module_close
= vm_close
;
73 vtable
->find_sym
= vm_sym
;
74 vtable
->dlloader_exit
= vl_exit
;
75 vtable
->dlloader_data
= loader_data
;
76 vtable
->priority
= LT_DLLOADER_APPEND
;
79 if (vtable
&& (vtable
->dlloader_data
!= loader_data
))
81 LT__SETERROR (INIT_LOADER
);
90 /* --- IMPLEMENTATION --- */
93 #include <kernel/image.h>
95 /* A function called through the vtable when this loader is no
96 longer needed by the application. */
98 vl_exit (lt_user_data LT__UNUSED loader_data
)
104 /* A function called through the vtable to open a module with this
105 loader. Returns an opaque representation of the newly opened
106 module for processing with this loader's other vtable functions. */
108 vm_open (lt_user_data LT__UNUSED loader_data
, const char *filename
,
109 lt_dladvise LT__UNUSED advise
)
115 image
= load_add_on (filename
);
121 if (get_next_image_info (0, &cookie
, &info
) == B_OK
)
122 image
= load_add_on (info
.name
);
127 LT__SETERROR (CANNOT_OPEN
);
131 return (lt_module
) image
;
135 /* A function called through the vtable when a particular module
136 should be unloaded. */
138 vm_close (lt_user_data LT__UNUSED loader_data
, lt_module module
)
142 if (unload_add_on ((image_id
) module
) != B_OK
)
144 LT__SETERROR (CANNOT_CLOSE
);
152 /* A function called through the vtable to get the address of
153 a symbol loaded from a particular module. */
155 vm_sym (lt_user_data LT__UNUSED loader_data
, lt_module module
, const char *name
)
158 image_id image
= (image_id
) module
;
160 if (get_image_symbol (image
, name
, B_SYMBOL_TYPE_ANY
, address
) != B_OK
)
162 LT__SETERROR (SYMBOL_NOT_FOUND
);