source: trunk/src/win32k/ldr/ModuleBase.cpp@ 2501

Last change on this file since 2501 was 2501, checked in by bird, 26 years ago

Temporary backup checkin.

File size: 7.8 KB
Line 
1/* $Id: ModuleBase.cpp,v 1.2 2000-01-22 18:21:01 bird Exp $
2 *
3 * ModuleBase - Implementetation.
4 *
5 * Copyright (c) 1999 knut st. osmundsen
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11/*******************************************************************************
12* Defined Constants And Macros *
13*******************************************************************************/
14#define INCL_DOSERRORS /* DOS Error codes. */
15#ifdef RING0
16 #define INCL_NOAPI /* RING0: No apis. */
17#else /*RING3*/
18 #define INCL_DOSFILEMGR /* RING3: DOS File api. */
19#endif
20
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <os2.h> /* OS/2 header file. */
26
27#include "malloc.h" /* win32k malloc. Not C library! */
28
29#include <string.h> /* C library string.h. */
30#include <stdarg.h> /* C library stdarg.h. */
31
32#include "vprintf.h" /* win32k printf and vprintf. Not C library! */
33#include "dev32.h" /* 32-Bit part of the device driver. (SSToDS) */
34#include "OS2Krnl.h" /* kernel structs. (SFN) */
35#include "modulebase.h" /* ModuleBase class definitions, ++. */
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41/**
42 * Current output message detail level; default: ModuleBase::Info, -W3.
43 */
44ULONG ModuleBase::ulInfoLevel = ModuleBase::Info;
45
46
47
48/**
49 * Constructor - Initializes the object to init state and sets the filehandle.
50 * @param hFile System filenumber of the exectuable file.
51 * @status completely implemented.
52 * @author knut st. osmundsen
53 */
54ModuleBase::ModuleBase(SFN hFile) : hFile(hFile), pszFilename(NULL), pszModuleName(NULL)
55{
56 #ifdef DEBUG
57 fInitTime = TRUE;
58 #endif
59}
60
61
62/**
63 * Destructor frees all memory allocated by this object.
64 * @status completely implemented.
65 * @author knut st. osmundsen
66 */
67ModuleBase::~ModuleBase()
68{
69 if (pszFilename != NULL)
70 free(pszFilename);
71 if (pszModuleName != NULL)
72 free(pszModuleName);
73 #ifdef DEBUG
74 fInitTime = (BOOL)-1;
75 pszFilename = (PSZ)0xFFFFBEEF;
76 pszModuleName = (PSZ)0xFFFFBEEF;
77 #endif
78}
79
80
81
82/**
83 * This functions sets the filename and modulename for the ModuleBase object.
84 *
85 * The children of this class should override this method and upon return of it
86 * the object should be a fully initialized virtual LX file. The object will
87 * then not be in init mode any longer (fInitTime is FALSE).
88 *
89 * @returns NO_ERROR on success.
90 * ERROR_NOT_ENOUGH_MEMORY
91 * ERROR_INTERNAL_PROCESSING_ERROR
92 * @param pszFilename Module filename.
93 * @precond Called in init-mode.
94 * @sketch DEBUG: Verify initmode.
95 * Duplicate filename.
96 * Derive the modulename from the filename.
97 * return successfully.
98 * @status Completely implemented; tested.
99 * @author knut st. osmundsen
100 * @remark The object is still in initmode when returing.
101 */
102ULONG ModuleBase::init(PCSZ pszFilename)
103{
104 PCSZ psz;
105 int i;
106
107 #ifdef DEBUG
108 /* check that were called in initmode. */
109 if (!fInitTime)
110 return ERROR_INTERNAL_PROCESSING_ERROR;
111 #endif
112
113 /* Duplicate filename. */
114 this->pszFilename = (char*)malloc(strlen(pszFilename) + 1);
115 if (this->pszFilename == NULL)
116 return ERROR_NOT_ENOUGH_MEMORY;
117 strcpy(this->pszFilename, pszFilename);
118
119 /* Derive the modulename. */
120 if ((psz = strrchr(pszFilename, '\\') + 1) == (PCHAR)1)
121 if ((psz = strrchr(pszFilename, '/') + 1) == (PCHAR)1)
122 psz = pszFilename;
123 pszModuleName = strchr(psz, '.');
124 i = pszModuleName != NULL ? pszModuleName - psz : strlen(psz);
125 pszModuleName = (PSZ)malloc(i + 1);
126 if (pszModuleName == NULL)
127 return ERROR_NOT_ENOUGH_MEMORY;
128 strncpy(pszModuleName, psz, i);
129 pszModuleName[i] = '\0';
130
131 /* return successfully */
132 return NO_ERROR;
133}
134
135
136
137/**
138 * Applies relocation fixups to a page which is being loaded.
139 * @returns NO_ERROR on success?
140 * error code on error?
141 * @param pMTE Pointer Module Table Entry.
142 * @param iObject Index into the object table. (0-based)
143 * @param iPageTable Index into the page table. (0-based)
144 * @param pvPage Pointer to the page which is being loaded.
145 * @param ulPageAddress Address of page.
146 * @param pvPTDA Pointer to Per Task Data Aera
147 * @remark Stub.
148 */
149ULONG ModuleBase::applyFixups(PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage,
150 ULONG ulPageAddress, PVOID pvPTDA)
151{
152 NOREF(pMTE);
153 NOREF(iObject);
154 NOREF(iPageTable);
155 NOREF(pvPage);
156 NOREF(ulPageAddress);
157 NOREF(pvPTDA);
158 return NO_ERROR;
159}
160
161
162
163#ifndef RING0
164
165/**
166 * Optional method objects when in Ring-3: Write the virtual LX file to disk.
167 *
168 * A child my override this method, as this is simply a dummy stub.
169 *
170 * @returns ERROR_NOT_SUPPORTED.
171 * Children: OS/2 styled return codes with the errorcodes specified in ModuleBase.h.
172 * @param pszFilename Name of output file. This file should be overwritten if exists and created
173 * if it don't exists.
174 * @status completely implemented.
175 * @author knut st. osmundsen
176 */
177ULONG ModuleBase::writeFile(PCSZ pszFilename)
178{
179 pszFilename = pszFilename;
180 return ERROR_NOT_SUPPORTED;
181}
182
183#endif
184
185
186/**
187 * Compare a given filename/modulename with the name of this module.
188 * @returns TRUE: Matching.
189 * FALSE: Non-matching.
190 * @param pszFilename Filename/modulename to match with this module.
191 * @sketch IF filename without path THEN
192 * BEGIN
193 * IF no extention THEN
194 * compare directly with modulename
195 * ELSE
196 * compare input filename with the object filename without path.
197 * END
198 * ELSE
199 * compare input filename with the object filename
200 * return TRUE if equal : FALSE if not.
201 * @status completely implemented.
202 * @author knut st. osmundsen
203 */
204BOOL ModuleBase::queryIsModuleName(PCSZ pszFilename)
205{
206 #ifdef DEBUG
207 if (!fInitTime)
208 {
209 printIPE(("queryIsModuleName should not be called during init!\n"));
210 return FALSE;
211 }
212 #endif
213 if (strchr(pszFilename, '\\') == NULL && strchr(pszFilename,'/') == NULL)
214 { /* use module name - no extention */
215 if (strchr(pszFilename, '.') == NULL)
216 return stricmp(pszFilename, pszModuleName) == 0;
217 else
218 { /* extention */
219 PCSZ psz = strchr(this->pszFilename, '\\');
220 if ((psz = strchr(this->pszFilename, '/')) == NULL)
221 psz = this->pszFilename;
222 else
223 psz++; /* skip '\\' or '/' */
224 return stricmp(pszFilename, psz) == 0;
225 }
226 }
227
228 /* TODO: relative name vs fullname. */
229 return stricmp(pszFilename, this->pszFilename) == 0;
230}
231
232
233/**
234 * Output function for Modules.
235 * @param pszFormat Pointer to format string.
236 * @status completely implemented; tested.
237 * @author knut st. osmundsen
238 */
239VOID ModuleBase::printf(PCSZ pszFormat, ...)
240{
241 va_list arguments;
242
243 if (ulInfoLevel <= ModuleBase::ulInfoLevel)
244 {
245 va_start(arguments, pszFormat);
246 vprintf2(pszFormat, arguments);
247 va_end(arguments);
248 }
249}
250
251
252
Note: See TracBrowser for help on using the repository browser.