1 | /* $Id: ModuleBase.h,v 1.6 2001-02-11 14:59:20 bird Exp $
|
---|
2 | *
|
---|
3 | * ModuleBase - Declaration of the Basic module class.
|
---|
4 | *
|
---|
5 | * Copyright (c) 1999-2000 knut st. osmundsen
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 | #ifndef _modulebase_h_
|
---|
11 | #define _modulebase_h_
|
---|
12 |
|
---|
13 |
|
---|
14 | /*******************************************************************************
|
---|
15 | * Defined Constants And Macros *
|
---|
16 | *******************************************************************************/
|
---|
17 | /*
|
---|
18 | * Error definitions (used in addition to them in bseerr.h)
|
---|
19 | */
|
---|
20 | #define ERROR_FAILED_TO_ADD_OBJECT 0x42000000UL
|
---|
21 | #define ERROR_INITMETHOD_NOT_INITTIME 0x42000001UL
|
---|
22 | #define ERROR_INTERNAL_PROCESSING_ERROR 0x42000002UL
|
---|
23 |
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * Some useful macros.
|
---|
27 | */
|
---|
28 | #define NOREF(a) (a=a) /* Not referenced parameter warning fix. */
|
---|
29 | #define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL))
|
---|
30 | /* aligns something, a, up to nearest alignment boundrary-
|
---|
31 | * Note: Aligment must be a 2**n number. */
|
---|
32 |
|
---|
33 | #ifndef PAGESHIFT
|
---|
34 | #define PAGESHIFT 12 /* bytes to pages or pages to bytes shift value. */
|
---|
35 | #endif
|
---|
36 | #ifndef PAGESIZE
|
---|
37 | #define PAGESIZE 0x1000 /* pagesize on i386 */
|
---|
38 | #endif
|
---|
39 | #ifndef PAGEOFFSET
|
---|
40 | #define PAGEOFFSET(addr) ((addr) & (PAGESIZE-1)) /* Gets the offset into the page addr points into. */
|
---|
41 | #endif
|
---|
42 | #ifndef PAGESTART
|
---|
43 | #define PAGESTART(addr) ((addr) & ~(PAGESIZE-1)) /* Gets the address of the page addr points into. */
|
---|
44 | #endif
|
---|
45 |
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * Output macros.
|
---|
49 | * Macros: option infolevel
|
---|
50 | * printIPE -W1 Error
|
---|
51 | * printErr -W1 Error
|
---|
52 | * printWar -W2 Warning
|
---|
53 | * printInf -W3 Info
|
---|
54 | * printInfA -W4 InfoAll
|
---|
55 | */
|
---|
56 | #define printIPE(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
---|
57 | ModuleBase::printf("\nerror(%d:"__FUNCTION__"): !Internal Processing Error!\n\t", __LINE__), \
|
---|
58 | ModuleBase::printf a, \
|
---|
59 | ModuleBase::printf("\n") \
|
---|
60 | : (void)0,(void)0,(void)0 )
|
---|
61 | #define printErr(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
---|
62 | ModuleBase::printf("error(%d:"__FUNCTION__"): ", __LINE__), \
|
---|
63 | ModuleBase::printf a \
|
---|
64 | : (void)0,(void)0 )
|
---|
65 | #define printWar(a) (ModuleBase::ulInfoLevel >= ModuleBase::Warning ? \
|
---|
66 | ModuleBase::printf("warning("__FUNCTION__"): "), \
|
---|
67 | ModuleBase::printf a \
|
---|
68 | : (void)0,(void)0 )
|
---|
69 | #define printInf(a) (ModuleBase::ulInfoLevel >= ModuleBase::Info ? \
|
---|
70 | ModuleBase::printf a : (void)0 )
|
---|
71 | #define printInfA(a)(ModuleBase::ulInfoLevel >= ModuleBase::InfoAll ? \
|
---|
72 | ModuleBase::printf a : (void)0 )
|
---|
73 |
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Read macros.
|
---|
77 | * ReadAt: Reads from a file, hFile, at a given offset, ulOffset, into a buffer, pvBuffer,
|
---|
78 | * an amount of bytes, cbToRead.
|
---|
79 | * RING0: Map this to ldrRead with 0UL as flFlags.
|
---|
80 | * RING3: Implementes this function as a static function, ReadAt.
|
---|
81 | * ReadAtF: Same as ReadAt but two extra parameters; an additional far pointer to the buffer and
|
---|
82 | * a MTE pointer. Used in the read method.
|
---|
83 | * RING0: Map directly to ldrRead.
|
---|
84 | * RING3: Map to ReadAt, ignoring the two extra parameters.
|
---|
85 | */
|
---|
86 | #ifdef RING0
|
---|
87 | #define ReadAt(hFile, ulOffset, pvBuffer, cbToRead) \
|
---|
88 | ldrRead(hFile, ulOffset, pvBuffer, 0UL, cbToRead, NULL)
|
---|
89 | #define ReadAtF(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE) \
|
---|
90 | ldrRead(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE)
|
---|
91 | #else
|
---|
92 | #define ReadAtF(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE) \
|
---|
93 | ReadAt(hFile, ulOffset, pvBuffer, cbToRead)
|
---|
94 | #endif
|
---|
95 |
|
---|
96 |
|
---|
97 | /*******************************************************************************
|
---|
98 | * Functions *
|
---|
99 | *******************************************************************************/
|
---|
100 | #ifndef RING0
|
---|
101 | APIRET ReadAt(SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG cbToRead);
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Make sure that pLdrLv is defined.
|
---|
106 | */
|
---|
107 | #if !defined(RING0) && !defined(_ldrCalls_h_)
|
---|
108 | typedef struct ldrlv_s ldrlv_t;
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Base class for executable modules.
|
---|
113 | * @author knut st. osmundsen
|
---|
114 | * @approval not approved yet...
|
---|
115 | */
|
---|
116 | class ModuleBase
|
---|
117 | {
|
---|
118 | public:
|
---|
119 | /** @cat Constructor/Destructor */
|
---|
120 | ModuleBase(SFN hFile);
|
---|
121 | virtual ~ModuleBase();
|
---|
122 |
|
---|
123 | /** @cat Public Main methods */
|
---|
124 | virtual ULONG init(PCSZ pszFilename);
|
---|
125 | virtual ULONG read(ULONG offLXFile, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE) = 0;
|
---|
126 | virtual ULONG applyFixups(PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage,
|
---|
127 | ULONG ulPageAddress, PVOID pvPTDA); /*(ldrEnum32bitRelRecs)*/
|
---|
128 | virtual ULONG openPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *pLdrLv, PULONG pful, ULONG lLibPath); /* (ldrOpenPath) */
|
---|
129 | #ifndef RING0
|
---|
130 | virtual ULONG writeFile(PCSZ pszLXFilename);
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | /** @cat public Helper methods */
|
---|
134 | virtual VOID dumpVirtualLxFile() = 0;
|
---|
135 | BOOL queryIsModuleName(PCSZ pszFilename);
|
---|
136 | PCSZ getFilename();
|
---|
137 | PCSZ getModuleName();
|
---|
138 |
|
---|
139 | /** @cat static print method */
|
---|
140 | static VOID printf(PCSZ pszFormat, ...);
|
---|
141 |
|
---|
142 | protected:
|
---|
143 | /** @cat private data members. */
|
---|
144 | #ifdef DEBUG
|
---|
145 | BOOL fInitTime; /* init time indicator (debug) */
|
---|
146 | #endif
|
---|
147 | SFN hFile; /* filehandle */
|
---|
148 | PSZ pszFilename; /* fullpath */
|
---|
149 | PSZ pszModuleName; /* filename without path and extention. */
|
---|
150 |
|
---|
151 | /** @cat public static data. */
|
---|
152 | public:
|
---|
153 | static ULONG ulInfoLevel; /* Current output message detail level. */
|
---|
154 | enum {Quiet, Error, Warning, Info, InfoAll}; /* Output message detail levels. */
|
---|
155 | };
|
---|
156 |
|
---|
157 |
|
---|
158 | #endif
|
---|
159 |
|
---|
160 |
|
---|