VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prlink.h@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
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
4 *
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/
9 *
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
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
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.
21 *
22 * Contributor(s):
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef prlink_h___
39#define prlink_h___
40
41/*
42** API to static and dynamic linking.
43*/
44#include "prtypes.h"
45
46PR_BEGIN_EXTERN_C
47
48typedef struct PRLibrary PRLibrary;
49
50typedef struct PRStaticLinkTable {
51 const char *name;
52 void (*fp)();
53} PRStaticLinkTable;
54
55/*
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.
58**
59** The string provided as 'path' is copied. The caller can do whatever is
60** convenient with the argument when the function is complete.
61*/
62NSPR_API(PRStatus) PR_SetLibraryPath(const char *path);
63
64/*
65** Return a character string which contains the path used to search for
66** dynamically loadable libraries.
67**
68** The returned value is basically a copy of a PR_SetLibraryPath().
69** The storage is allocated by the runtime and becomes the responsibilty
70** of the caller.
71*/
72NSPR_API(char*) PR_GetLibraryPath(void);
73
74/*
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.
81**
82** The storage for the result is allocated by the runtime and becomes the
83** responsibility of the caller.
84*/
85NSPR_API(char*) PR_GetLibraryName(const char *dir, const char *lib);
86
87/*
88**
89** Free the memory allocated, for the caller, by PR_GetLibraryName
90*/
91NSPR_API(void) PR_FreeLibraryName(char *mem);
92
93/*
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.
98**
99** If the library is loaded successfully, then a pointer to the PRLibrary
100** structure representing the library is returned. Otherwise, NULL is
101** returned.
102**
103** This increments the reference count of the library.
104*/
105NSPR_API(PRLibrary*) PR_LoadLibrary(const char *name);
106
107/*
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, 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.
114**
115** On some operating systems such as Mac OS, a shared library may
116** 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.
120**
121** Right now PRLibSpec supports three types of library specification:
122** a pathname, a Mac code fragment by name, and a Mac code fragment
123** by index.
124*/
125
126typedef enum PRLibSpecType {
127 PR_LibSpec_Pathname,
128 PR_LibSpec_MacNamedFragment,
129 PR_LibSpec_MacIndexedFragment
130} PRLibSpecType;
131
132struct FSSpec; /* Mac OS FSSpec */
133
134typedef struct PRLibSpec {
135 PRLibSpecType type;
136 union {
137 /* if type is PR_LibSpec_Pathname */
138 const char *pathname;
139
140 /* if type is PR_LibSpec_MacNamedFragment */
141 struct {
142 const struct FSSpec *fsspec;
143 const char *name;
144 } mac_named_fragment;
145
146 /* if type is PR_LibSpec_MacIndexedFragment */
147 struct {
148 const struct FSSpec *fsspec;
149 PRUint32 index;
150 } mac_indexed_fragment;
151 } value;
152} PRLibSpec;
153
154/*
155** The following bit flags may be or'd together and passed
156** as the 'flags' argument to PR_LoadLibraryWithFlags.
157** Flags not supported by the underlying OS are ignored.
158*/
159
160#define PR_LD_LAZY 0x1 /* equivalent to RTLD_LAZY on Unix */
161#define PR_LD_NOW 0x2 /* equivalent to RTLD_NOW on Unix */
162#define PR_LD_GLOBAL 0x4 /* equivalent to RTLD_GLOBAL on Unix */
163#define PR_LD_LOCAL 0x8 /* equivalent to RTLD_LOCAL on Unix */
164
165/*
166** Load the specified library, in the manner specified by 'flags'.
167*/
168
169NSPR_API(PRLibrary *)
170PR_LoadLibraryWithFlags(
171 PRLibSpec libSpec, /* the shared library */
172 PRIntn flags /* flags that affect the loading */
173);
174
175/*
176** Unload a previously loaded library. If the library was a static
177** library then the static link table will no longer be referenced. The
178** associated PRLibrary object is freed.
179**
180** PR_FAILURE is returned if the library cannot be unloaded.
181**
182** This function decrements the reference count of the library.
183*/
184NSPR_API(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
185
186/*
187** Given the name of a procedure, return the address of the function that
188** implements the procedure, or NULL if no such function can be
189** found. This does not find symbols in the main program (the ".exe");
190** use PR_LoadStaticLibrary to register symbols in the main program.
191**
192** This function does not modify the reference count of the library.
193*/
194NSPR_API(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
195
196/*
197** Similar to PR_FindSymbol, except that the return value is a pointer to
198** a function, and not a pointer to void. Casting between a data pointer
199** and a function pointer is not portable according to the C standard.
200** Any function pointer can be cast to any other function pointer.
201**
202** This function does not modify the reference count of the library.
203*/
204typedef void (*PRFuncPtr)();
205NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
206
207/*
208** Finds a symbol in one of the currently loaded libraries. Given the
209** name of a procedure, return the address of the function that
210** implements the procedure, and return the library that contains that
211** symbol, or NULL if no such function can be found. This does not find
212** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
213** register symbols in the main program.
214**
215** This increments the reference count of the library.
216*/
217NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
218 PRLibrary* *lib);
219
220/*
221** Similar to PR_FindSymbolAndLibrary, except that the return value is
222** a pointer to a function, and not a pointer to void. Casting between a
223** data pointer and a function pointer is not portable according to the C
224** standard. Any function pointer can be cast to any other function pointer.
225**
226** This increments the reference count of the library.
227*/
228NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
229 PRLibrary* *lib);
230
231/*
232** Register a static link table with the runtime under the name
233** "name". The symbols present in the static link table will be made
234** available to PR_FindSymbol. If "name" is null then the symbols will be
235** made available to the library which represents the executable. The
236** tables are not copied.
237**
238** Returns the library object if successful, null otherwise.
239**
240** This increments the reference count of the library.
241*/
242NSPR_API(PRLibrary*) PR_LoadStaticLibrary(
243 const char *name, const PRStaticLinkTable *table);
244
245/*
246** Return the pathname of the file that the library "name" was loaded
247** from. "addr" is the address of a function defined in the library.
248**
249** The caller is responsible for freeing the result with PR_Free.
250*/
251NSPR_API(char *) PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr);
252
253PR_END_EXTERN_C
254
255#endif /* prlink_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette