PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/gecko_api/include/prlink.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 260 lines | 58 code | 30 blank | 172 comment | 0 complexity | a7beb37fb2380893ed933c23b8648332 MD5 | raw file
  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 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.
124*/
125
126typedef enum PRLibSpecType {
127    PR_LibSpec_Pathname,
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 */ 
131} PRLibSpecType;
132
133struct FSSpec; /* Mac OS FSSpec */
134
135typedef struct PRLibSpec {
136    PRLibSpecType type;
137    union {
138        /* if type is PR_LibSpec_Pathname */
139        const char *pathname;
140
141        /* if type is PR_LibSpec_MacNamedFragment */
142        struct {
143            const struct FSSpec *fsspec;
144            const char *name;
145        } mac_named_fragment;      /* obsolete (for Mac OS Classic) */
146
147        /* if type is PR_LibSpec_MacIndexedFragment */
148        struct {
149            const struct FSSpec *fsspec;
150            PRUint32 index;
151        } mac_indexed_fragment;    /* obsolete (for Mac OS Classic) */
152
153        /* if type is PR_LibSpec_PathnameU */
154        const PRUnichar *pathname_u; /* supported only on Win32 */
155    } value;
156} PRLibSpec;
157
158/*
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.
162*/
163
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/*                0x8000     reserved for NSPR internal use */
169
170/*
171** Load the specified library, in the manner specified by 'flags'.
172*/
173
174NSPR_API(PRLibrary *)
175PR_LoadLibraryWithFlags(
176    PRLibSpec libSpec,    /* the shared library */
177    PRIntn flags          /* flags that affect the loading */
178);
179
180/*
181** Unload a previously loaded library. If the library was a static
182** library then the static link table will no longer be referenced. The
183** associated PRLibrary object is freed.
184**
185** PR_FAILURE is returned if the library cannot be unloaded.
186**
187** This function decrements the reference count of the library.
188*/
189NSPR_API(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
190
191/*
192** Given the name of a procedure, return the address of the function that
193** implements the procedure, or NULL if no such function can be
194** found. This does not find symbols in the main program (the ".exe");
195** use PR_LoadStaticLibrary to register symbols in the main program.
196**
197** This function does not modify the reference count of the library.
198*/
199NSPR_API(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
200
201/*
202** Similar to PR_FindSymbol, except that the return value is a pointer to
203** a function, and not a pointer to void. Casting between a data pointer
204** and a function pointer is not portable according to the C standard.
205** Any function pointer can be cast to any other function pointer.
206**
207** This function does not modify the reference count of the library.
208*/
209typedef void (*PRFuncPtr)();
210NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
211
212/*
213** Finds a symbol in one of the currently loaded libraries. Given the
214** name of a procedure, return the address of the function that
215** implements the procedure, and return the library that contains that
216** symbol, or NULL if no such function can be found. This does not find
217** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
218** register symbols in the main program.  
219**
220** This increments the reference count of the library.
221*/
222NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
223						      PRLibrary* *lib);
224
225/*
226** Similar to PR_FindSymbolAndLibrary, except that the return value is
227** a pointer to a function, and not a pointer to void. Casting between a
228** data pointer and a function pointer is not portable according to the C
229** standard. Any function pointer can be cast to any other function pointer.
230**
231** This increments the reference count of the library.
232*/
233NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
234						      PRLibrary* *lib);
235
236/*
237** Register a static link table with the runtime under the name
238** "name". The symbols present in the static link table will be made
239** available to PR_FindSymbol. If "name" is null then the symbols will be
240** made available to the library which represents the executable. The
241** tables are not copied.
242**
243** Returns the library object if successful, null otherwise.
244**
245** This increments the reference count of the library.
246*/
247NSPR_API(PRLibrary*) PR_LoadStaticLibrary(
248    const char *name, const PRStaticLinkTable *table);
249
250/*
251** Return the pathname of the file that the library "name" was loaded
252** from. "addr" is the address of a function defined in the library.
253**
254** The caller is responsible for freeing the result with PR_Free.
255*/
256NSPR_API(char *) PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr);
257
258PR_END_EXTERN_C
259
260#endif /* prlink_h___ */