Changeset 490 for Whitix/branches/hybrid

Show
Ignore:
Timestamp:
05/13/08 20:10:53 (5 months ago)
Author:
mwhitworth
Message:

Various cleanups, add comments.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/kernel/module.c

    r483 r490  
    3737void* ModuleSymbolFind(struct Module* module, const char* symName, int type) 
    3838{ 
    39         int i; 
     39        DWORD i; 
    4040        struct ElfSymbol* symbol; 
    4141 
     
    5454 
    5555                /* Handle data? */ 
    56                 return symbol->symValue; 
     56                return (void*)(symbol->symValue); 
    5757        } 
    5858 
     
    153153} 
    154154 
     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 
    155169int ModuleSymbolPrepare(struct Module* module) 
    156170{ 
    157         int i; 
     171        DWORD i; 
    158172        DWORD symSize=module->symTableSize/sizeof(struct ElfSymbol); 
    159173 
     174        /* Iterate through all the symbols in the symbol table, skipping the first entry, 
     175         * which is a NULL symbol. */ 
    160176        for (i=1; i<symSize; i++) 
    161177        { 
    162178                struct ElfSymbol* symbol=&module->symTable[i]; 
     179 
     180                /* Get the symbol's name in the string table. */ 
    163181                char* symName=module->strTable+symbol->symName; 
    164182 
    165183                switch (symbol->symIndex) 
    166184                { 
     185                        /* The symbol is undefined, so we've got to look at the kernel 
     186                         * and module symbols to set its value. */ 
    167187                        case STN_UNDEF: 
    168188                                symbol->symValue=ModuleResolveKernel(symName); 
     
    178198                                break; 
    179199 
     200                        /* Common symbols aren't supported by the module loading code. */ 
    180201                        case STN_COMMON: 
    181202                                printf("Please recompile the module with -fno-common.\n"); 
    182203                                return -ENOENT; 
    183204 
     205                        /* Just add the section base to the symbol value. */ 
    184206                        default: 
    185207                                symbol->symValue+=module->sectionHeaders[symbol->symIndex].shAddr; 
     
    190212} 
    191213 
    192 /* TODO: Create a prepare symbols function, then remove symValue manipulation code here. */ 
    193  
    194214void ModuleSymbolResolve(struct Module* module, char* file, int sec) 
    195215{ 
    196         int i; 
     216        DWORD i; 
    197217        struct ElfReloc* reloc; 
    198218        struct ElfReloc* relTable=(struct ElfReloc*)(file+module->sectionHeaders[sec].shOffset); 
     
    241261                                *size=module->sectionHeaders[i].shSize; 
    242262 
    243                         return module->sectionHeaders[i].shAddr; 
     263                        return (void*)(module->sectionHeaders[i].shAddr); 
    244264                } 
    245265        } 
     
    277297                if (sectionHeaders[i].shType == SEC_TYPE_SYMTAB) 
    278298                { 
    279                         module->symTable=(char*)file+sectionHeaders[i].shOffset; 
     299                        module->symTable=(struct ElfSymbol*)(file+sectionHeaders[i].shOffset); 
    280300                        module->symTableSize=sectionHeaders[i].shSize; 
    281301                } 
     
    293313        /* Copy over the module data into a new image. */ 
    294314        char* dest; 
    295         dest=module->loadAddr; 
     315        dest=(char*)module->loadAddr; 
    296316 
    297317        for (i=0; i<elfHeader->shEntries; i++) 
     
    302322                if (sectionHeaders[i].shFlags & SEC_FLAGS_EXEC) 
    303323                { 
    304                         module->textAddr=dest; 
     324                        module->textAddr=(DWORD)dest; 
    305325                        module->textLength=sectionHeaders[i].shSize; 
    306326                } 
    307327 
    308                 sectionHeaders[i].shAddr=dest; 
     328                sectionHeaders[i].shAddr=(DWORD)dest; 
    309329 
    310330                /* Unless it's a BSS section (or similar), copy the data over. */