Changeset 490 for Whitix/branches/hybrid
- Timestamp:
- 05/13/08 20:10:53 (5 months ago)
- Files:
-
- 1 modified
-
Whitix/branches/hybrid/kernel/module.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/hybrid/kernel/module.c
r483 r490 37 37 void* ModuleSymbolFind(struct Module* module, const char* symName, int type) 38 38 { 39 inti;39 DWORD i; 40 40 struct ElfSymbol* symbol; 41 41 … … 54 54 55 55 /* Handle data? */ 56 return symbol->symValue;56 return (void*)(symbol->symValue); 57 57 } 58 58 … … 153 153 } 154 154 155 /*********************************************************************** 156 * 157 * FUNCTION: ModuleSymbolPrepare 158 * 159 * DESCRIPTION: Iterate through the symbol table and relocate them to the 160 * base address by altering their symValue, ready for 161 * ModuleSymbolResolve to update the relocations. 162 * 163 * PARAMETERS: module - the module's whose symbols are to be relocated. 164 * 165 * RETURNS: 0 on success, -ENOENT on an invalid symbol. 166 * 167 ***********************************************************************/ 168 155 169 int ModuleSymbolPrepare(struct Module* module) 156 170 { 157 inti;171 DWORD i; 158 172 DWORD symSize=module->symTableSize/sizeof(struct ElfSymbol); 159 173 174 /* Iterate through all the symbols in the symbol table, skipping the first entry, 175 * which is a NULL symbol. */ 160 176 for (i=1; i<symSize; i++) 161 177 { 162 178 struct ElfSymbol* symbol=&module->symTable[i]; 179 180 /* Get the symbol's name in the string table. */ 163 181 char* symName=module->strTable+symbol->symName; 164 182 165 183 switch (symbol->symIndex) 166 184 { 185 /* The symbol is undefined, so we've got to look at the kernel 186 * and module symbols to set its value. */ 167 187 case STN_UNDEF: 168 188 symbol->symValue=ModuleResolveKernel(symName); … … 178 198 break; 179 199 200 /* Common symbols aren't supported by the module loading code. */ 180 201 case STN_COMMON: 181 202 printf("Please recompile the module with -fno-common.\n"); 182 203 return -ENOENT; 183 204 205 /* Just add the section base to the symbol value. */ 184 206 default: 185 207 symbol->symValue+=module->sectionHeaders[symbol->symIndex].shAddr; … … 190 212 } 191 213 192 /* TODO: Create a prepare symbols function, then remove symValue manipulation code here. */193 194 214 void ModuleSymbolResolve(struct Module* module, char* file, int sec) 195 215 { 196 inti;216 DWORD i; 197 217 struct ElfReloc* reloc; 198 218 struct ElfReloc* relTable=(struct ElfReloc*)(file+module->sectionHeaders[sec].shOffset); … … 241 261 *size=module->sectionHeaders[i].shSize; 242 262 243 return module->sectionHeaders[i].shAddr;263 return (void*)(module->sectionHeaders[i].shAddr); 244 264 } 245 265 } … … 277 297 if (sectionHeaders[i].shType == SEC_TYPE_SYMTAB) 278 298 { 279 module->symTable=( char*)file+sectionHeaders[i].shOffset;299 module->symTable=(struct ElfSymbol*)(file+sectionHeaders[i].shOffset); 280 300 module->symTableSize=sectionHeaders[i].shSize; 281 301 } … … 293 313 /* Copy over the module data into a new image. */ 294 314 char* dest; 295 dest= module->loadAddr;315 dest=(char*)module->loadAddr; 296 316 297 317 for (i=0; i<elfHeader->shEntries; i++) … … 302 322 if (sectionHeaders[i].shFlags & SEC_FLAGS_EXEC) 303 323 { 304 module->textAddr= dest;324 module->textAddr=(DWORD)dest; 305 325 module->textLength=sectionHeaders[i].shSize; 306 326 } 307 327 308 sectionHeaders[i].shAddr= dest;328 sectionHeaders[i].shAddr=(DWORD)dest; 309 329 310 330 /* Unless it's a BSS section (or similar), copy the data over. */
