home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / mach-o / dyld.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-14  |  9.8 KB  |  308 lines

  1. /*
  2.  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
  7.  * Reserved.  This file contains Original Code and/or Modifications of
  8.  * Original Code as defined in and that are subject to the Apple Public
  9.  * Source License Version 1.1 (the "License").  You may not use this file
  10.  * except in compliance with the License.  Please obtain a copy of the
  11.  * License at http://www.apple.com/publicsource and read it before using
  12.  * this file.
  13.  * 
  14.  * The Original Code and all software distributed under the License are
  15.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  16.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  17.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
  19.  * License for the specific language governing rights and limitations
  20.  * under the License.
  21.  * 
  22.  * @APPLE_LICENSE_HEADER_END@
  23.  */
  24. #ifndef _MACH_O_DYLD_H_
  25. #define _MACH_O_DYLD_H_
  26.  
  27. #if __cplusplus
  28. extern "C" {
  29. #endif /* __cplusplus */
  30.  
  31. #if defined(__MWERKS__) && !defined(__private_extern__)
  32. #define __private_extern__ __declspec(private_extern)
  33. #endif
  34.  
  35. #import "mach-o/loader.h"
  36.  
  37. #ifndef ENUM_DYLD_BOOL
  38. #define ENUM_DYLD_BOOL
  39. #undef FALSE
  40. #undef TRUE
  41. #if !defined(__cplusplus) && !defined(__ALTIVEC__) && !defined(DYLD_BOOL)
  42. #define DYLD_BOOL bool
  43. #endif
  44. enum DYLD_BOOL {
  45.     FALSE,
  46.     TRUE
  47. };
  48. #endif /* ENUM_DYLD_BOOL */
  49.  
  50. /*
  51.  * The high level NS... API.
  52.  */
  53.  
  54. /* Object file image api */
  55. typedef enum {
  56.     NSObjectFileImageFailure, /* for this a message is printed on stderr */
  57.     NSObjectFileImageSuccess,
  58.     NSObjectFileImageInappropriateFile,
  59.     NSObjectFileImageArch,
  60.     NSObjectFileImageFormat, /* for this a message is printed on stderr */
  61.     NSObjectFileImageAccess
  62. } NSObjectFileImageReturnCode;
  63.  
  64. typedef void * NSObjectFileImage;
  65.  
  66. /* limited implementation, only MH_BUNDLE files can be used */
  67. extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(
  68.     const char *pathName,
  69.     NSObjectFileImage *objectFileImage);
  70. extern NSObjectFileImageReturnCode NSCreateCoreFileImageFromFile(
  71.     const char *pathName,
  72.     NSObjectFileImage *objectFileImage);
  73. /* not yet implemented */
  74. extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(
  75.     void *address,
  76.     unsigned long size, 
  77.     NSObjectFileImage *objectFileImage);
  78. extern enum DYLD_BOOL NSDestroyObjectFileImage(
  79.     NSObjectFileImage objectFileImage);
  80. /*
  81.  * Need api on NSObjectFileImage's for:
  82.  *   "for Each Symbol Definition In Object File Image" (for Dynamic Bundles)
  83.  *   Could have the same thing for references
  84.  */
  85. /* not yet implemented */
  86. extern unsigned long NSSymbolDefinitionCountInObjectFileImage(
  87.     NSObjectFileImage objectFileImage);
  88. /* not yet implemented */
  89. extern const char * NSSymbolDefinitionNameInObjectFileImage(
  90.     NSObjectFileImage objectFileImage,
  91.     unsigned long ordinal);
  92. /* not yet implemented */
  93. extern unsigned long NSSymbolReferenceCountInObjectFileImage(
  94.     NSObjectFileImage objectFileImage);
  95. /* not yet implemented */
  96. extern const char * NSSymbolReferenceNameInObjectFileImage(
  97.     NSObjectFileImage objectFileImage,
  98.     unsigned long ordinal,
  99.     enum DYLD_BOOL *tentative_definition); /* can be NULL */
  100. /*
  101.  * Other needed api on NSObjectFileImage:
  102.  *   "does Object File Image define symbol name X" (using sorted symbol table)
  103.  *   a way to get the named objective-C section
  104.  */
  105. /* not yet implemented */
  106. extern enum DYLD_BOOL NSIsSymbolDefinedInObjectFileImage(
  107.     NSObjectFileImage objectFileImage,
  108.     const char *symbolName);
  109. /* not yet implemented */
  110. extern void * NSGetSectionDataInObjectFileImage(
  111.     NSObjectFileImage objectFileImage,
  112.     const char *segmentName,
  113.     const char *sectionName);
  114.  
  115. /* module api */
  116. typedef void * NSModule;
  117. extern const char * NSNameOfModule(
  118.     NSModule m); 
  119. extern const char * NSLibraryNameForModule(
  120.     NSModule m);
  121.  
  122. /* limited implementation, only MH_BUNDLE files can be linked */
  123. extern NSModule NSLinkModule(
  124.     NSObjectFileImage objectFileImage, 
  125.     const char *moduleName,
  126.     unsigned long options);
  127. #define NSLINKMODULE_OPTION_NONE        0x0
  128. #define NSLINKMODULE_OPTION_BINDNOW        0x1
  129. #define NSLINKMODULE_OPTION_PRIVATE        0x2
  130. #define NSLINKMODULE_OPTION_RETURN_ON_ERROR    0x4
  131.  
  132. /* limited implementation, only modules loaded with NSLinkModule() can be
  133.    unlinked */
  134. extern enum DYLD_BOOL NSUnLinkModule(
  135.     NSModule module, 
  136.     unsigned long options);
  137. #define NSUNLINKMODULE_OPTION_NONE            0x0
  138. #define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED    0x1
  139. #define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES    0x2
  140.  
  141. /* not yet implemented */
  142. extern NSModule NSReplaceModule(
  143.     NSModule moduleToReplace,
  144.     NSObjectFileImage newObjectFileImage, 
  145.     unsigned long options);
  146.  
  147. /* symbol api */
  148. typedef void * NSSymbol;
  149. extern enum DYLD_BOOL NSIsSymbolNameDefined(
  150.     const char *symbolName);
  151. extern enum DYLD_BOOL NSIsSymbolNameDefinedWithHint(
  152.     const char *symbolName,
  153.     const char *libraryNameHint);
  154. extern enum DYLD_BOOL NSIsSymbolNameDefinedInImage(
  155.     const struct mach_header *image,
  156.     const char *symbolName);
  157. extern NSSymbol NSLookupAndBindSymbol(
  158.     const char *symbolName);
  159. extern NSSymbol NSLookupAndBindSymbolWithHint(
  160.     const char *symbolName,
  161.     const char *libraryNameHint);
  162. extern NSSymbol NSLookupSymbolInModule(
  163.     NSModule module,
  164.     const char *symbolName);
  165. extern NSSymbol NSLookupSymbolInImage(
  166.     const struct mach_header *image,
  167.     const char *symbolName,
  168.     unsigned long options);
  169. #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND            0x0
  170. #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW        0x1
  171. #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY      0x2
  172. #define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
  173. extern const char * NSNameOfSymbol(
  174.     NSSymbol symbol);
  175. extern void * NSAddressOfSymbol(
  176.     NSSymbol symbol);
  177. extern NSModule NSModuleForSymbol(
  178.     NSSymbol symbol);
  179.  
  180. /* error handling api */
  181. typedef enum {
  182.     NSLinkEditFileAccessError,
  183.     NSLinkEditFileFormatError,
  184.     NSLinkEditMachResourceError,
  185.     NSLinkEditUnixResourceError,
  186.     NSLinkEditOtherError,
  187.     NSLinkEditWarningError,
  188.     NSLinkEditMultiplyDefinedError,
  189.     NSLinkEditUndefinedError
  190. } NSLinkEditErrors;
  191.  
  192. /*
  193.  * For the NSLinkEditErrors value NSLinkEditOtherError these are the values
  194.  * passed to the link edit error handler as the errorNumber (what would be an
  195.  * errno value for NSLinkEditUnixResourceError or a kern_return_t value for
  196.  * NSLinkEditMachResourceError).
  197.  */
  198. typedef enum {
  199.     NSOtherErrorRelocation, 
  200.     NSOtherErrorLazyBind,
  201.     NSOtherErrorIndrLoop,
  202.     NSOtherErrorLazyInit,
  203.     NSOtherErrorInvalidArgs
  204. } NSOtherErrorNumbers;
  205.  
  206. extern void NSLinkEditError(
  207.     NSLinkEditErrors *c,
  208.     int *errorNumber, 
  209.     const char **fileName,
  210.     const char **errorString);
  211.  
  212. typedef struct {
  213.      void     (*undefined)(const char *symbolName);
  214.      NSModule (*multiple)(NSSymbol s, NSModule oldModule, NSModule newModule); 
  215.      void     (*linkEdit)(NSLinkEditErrors errorClass, int errorNumber,
  216.                           const char *fileName, const char *errorString);
  217. } NSLinkEditErrorHandlers;
  218.  
  219. extern void NSInstallLinkEditErrorHandlers(
  220.     NSLinkEditErrorHandlers *handlers);
  221.  
  222. /* other api */
  223. extern enum DYLD_BOOL NSAddLibrary(
  224.     const char *pathName);
  225. extern enum DYLD_BOOL NSAddLibraryWithSearching(
  226.     const char *pathName);
  227. extern const struct mach_header * NSAddImage(
  228.     const char *image_name,
  229.     unsigned long options);
  230. #define NSADDIMAGE_OPTION_NONE                  0x0
  231. #define NSADDIMAGE_OPTION_RETURN_ON_ERROR       0x1
  232. #define NSADDIMAGE_OPTION_WITH_SEARCHING        0x2
  233. #define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
  234. extern long NSVersionOfRunTimeLibrary(
  235.     const char *libraryName);
  236. extern long NSVersionOfLinkTimeLibrary(
  237.     const char *libraryName);
  238.  
  239. /*
  240.  * The low level _dyld_... API.
  241.  * (used by the objective-C runtime primarily)
  242.  */
  243. extern unsigned long _dyld_present(
  244.     void);
  245.  
  246. extern unsigned long _dyld_image_count(
  247.     void);
  248. extern struct mach_header * _dyld_get_image_header(
  249.     unsigned long image_index);
  250. extern unsigned long _dyld_get_image_vmaddr_slide(
  251.     unsigned long image_index);
  252. extern char * _dyld_get_image_name(
  253.     unsigned long image_index);
  254.  
  255. extern void _dyld_register_func_for_add_image(
  256.     void (*func)(struct mach_header *mh, unsigned long vmaddr_slide));
  257. extern void _dyld_register_func_for_remove_image(
  258.     void (*func)(struct mach_header *mh, unsigned long vmaddr_slide));
  259. extern void _dyld_register_func_for_link_module(
  260.     void (*func)(NSModule module));
  261. /* not yet implemented */
  262. extern void _dyld_register_func_for_unlink_module(
  263.     void (*func)(NSModule module));
  264. /* not yet implemented */
  265. extern void _dyld_register_func_for_replace_module(
  266.     void (*func)(NSModule oldmodule, NSModule newmodule));
  267. extern void _dyld_get_objc_module_sect_for_module(
  268.     NSModule module,
  269.     void **objc_module,
  270.     unsigned long *size);
  271. extern void _dyld_bind_objc_module(
  272.     void *objc_module);
  273. extern enum DYLD_BOOL _dyld_bind_fully_image_containing_address(
  274.     unsigned long *address);
  275.  
  276. extern void _dyld_moninit(
  277.     void (*monaddition)(char *lowpc, char *highpc));
  278. extern enum DYLD_BOOL _dyld_launched_prebound(
  279.     void);
  280.  
  281. extern void _dyld_lookup_and_bind(
  282.     const char *symbol_name,
  283.     unsigned long *address,
  284.     void **module);
  285. extern void _dyld_lookup_and_bind_with_hint(
  286.     const char *symbol_name,
  287.     const char *library_name_hint,
  288.     unsigned long *address,
  289.     void **module);
  290. extern void _dyld_lookup_and_bind_objc(
  291.     const char *symbol_name,
  292.     unsigned long *address,
  293.     void **module);
  294. extern void _dyld_lookup_and_bind_fully(
  295.     const char *symbol_name,
  296.     unsigned long *address,
  297.     void **module);
  298.  
  299. __private_extern__ int _dyld_func_lookup(
  300.     const char *dyld_func_name,
  301.     unsigned long *address);
  302.  
  303. #if __cplusplus
  304. }
  305. #endif /* __cplusplus */
  306.  
  307. #endif /* _MACH_O_DYLD_H_ */
  308.