PageRenderTime 29ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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