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

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

Some bugsfixes - Yield is disabled.
Added parameters.
Correcte moduleheaders.
Introduced a new base class for virtual lx modules + some elf sketches.

File size: 7.0 KB
Line 
1/* $Id: ModuleBase.cpp,v 1.1 1999-11-10 01:45:35 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#ifndef RING0
137
138/**
139 * Optional method objects when in Ring-3: Write the virtual LX file to disk.
140 *
141 * A child my override this method, as this is simply a dummy stub.
142 *
143 * @returns ERROR_NOT_SUPPORTED.
144 * Children: OS/2 styled return codes with the errorcodes specified in ModuleBase.h.
145 * @param pszFilename Name of output file. This file should be overwritten if exists and created
146 * if it don't exists.
147 * @status completely implemented.
148 * @author knut st. osmundsen
149 */
150ULONG ModuleBase::writeFile(PCSZ pszFilename)
151{
152 pszFilename = pszFilename;
153 return ERROR_NOT_SUPPORTED;
154}
155
156#endif
157
158
159/**
160 * Compare a given filename/modulename with the name of this module.
161 * @returns TRUE: Matching.
162 * FALSE: Non-matching.
163 * @param pszFilename Filename/modulename to match with this module.
164 * @sketch IF filename without path THEN
165 * BEGIN
166 * IF no extention THEN
167 * compare directly with modulename
168 * ELSE
169 * compare input filename with the object filename without path.
170 * END
171 * ELSE
172 * compare input filename with the object filename
173 * return TRUE if equal : FALSE if not.
174 * @status completely implemented.
175 * @author knut st. osmundsen
176 */
177BOOL ModuleBase::queryIsModuleName(PCSZ pszFilename)
178{
179 #ifdef DEBUG
180 if (!fInitTime)
181 {
182 printIPE(("queryIsModuleName should not be called during init!\n"));
183 return FALSE;
184 }
185 #endif
186 if (strchr(pszFilename, '\\') == NULL && strchr(pszFilename,'/') == NULL)
187 { /* use module name - no extention */
188 if (strchr(pszFilename, '.') == NULL)
189 return stricmp(pszFilename, pszModuleName) == 0;
190 else
191 { /* extention */
192 PCSZ psz = strchr(this->pszFilename, '\\');
193 if ((psz = strchr(this->pszFilename, '/')) == NULL)
194 psz = this->pszFilename;
195 else
196 psz++; /* skip '\\' or '/' */
197 return stricmp(pszFilename, psz) == 0;
198 }
199 }
200
201 /* TODO: relative name vs fullname. */
202 return stricmp(pszFilename, this->pszFilename) == 0;
203}
204
205
206/**
207 * Output function for Modules.
208 * @param pszFormat Pointer to format string.
209 * @status completely implemented; tested.
210 * @author knut st. osmundsen
211 */
212VOID ModuleBase::printf(PCSZ pszFormat, ...)
213{
214 va_list arguments;
215
216 if (ulInfoLevel <= ModuleBase::ulInfoLevel)
217 {
218 va_start(arguments, pszFormat);
219 vprintf2(pszFormat, arguments);
220 va_end(arguments);
221 }
222}
223
224
225
Note: See TracBrowser for help on using the repository browser.