imp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. imp.h
  5. Abstract:
  6. This header contains definitions internal to the Image Library.
  7. Author:
  8. Evan Green 13-Oct-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. #define RTL_API __DLLEXPORT
  14. #include <minoca/kernel/driver.h>
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. //
  19. // Define the initial amount to read for loading image segments.
  20. //
  21. #define IMAGE_INITIAL_READ_SIZE 1024
  22. //
  23. // Define the macros to the various functions.
  24. //
  25. #define ImAllocateMemory ImImportTable->AllocateMemory
  26. #define ImFreeMemory ImImportTable->FreeMemory
  27. #define ImOpenFile ImImportTable->OpenFile
  28. #define ImCloseFile ImImportTable->CloseFile
  29. #define ImLoadFile ImImportTable->LoadFile
  30. #define ImReadFile ImImportTable->ReadFile
  31. #define ImUnloadBuffer ImImportTable->UnloadBuffer
  32. #define ImAllocateAddressSpace ImImportTable->AllocateAddressSpace
  33. #define ImFreeAddressSpace ImImportTable->FreeAddressSpace
  34. #define ImMapImageSegment ImImportTable->MapImageSegment
  35. #define ImUnmapImageSegment ImImportTable->UnmapImageSegment
  36. #define ImNotifyImageLoad ImImportTable->NotifyImageLoad
  37. #define ImNotifyImageUnload ImImportTable->NotifyImageUnload
  38. #define ImInvalidateInstructionCacheRegion \
  39. ImImportTable->InvalidateInstructionCacheRegion
  40. #define ImGetEnvironmentVariable ImImportTable->GetEnvironmentVariable
  41. #define ImFinalizeSegments ImImportTable->FinalizeSegments
  42. //
  43. // Define the maximum import recursion depth.
  44. //
  45. #define MAX_IMPORT_RECURSION_DEPTH 1000
  46. //
  47. // ------------------------------------------------------ Data Type Definitions
  48. //
  49. //
  50. // -------------------------------------------------------------------- Globals
  51. //
  52. extern PIM_IMPORT_TABLE ImImportTable;
  53. //
  54. // -------------------------------------------------------- Function Prototypes
  55. //
  56. PVOID
  57. ImpReadBuffer (
  58. PIMAGE_FILE_INFORMATION File,
  59. PIMAGE_BUFFER Buffer,
  60. UINTN Offset,
  61. UINTN Size
  62. );
  63. /*++
  64. Routine Description:
  65. This routine handles access to an image buffer.
  66. Arguments:
  67. File - Supplies an optional pointer to the file information, if the buffer
  68. may need to be resized.
  69. Buffer - Supplies a pointer to the buffer to read from.
  70. Offset - Supplies the offset from the start of the file to read.
  71. Size - Supplies the required size.
  72. Return Value:
  73. Returns a pointer to the image file at the requested offset on success.
  74. NULL if the range is invalid or the file could not be fully loaded.
  75. --*/
  76. KSTATUS
  77. ImpLoad (
  78. PLIST_ENTRY ListHead,
  79. PSTR BinaryName,
  80. PIMAGE_FILE_INFORMATION BinaryFile,
  81. PIMAGE_BUFFER ImageBuffer,
  82. PVOID SystemContext,
  83. ULONG Flags,
  84. PLOADED_IMAGE Parent,
  85. PLOADED_IMAGE *LoadedImage,
  86. PLOADED_IMAGE *Interpreter
  87. );
  88. /*++
  89. Routine Description:
  90. This routine loads an executable image into memory.
  91. Arguments:
  92. ListHead - Supplies a pointer to the head of the list of loaded images.
  93. BinaryName - Supplies the name of the binary executable image to load. If
  94. this is NULL, then a pointer to the first (primary) image loaded, with
  95. a reference added.
  96. BinaryFile - Supplies an optional handle to the file information. The
  97. handle should be positioned to the beginning of the file. Supply NULL
  98. if the caller does not already have an open handle to the binary. On
  99. success, the image library takes ownership of the handle.
  100. ImageBuffer - Supplies an optional pointer to the image buffer. This can
  101. be a complete image file buffer, or just a partial load of the file.
  102. SystemContext - Supplies an opaque token that will be passed to the
  103. support functions called by the image support library.
  104. Flags - Supplies a bitfield of flags governing the load. See
  105. IMAGE_LOAD_FLAG_* flags.
  106. Parent - Supplies an optional pointer to the parent image that imports this
  107. image.
  108. LoadedImage - Supplies an optional pointer where a pointer to the loaded
  109. image structure will be returned on success.
  110. Interpreter - Supplies an optional pointer where a pointer to the loaded
  111. interpreter structure will be returned on success.
  112. Return Value:
  113. Status code.
  114. --*/
  115. PLOADED_IMAGE
  116. ImpGetPrimaryExecutable (
  117. PLIST_ENTRY ListHead
  118. );
  119. /*++
  120. Routine Description:
  121. This routine returns the primary executable in the list, if there is one.
  122. Arguments:
  123. ListHead - Supplies a pointer to the head of the list of loaded images.
  124. Return Value:
  125. Returns a pointer to the primary executable if it exists. This routine does
  126. not add a reference on the image.
  127. NULL if no primary executable is currently loaded in the list.
  128. --*/