1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
42 ** API to static and dynamic linking.
48 typedef struct PRLibrary PRLibrary;
50 typedef struct PRStaticLinkTable {
56 ** Change the default library path to the given string. The string is
57 ** copied. This call will fail if it runs out of memory.
59 ** The string provided as 'path' is copied. The caller can do whatever is
60 ** convenient with the argument when the function is complete.
62 NSPR_API(PRStatus) PR_SetLibraryPath(const char *path);
65 ** Return a character string which contains the path used to search for
66 ** dynamically loadable libraries.
68 ** The returned value is basically a copy of a PR_SetLibraryPath().
69 ** The storage is allocated by the runtime and becomes the responsibilty
72 NSPR_API(char*) PR_GetLibraryPath(void);
75 ** Given a directory name "dir" and a library name "lib" construct a full
76 ** path name that will refer to the actual dynamically loaded
77 ** library. This does not test for existance of said file, it just
78 ** constructs the full filename. The name constructed is system dependent
79 ** and prepared for PR_LoadLibrary. The result must be free'd when the
80 ** caller is done with it.
82 ** The storage for the result is allocated by the runtime and becomes the
83 ** responsibility of the caller.
85 NSPR_API(char*) PR_GetLibraryName(const char *dir, const char *lib);
89 ** Free the memory allocated, for the caller, by PR_GetLibraryName
91 NSPR_API(void) PR_FreeLibraryName(char *mem);
94 ** Given a library "name" try to load the library. The argument "name"
95 ** is a machine-dependent name for the library, such as the full pathname
96 ** returned by PR_GetLibraryName. If the library is already loaded,
97 ** this function will avoid loading the library twice.
99 ** If the library is loaded successfully, then a pointer to the PRLibrary
100 ** structure representing the library is returned. Otherwise, NULL is
103 ** This increments the reference count of the library.
105 NSPR_API(PRLibrary*) PR_LoadLibrary(const char *name);
108 ** Each operating system has its preferred way of specifying
109 ** a file in the file system. Most operating systems use
110 ** a pathname. Mac OS Classic, on the other hand, uses the FSSpec
111 ** structure to specify a file. PRLibSpec allows NSPR clients
112 ** to use the type of file specification that is most efficient
113 ** for a particular platform.
115 ** On some operating systems such as Mac OS Classic, a shared library
116 ** may contain code fragments that can be individually loaded.
117 ** PRLibSpec also allows NSPR clients to identify a code fragment
118 ** in a library, if code fragments are supported by the OS.
119 ** A code fragment can be specified by name or by an integer index.
121 ** Right now PRLibSpec supports four types of library specification:
122 ** a pathname in the native character encoding, a Mac code fragment
123 ** by name, a Mac code fragment by index, and a UTF-16 pathname.
126 typedef enum PRLibSpecType {
128 PR_LibSpec_MacNamedFragment, /* obsolete (for Mac OS Classic) */
129 PR_LibSpec_MacIndexedFragment, /* obsolete (for Mac OS Classic) */
130 PR_LibSpec_PathnameU /* supported only on Win32 */
133 struct FSSpec; /* Mac OS Classic FSSpec */
135 typedef struct PRLibSpec {
138 /* if type is PR_LibSpec_Pathname */
139 const char *pathname;
141 /* if type is PR_LibSpec_MacNamedFragment */
143 const struct FSSpec *fsspec;
145 } mac_named_fragment; /* obsolete (for Mac OS Classic) */
147 /* if type is PR_LibSpec_MacIndexedFragment */
149 const struct FSSpec *fsspec;
151 } mac_indexed_fragment; /* obsolete (for Mac OS Classic) */
153 /* if type is PR_LibSpec_PathnameU */
154 const PRUnichar *pathname_u; /* supported only on Win32 */
159 ** The following bit flags may be or'd together and passed
160 ** as the 'flags' argument to PR_LoadLibraryWithFlags.
161 ** Flags not supported by the underlying OS are ignored.
164 #define PR_LD_LAZY 0x1 /* equivalent to RTLD_LAZY on Unix */
165 #define PR_LD_NOW 0x2 /* equivalent to RTLD_NOW on Unix */
166 #define PR_LD_GLOBAL 0x4 /* equivalent to RTLD_GLOBAL on Unix */
167 #define PR_LD_LOCAL 0x8 /* equivalent to RTLD_LOCAL on Unix */
168 /* The following is equivalent to LOAD_WITH_ALTERED_SEARCH_PATH on Windows */
169 #define PR_LD_ALT_SEARCH_PATH 0x10
170 /* 0x8000 reserved for NSPR internal use */
173 ** Load the specified library, in the manner specified by 'flags'.
176 NSPR_API(PRLibrary *)
177 PR_LoadLibraryWithFlags(
178 PRLibSpec libSpec, /* the shared library */
179 PRIntn flags /* flags that affect the loading */
183 ** Unload a previously loaded library. If the library was a static
184 ** library then the static link table will no longer be referenced. The
185 ** associated PRLibrary object is freed.
187 ** PR_FAILURE is returned if the library cannot be unloaded.
189 ** This function decrements the reference count of the library.
191 NSPR_API(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
194 ** Given the name of a procedure, return the address of the function that
195 ** implements the procedure, or NULL if no such function can be
196 ** found. This does not find symbols in the main program (the ".exe");
197 ** use PR_LoadStaticLibrary to register symbols in the main program.
199 ** This function does not modify the reference count of the library.
201 NSPR_API(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
204 ** Similar to PR_FindSymbol, except that the return value is a pointer to
205 ** a function, and not a pointer to void. Casting between a data pointer
206 ** and a function pointer is not portable according to the C standard.
207 ** Any function pointer can be cast to any other function pointer.
209 ** This function does not modify the reference count of the library.
211 typedef void (*PRFuncPtr)(void);
212 NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
215 ** Finds a symbol in one of the currently loaded libraries. Given the
216 ** name of a procedure, return the address of the function that
217 ** implements the procedure, and return the library that contains that
218 ** symbol, or NULL if no such function can be found. This does not find
219 ** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
220 ** register symbols in the main program.
222 ** This increments the reference count of the library.
224 NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
228 ** Similar to PR_FindSymbolAndLibrary, except that the return value is
229 ** a pointer to a function, and not a pointer to void. Casting between a
230 ** data pointer and a function pointer is not portable according to the C
231 ** standard. Any function pointer can be cast to any other function pointer.
233 ** This increments the reference count of the library.
235 NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
239 ** Register a static link table with the runtime under the name
240 ** "name". The symbols present in the static link table will be made
241 ** available to PR_FindSymbol. If "name" is null then the symbols will be
242 ** made available to the library which represents the executable. The
243 ** tables are not copied.
245 ** Returns the library object if successful, null otherwise.
247 ** This increments the reference count of the library.
249 NSPR_API(PRLibrary*) PR_LoadStaticLibrary(
250 const char *name, const PRStaticLinkTable *table);
253 ** Return the pathname of the file that the library "name" was loaded
254 ** from. "addr" is the address of a function defined in the library.
256 ** The caller is responsible for freeing the result with PR_Free.
258 NSPR_API(char *) PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr);
262 #endif /* prlink_h___ */