-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimp.h
197 lines (132 loc) · 4.92 KB
/
imp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*++
Copyright (c) 2012 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
[email protected] for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
imp.h
Abstract:
This header contains definitions internal to the Image Library.
Author:
Evan Green 13-Oct-2012
--*/
//
// ------------------------------------------------------------------- Includes
//
#define RTL_API __DLLEXPORT
#include <minoca/kernel/driver.h>
//
// ---------------------------------------------------------------- Definitions
//
//
// Define the initial amount to read for loading image segments.
//
#define IMAGE_INITIAL_READ_SIZE 1024
//
// Define the macros to the various functions.
//
#define ImAllocateMemory ImImportTable->AllocateMemory
#define ImFreeMemory ImImportTable->FreeMemory
#define ImOpenFile ImImportTable->OpenFile
#define ImCloseFile ImImportTable->CloseFile
#define ImLoadFile ImImportTable->LoadFile
#define ImReadFile ImImportTable->ReadFile
#define ImUnloadBuffer ImImportTable->UnloadBuffer
#define ImAllocateAddressSpace ImImportTable->AllocateAddressSpace
#define ImFreeAddressSpace ImImportTable->FreeAddressSpace
#define ImMapImageSegment ImImportTable->MapImageSegment
#define ImUnmapImageSegment ImImportTable->UnmapImageSegment
#define ImNotifyImageLoad ImImportTable->NotifyImageLoad
#define ImNotifyImageUnload ImImportTable->NotifyImageUnload
#define ImInvalidateInstructionCacheRegion \
ImImportTable->InvalidateInstructionCacheRegion
#define ImGetEnvironmentVariable ImImportTable->GetEnvironmentVariable
#define ImFinalizeSegments ImImportTable->FinalizeSegments
//
// Define the maximum import recursion depth.
//
#define MAX_IMPORT_RECURSION_DEPTH 1000
//
// ------------------------------------------------------ Data Type Definitions
//
//
// -------------------------------------------------------------------- Globals
//
extern PIM_IMPORT_TABLE ImImportTable;
//
// -------------------------------------------------------- Function Prototypes
//
PVOID
ImpReadBuffer (
PIMAGE_FILE_INFORMATION File,
PIMAGE_BUFFER Buffer,
UINTN Offset,
UINTN Size
);
/*++
Routine Description:
This routine handles access to an image buffer.
Arguments:
File - Supplies an optional pointer to the file information, if the buffer
may need to be resized.
Buffer - Supplies a pointer to the buffer to read from.
Offset - Supplies the offset from the start of the file to read.
Size - Supplies the required size.
Return Value:
Returns a pointer to the image file at the requested offset on success.
NULL if the range is invalid or the file could not be fully loaded.
--*/
KSTATUS
ImpLoad (
PLIST_ENTRY ListHead,
PCSTR BinaryName,
PIMAGE_FILE_INFORMATION BinaryFile,
PIMAGE_BUFFER ImageBuffer,
PVOID SystemContext,
ULONG Flags,
PLOADED_IMAGE Parent,
PLOADED_IMAGE *LoadedImage,
PLOADED_IMAGE *Interpreter
);
/*++
Routine Description:
This routine loads an executable image into memory.
Arguments:
ListHead - Supplies a pointer to the head of the list of loaded images.
BinaryName - Supplies the name of the binary executable image to load. If
this is NULL, then a pointer to the first (primary) image loaded, with
a reference added.
BinaryFile - Supplies an optional handle to the file information. The
handle should be positioned to the beginning of the file. Supply NULL
if the caller does not already have an open handle to the binary. On
success, the image library takes ownership of the handle.
ImageBuffer - Supplies an optional pointer to the image buffer. This can
be a complete image file buffer, or just a partial load of the file.
SystemContext - Supplies an opaque token that will be passed to the
support functions called by the image support library.
Flags - Supplies a bitfield of flags governing the load. See
IMAGE_LOAD_FLAG_* flags.
Parent - Supplies an optional pointer to the parent image that imports this
image.
LoadedImage - Supplies an optional pointer where a pointer to the loaded
image structure will be returned on success.
Interpreter - Supplies an optional pointer where a pointer to the loaded
interpreter structure will be returned on success.
Return Value:
Status code.
--*/
PLOADED_IMAGE
ImpGetPrimaryExecutable (
PLIST_ENTRY ListHead
);
/*++
Routine Description:
This routine returns the primary executable in the list, if there is one.
Arguments:
ListHead - Supplies a pointer to the head of the list of loaded images.
Return Value:
Returns a pointer to the primary executable if it exists. This routine does
not add a reference on the image.
NULL if no primary executable is currently loaded in the list.
--*/