Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

object.h

Go to the documentation of this file.
00001 /* ndk - [ queue.h ]
00002  *
00003  * Basic abstract queue class
00004  *
00005  * (c)2004 dcipher / neuraldk
00006  *           www.neuraldk.org
00007  */
00008 
00020 #ifndef __ndk_object_h__
00021 #define __ndk_object_h__
00022 
00023 #include <list.h>
00024 #include <errorCodes.h>
00025 #include <types.h>
00026 
00027 typedef struct _Object *Object;
00028 typedef struct _ObjectParser *ObjectParser;
00029 typedef struct _ObjectSection *ObjectSection;
00030 
00031 struct _Object
00032 {
00033    String name;
00034    uint8 *base;
00035    uint32 length;
00036    ObjectParser parser;
00037    List sections;
00038    ListIterator sectionsIterator;
00039    List imports;
00040    ListIterator importsIterator;
00041    List exports;
00042    ListIterator exportsIterator;
00043    List relocations;
00044    ListIterator relocationsIterator;
00045    void *privateData;
00046 };
00047 
00048 typedef struct _ObjectSymbol
00049 {
00050    String symbolName;
00051    uint32 symbolId;
00052    uint32 symbolLocation;
00053    uint32 sectionNumber;
00054    ObjectSection section;
00055 }            *ObjectSymbol;
00056 
00057 typedef struct _ObjectRelocation
00058 {
00059    ObjectSymbol symbol;         /* if this is a symbol relocation, this is the import symbol we want */
00060    ObjectSection section;       /* if this is a section relocation, this is the section we want */
00061    uint32 symbolId;             // remove?
00062    uint32 sectionId;            // remove?
00063    ObjectSection sourceSection; /* this is the section where the relocation exists */
00064    uint32 location;
00065    uint8 length;
00066    Boolean relative;
00067 }                *ObjectRelocation;
00068 
00069 struct _ObjectSection
00070 {
00071    String name;
00072    uint32 id;
00073    uint32 offset;
00074    uint32 length;
00075    uint8 alignment;             // byteAlignment = pow(2, alignment)
00076    List symbols;
00077    ListIterator symbolIterator;
00078 };
00079 
00080 // move these into an objectParser file?
00081 typedef ErrorCode(*ObjectParserCreateFunction) (Object obj, void *buffer, uint32 length);
00082 typedef ErrorCode(*ObjectParserDestroyFunction) (Object obj);
00083 
00084 struct _ObjectParser
00085 {
00086    String name;
00087    ObjectParserCreateFunction create;
00088    ObjectParserDestroyFunction destroy;
00089 };
00090 
00095 ErrorCode objectCreate(Object *obj, String name, void *buffer, uint32 length);
00096 ErrorCode objectCreateEmpty(Object *obj);
00097 ErrorCode objectDestroy(Object *obj);
00098 ErrorCode objectGetImportList(Object obj, List *imports);
00099 ErrorCode objectGetExportList(Object obj, List *exports);
00100 ErrorCode objectGetSectionIterator(Object obj, ListIterator * iterator);
00101 ErrorCode objectGetSectionList(Object obj, List *sections);
00102 ErrorCode objectSetBase(Object obj, void *base);
00103 ErrorCode objectLink(Object obj1, Object obj2);
00104 ErrorCode objectDump(Object obj);
00105 
00106 ErrorCode objectParserInit(void);
00107 ErrorCode objectParserFinal(void);
00108 ErrorCode objectParserAdd(String formatName, ObjectParserCreateFunction create,
00109                           ObjectParserDestroyFunction destroy);
00110 ErrorCode objectParserRemove(ObjectParser parser);
00111 
00112 ErrorCode objectParserCreateSection(ObjectSection *section, String name, uint32 id, uint32 offset,
00113                                     uint32 length, uint32 alignment);
00114 ErrorCode objectParserAddSection(Object obj, ObjectSection section);
00115 ErrorCode objectParserGetSection(Object obj, String name, ObjectSection *section);
00116 ErrorCode objectParserGetSectionById(Object obj, uint32 id, ObjectSection *section);
00117 
00118 ErrorCode objectParserCreateSymbol(ObjectSymbol *symbol, String name, uint32 id, uint32 location);
00119 
00120 //ErrorCode objectParsetSymbolSetSection(ObjectSymbol symbol, ObjectSection section);
00121 //ErrorCode objectParserAddSymbol(ObjectSection section, ObjectSymbol symbol);
00122 // above, or below...
00123 ErrorCode objectParserAddImport(Object obj, ObjectSymbol import);
00124 ErrorCode objectParserAddExport(Object obj, ObjectSymbol export, ObjectSection section);
00125 
00126 ErrorCode objectParserGetImportById(Object obj, uint32 id, ObjectSymbol *symbol);
00127 ErrorCode objectParserGetExportById(Object obj, uint32 id, ObjectSymbol *symbol);
00128 
00129 ErrorCode objectParserGetImportByName(Object obj, String name, ObjectSymbol *symbol);
00130 ErrorCode objectParserGetExportByName(Object obj, String name, ObjectSymbol *symbol);
00131 
00144  /* previous
00145     ErrorCode objectParserCreateRelocation(ObjectRelocation *reloc, ObjectSection section, ObjectSymbol symbol,
00146     uint32 location, uint8 length, Boolean relative);
00147   */
00148 ErrorCode objectParserCreateSymbolRelocation(ObjectRelocation *reloc, ObjectSection sourceSection,
00149                                              uint32 offset, ObjectSymbol symbol, uint8 length,
00150                                              Boolean relative);
00151 ErrorCode objectParserCreateSectionRelocation(ObjectRelocation *reloc, ObjectSection sourceSection,
00152                                               uint32 offset, ObjectSection section, uint8 length,
00153                                               Boolean relative);
00154 ErrorCode objectParserAddRelocation(Object obj, ObjectRelocation rec);
00155 
00156 ErrorCode objectParserSetPrivateData(Object obj, void *privateData);
00157 ErrorCode objectParserGetPrivateData(Object obj, void **privateData);
00158 
00159 #endif
00160 
00161 /* @} */

Generated on Wed Mar 22 20:36:33 2006 for ndk by  doxygen 1.4.4