| 1 | /* $Id: ModuleBase.h,v 1.2 2000-01-22 18:20:58 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * ModuleBase - Declaration of the Basic module class. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c) 1999 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 | /* | 
|---|
| 34 | * Output macros. | 
|---|
| 35 | * Macros:          option   infolevel | 
|---|
| 36 | *      printIPE    -W1      Error | 
|---|
| 37 | *      printErr    -W1      Error | 
|---|
| 38 | *      printWar    -W2      Warning | 
|---|
| 39 | *      printInf    -W3      Info | 
|---|
| 40 | *      printInfA   -W4      InfoAll | 
|---|
| 41 | */ | 
|---|
| 42 | #define printIPE(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \ | 
|---|
| 43 | ModuleBase::printf("\nerror(%d:"__FUNCTION__"): !Internal Processing Error!\n\t", __LINE__), \ | 
|---|
| 44 | ModuleBase::printf a,  \ | 
|---|
| 45 | ModuleBase::printf("\n")  \ | 
|---|
| 46 | : (void)0,(void)0,(void)0 ) | 
|---|
| 47 | #define printErr(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \ | 
|---|
| 48 | ModuleBase::printf("error(%d:"__FUNCTION__"): ", __LINE__), \ | 
|---|
| 49 | ModuleBase::printf a  \ | 
|---|
| 50 | : (void)0,(void)0 ) | 
|---|
| 51 | #define printWar(a) (ModuleBase::ulInfoLevel >= ModuleBase::Warning ? \ | 
|---|
| 52 | ModuleBase::printf("warning("__FUNCTION__"): "), \ | 
|---|
| 53 | ModuleBase::printf a  \ | 
|---|
| 54 | : (void)0,(void)0 ) | 
|---|
| 55 | #define printInf(a) (ModuleBase::ulInfoLevel >= ModuleBase::Info ? \ | 
|---|
| 56 | ModuleBase::printf a : (void)0 ) | 
|---|
| 57 | #define printInfA(a)(ModuleBase::ulInfoLevel >= ModuleBase::InfoAll ? \ | 
|---|
| 58 | ModuleBase::printf a : (void)0 ) | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | /* | 
|---|
| 62 | * Misc | 
|---|
| 63 | */ | 
|---|
| 64 | #define PAGESIZE                    0x1000 | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | /** | 
|---|
| 70 | * Base class for executable modules. | 
|---|
| 71 | * @author      knut st. osmundsen | 
|---|
| 72 | * @approval    not approved yet... | 
|---|
| 73 | */ | 
|---|
| 74 | class ModuleBase | 
|---|
| 75 | { | 
|---|
| 76 | public: | 
|---|
| 77 | /** @cat Constructor/Destructor */ | 
|---|
| 78 | ModuleBase(SFN hFile); | 
|---|
| 79 | virtual ~ModuleBase(); | 
|---|
| 80 |  | 
|---|
| 81 | /** @cat Public Main methods */ | 
|---|
| 82 | virtual ULONG  init(PCSZ pszFilename); | 
|---|
| 83 | virtual ULONG  read(ULONG offLXFile, PVOID pvBuffer, ULONG cbToRead, ULONG flFlags, PMTE pMTE) = 0; | 
|---|
| 84 | virtual ULONG  applyFixups(PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage, | 
|---|
| 85 | ULONG ulPageAddress, PVOID pvPTDA); /*(ldrEnum32bitRelRecs)*/ | 
|---|
| 86 | #ifndef RING0 | 
|---|
| 87 | virtual ULONG  writeFile(PCSZ pszLXFilename); | 
|---|
| 88 | #endif | 
|---|
| 89 |  | 
|---|
| 90 | /** @cat public Helper methods */ | 
|---|
| 91 | virtual VOID   dumpVirtualLxFile() = 0; | 
|---|
| 92 | BOOL           queryIsModuleName(PCSZ pszFilename); | 
|---|
| 93 |  | 
|---|
| 94 | /** @cat static print method */ | 
|---|
| 95 | static VOID     printf(PCSZ pszFormat, ...); | 
|---|
| 96 |  | 
|---|
| 97 | protected: | 
|---|
| 98 | /** @cat private data members. */ | 
|---|
| 99 | #ifdef DEBUG | 
|---|
| 100 | BOOL        fInitTime;              /* init time indicator (debug) */ | 
|---|
| 101 | #endif | 
|---|
| 102 | SFN         hFile;                  /* filehandle */ | 
|---|
| 103 | PSZ         pszFilename;            /* fullpath */ | 
|---|
| 104 | PSZ         pszModuleName;          /* filename without extention. */ | 
|---|
| 105 |  | 
|---|
| 106 | /** @cat public static data. */ | 
|---|
| 107 | public: | 
|---|
| 108 | static ULONG ulInfoLevel;                    /* Current output message detail level. */ | 
|---|
| 109 | enum {Quiet, Error, Warning, Info, InfoAll}; /* Output message detail levels. */ | 
|---|
| 110 | }; | 
|---|
| 111 |  | 
|---|
| 112 |  | 
|---|
| 113 | #endif | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|