1 | /* $Id: ModuleBase.h,v 1.5 2000-09-22 09:22:36 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 | #define PAGESHIFT 12 /* bytes to pages or pages to bytes shift value. */
|
---|
34 | #ifndef PAGESIZE
|
---|
35 | #define PAGESIZE 0x1000 /* pagesize on i386 */
|
---|
36 | #endif
|
---|
37 | #define PAGEOFFSET(addr) ((addr) & (PAGESIZE-1)) /* Gets the offset into the page addr points into. */
|
---|
38 | #define PAGESTART(addr) ((addr) & ~(PAGESIZE-1)) /* Gets the address of the page addr points into. */
|
---|
39 |
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * Output macros.
|
---|
43 | * Macros: option infolevel
|
---|
44 | * printIPE -W1 Error
|
---|
45 | * printErr -W1 Error
|
---|
46 | * printWar -W2 Warning
|
---|
47 | * printInf -W3 Info
|
---|
48 | * printInfA -W4 InfoAll
|
---|
49 | */
|
---|
50 | #define printIPE(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
---|
51 | ModuleBase::printf("\nerror(%d:"__FUNCTION__"): !Internal Processing Error!\n\t", __LINE__), \
|
---|
52 | ModuleBase::printf a, \
|
---|
53 | ModuleBase::printf("\n") \
|
---|
54 | : (void)0,(void)0,(void)0 )
|
---|
55 | #define printErr(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
---|
56 | ModuleBase::printf("error(%d:"__FUNCTION__"): ", __LINE__), \
|
---|
57 | ModuleBase::printf a \
|
---|
58 | : (void)0,(void)0 )
|
---|
59 | #define printWar(a) (ModuleBase::ulInfoLevel >= ModuleBase::Warning ? \
|
---|
60 | ModuleBase::printf("warning("__FUNCTION__"): "), \
|
---|
61 | ModuleBase::printf a \
|
---|
62 | : (void)0,(void)0 )
|
---|
63 | #define printInf(a) (ModuleBase::ulInfoLevel >= ModuleBase::Info ? \
|
---|
64 | ModuleBase::printf a : (void)0 )
|
---|
65 | #define printInfA(a)(ModuleBase::ulInfoLevel >= ModuleBase::InfoAll ? \
|
---|
66 | ModuleBase::printf a : (void)0 )
|
---|
67 |
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Read macros.
|
---|
71 | * ReadAt: Reads from a file, hFile, at a given offset, ulOffset, into a buffer, pvBuffer,
|
---|
72 | * an amount of bytes, cbToRead.
|
---|
73 | * RING0: Map this to ldrRead with 0UL as flFlags.
|
---|
74 | * RING3: Implementes this function as a static function, ReadAt.
|
---|
75 | * ReadAtF: Same as ReadAt but two extra parameters; an additional far pointer to the buffer and
|
---|
76 | * a MTE pointer. Used in the read method.
|
---|
77 | * RING0: Map directly to ldrRead.
|
---|
78 | * RING3: Map to ReadAt, ignoring the two extra parameters.
|
---|
79 | */
|
---|
80 | #ifdef RING0
|
---|
81 | #define ReadAt(hFile, ulOffset, pvBuffer, cbToRead) \
|
---|
82 | ldrRead(hFile, ulOffset, pvBuffer, 0UL, cbToRead, NULL)
|
---|
83 | #define ReadAtF(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE) \
|
---|
84 | ldrRead(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE)
|
---|
85 | #else
|
---|
86 | #define ReadAtF(hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE) \
|
---|
87 | ReadAt(hFile, ulOffset, pvBuffer, cbToRead)
|
---|
88 | #endif
|
---|
89 |
|
---|
90 |
|
---|
91 | /*******************************************************************************
|
---|
92 | * Functions *
|
---|
93 | *******************************************************************************/
|
---|
94 | #ifndef RING0
|
---|
95 | APIRET ReadAt(SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG cbToRead);
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Make sure that pLdrLv is defined.
|
---|
100 | */
|
---|
101 | #if !defined(RING0) && !defined(_ldrCalls_h_)
|
---|
102 | typedef struct ldrlv_s ldrlv_t;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Base class for executable modules.
|
---|
107 | * @author knut st. osmundsen
|
---|
108 | * @approval not approved yet...
|
---|
109 | */
|
---|
110 | class ModuleBase
|
---|
111 | {
|
---|
112 | public:
|
---|
113 | /** @cat Constructor/Destructor */
|
---|
114 | ModuleBase(SFN hFile);
|
---|
115 | virtual ~ModuleBase();
|
---|
116 |
|
---|
117 | /** @cat Public Main methods */
|
---|
118 | virtual ULONG init(PCSZ pszFilename);
|
---|
119 | virtual ULONG read(ULONG offLXFile, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE) = 0;
|
---|
120 | virtual ULONG applyFixups(PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage,
|
---|
121 | ULONG ulPageAddress, PVOID pvPTDA); /*(ldrEnum32bitRelRecs)*/
|
---|
122 | virtual ULONG openPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *pLdrLv, PULONG pful, ULONG lLibPath); /* (ldrOpenPath) */
|
---|
123 | #ifndef RING0
|
---|
124 | virtual ULONG writeFile(PCSZ pszLXFilename);
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | /** @cat public Helper methods */
|
---|
128 | virtual VOID dumpVirtualLxFile() = 0;
|
---|
129 | BOOL queryIsModuleName(PCSZ pszFilename);
|
---|
130 | PCSZ getFilename();
|
---|
131 | PCSZ getModuleName();
|
---|
132 |
|
---|
133 | /** @cat static print method */
|
---|
134 | static VOID printf(PCSZ pszFormat, ...);
|
---|
135 |
|
---|
136 | protected:
|
---|
137 | /** @cat private data members. */
|
---|
138 | #ifdef DEBUG
|
---|
139 | BOOL fInitTime; /* init time indicator (debug) */
|
---|
140 | #endif
|
---|
141 | SFN hFile; /* filehandle */
|
---|
142 | PSZ pszFilename; /* fullpath */
|
---|
143 | PSZ pszModuleName; /* filename without path and extention. */
|
---|
144 |
|
---|
145 | /** @cat public static data. */
|
---|
146 | public:
|
---|
147 | static ULONG ulInfoLevel; /* Current output message detail level. */
|
---|
148 | enum {Quiet, Error, Warning, Info, InfoAll}; /* Output message detail levels. */
|
---|
149 | };
|
---|
150 |
|
---|
151 |
|
---|
152 | #endif
|
---|
153 |
|
---|
154 |
|
---|