VirtualBox

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

最後變更 在這個檔案從22683是 11551,由 vboxsync 提交於 16 年 前

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.9 KB
 
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
46#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
47#define PR_SetLibraryPath VBoxNsprPR_SetLibraryPath
48#define PR_GetLibraryPath VBoxNsprPR_GetLibraryPath
49#define PR_GetLibraryName VBoxNsprPR_GetLibraryName
50#define PR_FreeLibraryName VBoxNsprPR_FreeLibraryName
51#define PR_LoadLibrary VBoxNsprPR_LoadLibrary
52#define PR_LoadLibraryWithFlags VBoxNsprPR_LoadLibraryWithFlags
53#define PR_UnloadLibrary VBoxNsprPR_UnloadLibrary
54#define PR_FindSymbol VBoxNsprPR_FindSymbol
55#define PR_FindFunctionSymbol VBoxNsprPR_FindFunctionSymbol
56#define PR_FindSymbolAndLibrary VBoxNsprPR_FindSymbolAndLibrary
57#define PR_FindFunctionSymbolAndLibrary VBoxNsprPR_FindFunctionSymbolAndLibrary
58#define PR_LoadStaticLibrary VBoxNsprPR_LoadStaticLibrary
59#define PR_GetLibraryFilePathname VBoxNsprPR_GetLibraryFilePathname
60#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
61
62PR_BEGIN_EXTERN_C
63
64typedef struct PRLibrary PRLibrary;
65
66typedef struct PRStaticLinkTable {
67 const char *name;
68 void (*fp)();
69} PRStaticLinkTable;
70
71/*
72** Change the default library path to the given string. The string is
73** copied. This call will fail if it runs out of memory.
74**
75** The string provided as 'path' is copied. The caller can do whatever is
76** convenient with the argument when the function is complete.
77*/
78NSPR_API(PRStatus) PR_SetLibraryPath(const char *path);
79
80/*
81** Return a character string which contains the path used to search for
82** dynamically loadable libraries.
83**
84** The returned value is basically a copy of a PR_SetLibraryPath().
85** The storage is allocated by the runtime and becomes the responsibilty
86** of the caller.
87*/
88NSPR_API(char*) PR_GetLibraryPath(void);
89
90/*
91** Given a directory name "dir" and a library name "lib" construct a full
92** path name that will refer to the actual dynamically loaded
93** library. This does not test for existance of said file, it just
94** constructs the full filename. The name constructed is system dependent
95** and prepared for PR_LoadLibrary. The result must be free'd when the
96** caller is done with it.
97**
98** The storage for the result is allocated by the runtime and becomes the
99** responsibility of the caller.
100*/
101NSPR_API(char*) PR_GetLibraryName(const char *dir, const char *lib);
102
103/*
104**
105** Free the memory allocated, for the caller, by PR_GetLibraryName
106*/
107NSPR_API(void) PR_FreeLibraryName(char *mem);
108
109/*
110** Given a library "name" try to load the library. The argument "name"
111** is a machine-dependent name for the library, such as the full pathname
112** returned by PR_GetLibraryName. If the library is already loaded,
113** this function will avoid loading the library twice.
114**
115** If the library is loaded successfully, then a pointer to the PRLibrary
116** structure representing the library is returned. Otherwise, NULL is
117** returned.
118**
119** This increments the reference count of the library.
120*/
121NSPR_API(PRLibrary*) PR_LoadLibrary(const char *name);
122
123/*
124** Each operating system has its preferred way of specifying
125** a file in the file system. Most operating systems use
126** a pathname. Mac OS, on the other hand, uses the FSSpec
127** structure to specify a file. PRLibSpec allows NSPR clients
128** to use the type of file specification that is most efficient
129** for a particular platform.
130**
131** On some operating systems such as Mac OS, a shared library may
132** contain code fragments that can be individually loaded.
133** PRLibSpec also allows NSPR clients to identify a code fragment
134** in a library, if code fragments are supported by the OS.
135** A code fragment can be specified by name or by an integer index.
136**
137** Right now PRLibSpec supports three types of library specification:
138** a pathname, a Mac code fragment by name, and a Mac code fragment
139** by index.
140*/
141
142typedef enum PRLibSpecType {
143 PR_LibSpec_Pathname,
144 PR_LibSpec_MacNamedFragment,
145 PR_LibSpec_MacIndexedFragment
146} PRLibSpecType;
147
148struct FSSpec; /* Mac OS FSSpec */
149
150typedef struct PRLibSpec {
151 PRLibSpecType type;
152 union {
153 /* if type is PR_LibSpec_Pathname */
154 const char *pathname;
155
156 /* if type is PR_LibSpec_MacNamedFragment */
157 struct {
158 const struct FSSpec *fsspec;
159 const char *name;
160 } mac_named_fragment;
161
162 /* if type is PR_LibSpec_MacIndexedFragment */
163 struct {
164 const struct FSSpec *fsspec;
165 PRUint32 index;
166 } mac_indexed_fragment;
167 } value;
168} PRLibSpec;
169
170/*
171** The following bit flags may be or'd together and passed
172** as the 'flags' argument to PR_LoadLibraryWithFlags.
173** Flags not supported by the underlying OS are ignored.
174*/
175
176#define PR_LD_LAZY 0x1 /* equivalent to RTLD_LAZY on Unix */
177#define PR_LD_NOW 0x2 /* equivalent to RTLD_NOW on Unix */
178#define PR_LD_GLOBAL 0x4 /* equivalent to RTLD_GLOBAL on Unix */
179#define PR_LD_LOCAL 0x8 /* equivalent to RTLD_LOCAL on Unix */
180
181/*
182** Load the specified library, in the manner specified by 'flags'.
183*/
184
185NSPR_API(PRLibrary *)
186PR_LoadLibraryWithFlags(
187 PRLibSpec libSpec, /* the shared library */
188 PRIntn flags /* flags that affect the loading */
189);
190
191/*
192** Unload a previously loaded library. If the library was a static
193** library then the static link table will no longer be referenced. The
194** associated PRLibrary object is freed.
195**
196** PR_FAILURE is returned if the library cannot be unloaded.
197**
198** This function decrements the reference count of the library.
199*/
200NSPR_API(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
201
202/*
203** Given the name of a procedure, return the address of the function that
204** implements the procedure, or NULL if no such function can be
205** found. This does not find symbols in the main program (the ".exe");
206** use PR_LoadStaticLibrary to register symbols in the main program.
207**
208** This function does not modify the reference count of the library.
209*/
210NSPR_API(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
211
212/*
213** Similar to PR_FindSymbol, except that the return value is a pointer to
214** a function, and not a pointer to void. Casting between a data pointer
215** and a function pointer is not portable according to the C standard.
216** Any function pointer can be cast to any other function pointer.
217**
218** This function does not modify the reference count of the library.
219*/
220typedef void (*PRFuncPtr)();
221NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
222
223/*
224** Finds a symbol in one of the currently loaded libraries. Given the
225** name of a procedure, return the address of the function that
226** implements the procedure, and return the library that contains that
227** symbol, or NULL if no such function can be found. This does not find
228** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
229** register symbols in the main program.
230**
231** This increments the reference count of the library.
232*/
233NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
234 PRLibrary* *lib);
235
236/*
237** Similar to PR_FindSymbolAndLibrary, except that the return value is
238** a pointer to a function, and not a pointer to void. Casting between a
239** data pointer and a function pointer is not portable according to the C
240** standard. Any function pointer can be cast to any other function pointer.
241**
242** This increments the reference count of the library.
243*/
244NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
245 PRLibrary* *lib);
246
247/*
248** Register a static link table with the runtime under the name
249** "name". The symbols present in the static link table will be made
250** available to PR_FindSymbol. If "name" is null then the symbols will be
251** made available to the library which represents the executable. The
252** tables are not copied.
253**
254** Returns the library object if successful, null otherwise.
255**
256** This increments the reference count of the library.
257*/
258NSPR_API(PRLibrary*) PR_LoadStaticLibrary(
259 const char *name, const PRStaticLinkTable *table);
260
261/*
262** Return the pathname of the file that the library "name" was loaded
263** from. "addr" is the address of a function defined in the library.
264**
265** The caller is responsible for freeing the result with PR_Free.
266*/
267NSPR_API(char *) PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr);
268
269PR_END_EXTERN_C
270
271#endif /* prlink_h___ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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