home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-28 | 23.2 KB | 1,359 lines |
- head 1.12;
- branch ;
- access ;
- symbols ;
- locks ediger:1.12;
- comment @@;
-
-
- 1.12
- date 94.05.28.16.17.05; author ediger; state Exp;
- branches ;
- next 1.11;
-
- 1.11
- date 94.01.30.16.25.39; author ediger; state Exp;
- branches ;
- next 1.10;
-
- 1.10
- date 93.12.28.23.09.05; author ediger; state Exp;
- branches ;
- next 1.9;
-
- 1.9
- date 93.12.28.23.07.40; author ediger; state Exp;
- branches ;
- next 1.8;
-
- 1.8
- date 93.12.08.00.52.12; author ediger; state Exp;
- branches ;
- next 1.7;
-
- 1.7
- date 93.12.02.00.45.36; author ediger; state Exp;
- branches ;
- next 1.6;
-
- 1.6
- date 93.10.31.21.36.40; author ediger; state Exp;
- branches ;
- next 1.5;
-
- 1.5
- date 93.10.31.16.47.01; author ediger; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 93.10.31.12.48.41; author ediger; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 93.10.28.00.07.08; author ediger; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 93.10.27.23.43.04; author ediger; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 93.10.25.17.59.06; author ediger; state Exp;
- branches ;
- next ;
-
-
- desc
- @definition/implementation of LoadCommand object
- @
-
-
- 1.12
- log
- @added LoadCommand -getUpperAddress and - (struct load_command *)loadCommandAddress
- @
- text
- @#import <LoadCommand.h>
- /*
- * $Log: LoadCommand.m,v $
- Revision 1.11 94/01/30 16:25:39 ediger
- added working version of -(unsigned long)pc method
-
- Revision 1.10 93/12/28 23:09:05 ediger
- removed printfs for memory leak checking.
-
- Revision 1.9 93/12/28 23:07:40 ediger
- Fixed memory leak caused by sections instance var of SegmentCommand
- subclass not getting freed. overrode -free method for that subclass.
- Left in the debug statements
-
- Revision 1.8 93/12/08 00:52:12 ediger
- added some assert()s in accordance with new ideology
-
- Revision 1.7 93/12/02 00:45:36 ediger
- fixed a renamed method (initFromFile: becomes initFromFileNamed:)
-
- Revision 1.6 93/10/31 21:36:40 ediger
- changed initialization of new LoadCommand object from 'new'
- to 'alloc] init]'.
-
- Revision 1.3 93/10/28 00:07:08 ediger
- correct a few typos, add better commentary
-
- Revision 1.2 93/10/27 23:43:04 ediger
- changed to one subclass per type of load command
-
- */
-
- @@implementation LoadCommand
-
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.11 94/01/30 16:25:39 ediger Exp Locker: ediger $";
-
- //M+ LoadCommand +new
- //M-
- + new
- {
- LoadCommand *oNew = [[LoadCommand alloc] init];
- assert(oNew != NULL);
- return oNew;
- }
-
- //M+ LoadCommand +new:
- // Accounts for cheesy polymorphism of Mach-O load commands.
- // Each of them begins with a struct load_command, but
- // a variable amount of stuff follows (and subsumes)
- // each struct load_command.
- //M-
- + new: (caddr_t)loadCommandAddress;
- {
- id oNew = Nil;
- struct load_command *lc = (struct load_command *)loadCommandAddress;
-
- assert(NULL != loadCommandAddress);
-
- switch (lc->cmd)
- {
- case LC_SEGMENT:
- oNew = [[SegmentCommand alloc] init];
- break;
- case LC_IDFVMLIB:
- oNew = [[IdFVMLibCommand alloc] init];
- break;
- case LC_LOADFVMLIB:
- oNew = [[LoadFVMLibCommand alloc] init];
- break;
- case LC_FVMFILE:
- oNew = [[FVMFileCommand alloc] init];
- break;
- case LC_SYMTAB:
- oNew = [[SymTabCommand alloc] init];
- break;
- case LC_SYMSEG:
- oNew = [[SymSegCommand alloc] init];
- break;
- case LC_THREAD:
- oNew = [[ThreadCommand alloc] init];
- break;
- case LC_UNIXTHREAD:
- oNew = [[UnixThreadCommand alloc] init];
- break;
- case LC_IDENT:
- oNew = [[IdentCommand alloc] init];
- break;
- default:
- oNew = [[LoadCommand alloc] init];
- break;
- }
-
- assert(Nil != oNew);
-
- [oNew setLoadCommand:loadCommandAddress];
-
- if (lc->cmd == LC_SEGMENT)
- [oNew fillSections];
-
- return oNew;
- }
-
- //M+ LoadCommand -init
- // Assumes that "self" is already allocated.
- //M-
- - init
- {
- [super init];
- loadCommand = NULL;
- mapped = FALSE;
- otherFile = FALSE;
- return self;
- }
-
- //M+ LoadCommand -free
- //M-
- - free
- {
- [super free];
- return self;
- }
-
- //M+ LoadCommand -setSegmentCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- loadCommand = (struct load_command *)loadCommandAddress;
- return self;
- }
-
- //M+ LoadCommand -isMapped
- // Does the object represent a memory-mapped piece
- // of the file? Probably not.
- //M-
- - (BOOL)isMapped
- {
- return mapped;
- }
-
- //M+ LoadCommand -isThread
- // Does the object represent a thread of some sort.
- // of the file? Again, Probably not.
- //M-
- - (BOOL)isThread
- {
- return FALSE;
- }
-
- //M+ LoadCommand -representsMappedFile
- // Does the object represent a load command
- // that would end up causing some other file
- // to be memory-mapped into the task's address
- // space?
- //M-
- - (BOOL)representsMappedFile
- {
- return otherFile;
- }
-
-
- //M+ LoadCommand -getBaseAddress
- //M-
- - (unsigned long)getBaseAddress
- {
- return -1;
- }
-
- //M+ LoadCommand -getUpperAddress
- //M-
- - (unsigned long)getUpperAddress
- {
- return -1;
- }
-
- //M+ LoadCommand -(unsigned long)commandSize
- //M-
- - (unsigned long)commandSize
- {
- return loadCommand->cmdsize;
- }
-
- //M+ LoadCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "load command";
- }
-
- //M+ LoadCommand - (int)numberOfSections
- // Only struct segment_commands have sections,
- // but it's handy to use this as a flag.
- //M-
- - (int)numberOfSections
- {
- return 0;
- }
-
- //M+ LoadCommand -struct load_command *)loadCommandAddress
- //M-
- - (struct load_command *)loadCommandAddress
- {
- return loadCommand;
- }
-
- @@end
-
-
- @@implementation SegmentCommand
-
- //M+ SegmentCommand -init
- //M-
- - init
- {
- [super init];
- sections = NULL;
- segmentCommand = NULL;
- mapped = TRUE; // struct segment_commands do map
- return self;
- }
-
- //M+ SegmentCommand -free
- // Had to override so as to free sections instance var
- //M-
- - free
- {
- if (NULL != sections)
- free(sections);
- [super free];
- return self;
- }
-
- //M+ SegmentCommand -fillSections
- // Create a quick-to-access array of pointers to
- // the struct sections in this load command.
- //M-
- - fillSections
- {
- assert(segmentCommand != NULL);
- sections
- = (struct section **)malloc(
- sizeof(struct section)*segmentCommand->nsects);
-
- if (sections != NULL)
- { int iCC;
- struct section *spSection
- = (struct section *)((unsigned long)segmentCommand
- + sizeof(struct segment_command));
-
- for (iCC = 0; iCC < segmentCommand->nsects; ++iCC)
- sections[iCC] = spSection++;
- }
-
- return self;
- }
-
- //M+ SegmentCommand -getBaseAddress
- //M-
- - (unsigned long)getBaseAddress
- {
- assert(segmentCommand != NULL);
- return segmentCommand->vmaddr;
- }
-
- //M+ SegmentCommand -getUpperAddress
- //M-
- - (unsigned long)getUpperAddress
- {
- assert(segmentCommand != NULL);
- return segmentCommand->vmaddr + segmentCommand->vmsize;
- }
-
- //M+ SegmentCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- [super setLoadCommand: loadCommandAddress];
- segmentCommand = (struct segment_command *)loadCommandAddress;
- return self;
- }
-
-
- //M+ SegmentCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- assert(segmentCommand != NULL);
- if (segmentCommand->segname == NULL || strlen(segmentCommand->segname) <= 0)
- return "LC_SEGMENT"; // relocatable object files?
- else
- return segmentCommand->segname;
- }
-
- //M+ SegmentCommand -numberOfSections
- //M-
- - (int)numberOfSections
- {
- assert(segmentCommand != NULL);
- return segmentCommand->nsects;
- }
-
-
- //M+ SegmentCommand -(struct section *)getSection:(int)sectionNumber
- //M-
- - (struct section *)getSection:(int)sectionNumber
- {
- assert(segmentCommand != NULL);
- if (sections != NULL && sectionNumber < segmentCommand->nsects)
- return sections[sectionNumber];
-
- return NULL;
- }
-
- @@end
-
- @@implementation LoadFVMLibCommand
-
- //M+ LoadFVMLibCommand -init
- //M-
- - init
- {
- [super init];
- fvmlibCommand = NULL;
- mapped = FALSE;
- otherFile = TRUE;
- theOtherFile = Nil;
- return self;
- }
-
- //M+ LoadFVMLibCommand -getBaseAddress
- //M-
- - (unsigned long)getBaseAddress
- {
- assert(fvmlibCommand != NULL);
- return fvmlibCommand->fvmlib.header_addr;
- }
-
- //M+ LoadFVMLibCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- [super setLoadCommand: loadCommandAddress];
- fvmlibCommand = (struct fvmlib_command *)loadCommandAddress;
- return self;
- }
-
- //M+ LoadFVMLibCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- assert(fvmlibCommand != NULL);
- return (char *)((unsigned long)fvmlibCommand
- + fvmlibCommand->fvmlib.name.offset);
- }
-
- //M+ LoadFVMLibCommand -loadOtherFile
- //M-
- - loadOtherFile
- {
- if (fvmlibCommand != NULL)
- { theOtherFile = [[MachOFile alloc] init];
- [theOtherFile fillFromFileNamed:[self commandName]];
- }
-
- return self;
- }
-
- //M+ LoadFVMLibCommand -otherFile
- //M-
- - otherFile
- {
- return theOtherFile;
- }
-
- //M+ LoadFVMLibCommand -free
- // Had to override this to ditch any other mapped files.
- //M-
- - free
- {
- if (theOtherFile != Nil)
- [theOtherFile free];
-
- [super free];
-
- return self;
- }
-
- @@end
-
- @@implementation IdFVMLibCommand
-
- //M+ IdFVMLibCommand -init
- //M-
- - init
- {
- [super init];
- namebuf = NULL;
- mapped = FALSE;
- return self;
- }
-
- //M+ IdFVMLibCommand -commandName
- // This is cheesy, but it separates the ident sections from
- // the mapped sections.
- //M-
- - (char *)commandName
- {
- char *filename;
- #define IDENT_PHRASE "FVM Lib ident: "
-
- if (namebuf != NULL)
- free(namebuf);
-
- filename = [super commandName];
-
- namebuf = malloc(strlen(filename) + strlen(IDENT_PHRASE) + 1);
-
- if (namebuf != NULL)
- strcat(strcpy(namebuf, IDENT_PHRASE), filename);
-
- return namebuf;
- }
-
- //M+ IdFVMLibCommand -free
- // Possibly this object has allocated some memory for its
- // own purposes. Free it.
- //M-
- - free
- {
- if (namebuf != NULL)
- free(namebuf);
-
- [super free];
-
- return self;
- }
-
- @@end
-
- @@implementation FVMFileCommand
-
- //M+ FVMFileCommand -init
- /*
- * The fvmfile_command contains a reference to a file to be loaded at the
- * specified virtual address. (Presently, this command is reserved for NeXT
- * internal use. The kernel ignores this command when loading a program into
- * memory).
- */
- //M-
- - init
- {
- [super init];
- mapped = TRUE;
- return self;
- }
-
- //M+ FVMFileCommand -getBaseAddress
- //M-
- - (unsigned long)getBaseAddress
- {
- assert(fvmFileCommand != NULL);
- return fvmFileCommand->header_addr; // address of FVM file's header
- }
-
- //M+ FVMFileCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- [super setLoadCommand: loadCommandAddress];
- fvmFileCommand = (struct fvmfile_command *)loadCommandAddress;
- return self;
- }
-
- //M+ FVMFileCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- assert(fvmFileCommand != NULL);
- return (char *)((unsigned long)fvmFileCommand
- + fvmFileCommand->name.offset);
- }
-
- @@end
-
- @@implementation SymTabCommand
-
- //M+ SymTabCommand -init
- //M-
- - init
- {
- [super init];
- mapped = FALSE;
- return self;
- }
-
- //M+ SymTabCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- [super setLoadCommand: loadCommandAddress];
- symTabCommand = (struct symtab_command *)loadCommandAddress;
- return self;
- }
-
- //M+ SymTabCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "LC_SYMTAB";
- }
- @@end
-
- @@implementation SymSegCommand
-
- //M+ SymSegCommand -init
- //M-
- - init
- {
- [super init];
- mapped = FALSE;
- return self;
- }
-
- //M+ SymSegCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- [super setLoadCommand: loadCommandAddress];
- symSegCommand = (struct symseg_command *)loadCommandAddress;
- return self;
- }
-
- //M+ SymSegCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "LC_SYMSEG";
- }
- @@end
-
- @@implementation ThreadCommand
- //M+ ThreadCommand +new
-
- //M+ ThreadCommand -init
- //M-
- - init
- {
- [super init];
- mapped = FALSE;
- return self;
- }
-
- //M+ ThreadCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- assert(loadCommandAddress != NULL);
- [super setLoadCommand: loadCommandAddress];
- threadCommand = (struct thread_command *)loadCommandAddress;
- return self;
- }
-
- //M+ ThreadCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "LC_THREAD";
- }
-
- //M+ ThreadCommand -(BOOL)isThread
- //M-
- - (BOOL)isThread
- {
- return TRUE;
- }
-
- - (unsigned long)pc
- {
- struct thread_state_flavor *spThreadStateFlavor;
- unsigned long lNextAddress;
- unsigned int irPC = -1;
-
- spThreadStateFlavor =
- (struct thread_state_flavor *)((unsigned long)threadCommand
- + sizeof(struct thread_command));
-
- lNextAddress = (unsigned long)spThreadStateFlavor
- + sizeof(struct thread_state_flavor);
-
- switch(spThreadStateFlavor->flavor)
- {
- case M68K_THREAD_STATE_REGS:
- irPC = ((struct m68k_thread_state_regs *)lNextAddress)->pc;
- break;
- case M68K_THREAD_STATE_68882:
- irPC = ((struct m68k_thread_state_68882 *)lNextAddress)->iar;
- break;
- case M68K_THREAD_STATE_USER_REG:
- irPC = ((struct m68k_thread_state_user_reg *)lNextAddress)->user_reg;
- break;
- case i386_THREAD_STATE:
- irPC = ((i386_thread_state_t *)lNextAddress)->eip;
- break;
- }
-
- return irPC;
- }
-
- @@end
-
- @@implementation UnixThreadCommand
-
- //M+ UnixThreadCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "LC_UNIXTHREAD";
- }
-
- @@end
-
- @@implementation IdentCommand
-
- //M+ IdentCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return "LC_IDENT";
- }
- @@end
- @
-
-
- 1.11
- log
- @added working version of -(unsigned long)pc method
- @
- text
- @d4 3
- d35 1
- a35 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.10 93/12/28 23:09:05 ediger Exp Locker: ediger $";
- d169 7
- d198 9
- @
-
-
- 1.10
- log
- @removed printfs for memory leak checking.
- @
- text
- @d4 3
- d32 1
- a32 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.9 93/12/28 23:07:40 ediger Exp Locker: ediger $";
- d138 9
- d554 40
- d604 1
- @
-
-
- 1.9
- log
- @Fixed memory leak caused by sections instance var of SegmentCommand
- subclass not getting freed. overrode -free method for that subclass.
- Left in the debug statements
- @
- text
- @d4 5
- d29 1
- a29 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.8 93/12/08 00:52:12 ediger Exp Locker: ediger $";
- a88 3
- printf("LoadCommand +new:0x%x => 0x%x\n", loadCommandAddress,
- oNew);
-
- a101 1
- printf("LoadCommand -init 0x%lx\n", self);
- a112 1
- printf("LoadCommand -free 0x%lx\n", (unsigned long)self);
- a183 1
- printf("SegmentCommand -init 0x%lx\n", self);
- a211 1
- printf("SegmentCommand - fillSections, 0x%x\n", sections);
- a291 1
- printf("LoadFVMLibCommand -init 0x%lx\n", self);
- a366 1
- printf("IdFVMLibCommand -init 0x%lx\n", self);
- a422 1
- printf("FVMFileCommand -init 0x%lx\n", self);
- a462 1
- printf("SymTabCommand -init 0x%lx\n", self);
- a490 1
- printf("SymSegCommand -init 0x%lx\n", self);
- a520 1
- printf("ThreadCommand -init 0x%lx\n", self);
- @
-
-
- 1.8
- log
- @added some assert()s in accordance with new ideology
- @
- text
- @d4 3
- d24 1
- a24 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.7 93/12/02 00:45:36 ediger Exp Locker: ediger $";
- d84 3
- d100 1
- d112 1
- d184 1
- d192 11
- d213 1
- d294 1
- d336 1
- a336 1
- [theOtherFile initFromFileNamed:[self commandName]];
- d370 1
- d427 1
- d468 1
- d497 1
- d528 1
- @
-
-
- 1.7
- log
- @fixed a renamed method (initFromFile: becomes initFromFileNamed:)
- @
- text
- @d4 3
- d21 1
- a21 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.6 93/10/31 21:36:40 ediger Exp Locker: ediger $";
- d28 1
- d43 2
- d79 2
- d113 1
- d189 1
- d211 1
- d219 1
- d227 1
- d238 1
- d249 1
- d258 1
- d285 1
- d293 1
- d303 1
- d413 1
- d421 1
- d431 1
- d481 1
- d511 1
- @
-
-
- 1.6
- log
- @changed initialization of new LoadCommand object from 'new'
- to 'alloc] init]'.
- @
- text
- @d4 4
- d18 1
- a18 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.3 93/10/28 00:07:08 ediger Exp Locker: ediger $";
- d295 1
- a295 1
- [theOtherFile initFromFile:[self commandName]];
- @
-
-
- 1.5
- log
- @ditched '+new' methods for all LoadCommand subclasses. They were dead weight anyway.
- @
- text
- @d65 1
- a65 1
- oNew = [LoadCommand new];
- @
-
-
- 1.4
- log
- @some assorted tiny typo corrections
- @
- text
- @d33 1
- a33 1
- struct load_command *spLC = (struct load_command *)loadCommandAddress;
- d35 1
- a35 1
- switch (spLC->cmd)
- d38 1
- a38 1
- oNew = [SegmentCommand new];
- d41 1
- a41 1
- oNew = [IdFVMLibCommand new];
- d44 1
- a44 1
- oNew = [LoadFVMLibCommand new];
- d47 1
- a47 1
- oNew = [FVMFileCommand new];
- d50 1
- a50 1
- oNew = [SymTabCommand new];
- d53 1
- a53 1
- oNew = [SymSegCommand new];
- d56 1
- a56 1
- oNew = [ThreadCommand new];
- d59 1
- a59 1
- oNew = [UnixThreadCommand new];
- d62 1
- a62 1
- oNew = [IdentCommand new];
- d71 1
- a71 1
- if (spLC->cmd == LC_SEGMENT)
- a158 8
- //M+ SegmentCommand +new
- //M-
- + new
- {
- SegmentCommand *oNew = [[SegmentCommand alloc] init];
- return oNew;
- }
-
- a192 20
-
- #ifdef DOO_DOO
- //M+ SegmentCommand -printSections
- //M-
- - printSections
- {
- if (sections != NULL)
- { int iCC;
- for (iCC = segmentCommand->nsects - 1; iCC >= 0; --iCC)
- {
- printf("\t%s in seg %s - 0x%lx, %lu bytes\n",
- sections[iCC]->sectname, sections[iCC]->segname,
- sections[iCC]->addr, sections[iCC]->size);
- }
- }
-
- return self;
- }
- #endif
-
- a248 8
- //M+ LoadFVMLibCommand +new
- //M-
- + new
- {
- LoadFVMLibCommand *oNew = [[LoadFVMLibCommand alloc] init];
- return oNew;
- }
-
- a320 8
- //M+ IdFVMLibCommand +new
- //M-
- + new
- {
- IdFVMLibCommand *oNew = [[IdFVMLibCommand alloc] init];
- return oNew;
- }
-
- a370 8
- //M+ FVMFileCommand +new
- //M-
- + new
- {
- FVMFileCommand *oNew = [[FVMFileCommand alloc] init];
- return oNew;
- }
-
- a412 7
- //M+ SymTabCommand +new
- //M-
- + new
- {
- SymTabCommand *oNew = [[SymTabCommand alloc] init];
- return oNew;
- }
- a440 7
- //M+ SymSegCommand +new
- //M-
- + new
- {
- SymSegCommand *oNew = [[SymSegCommand alloc] init];
- return oNew;
- }
- a469 6
- //M-
- + new
- {
- ThreadCommand *oNew = [[ThreadCommand alloc] init];
- return oNew;
- }
- a497 7
- //M+ ThreadCommand +new
- //M-
- + new
- {
- UnixThreadCommand *oNew = [[UnixThreadCommand alloc] init];
- return oNew;
- }
- a507 7
- //M+ IdentCommand +new
- //M-
- + new
- {
- IdentCommand *oNew = [[IdentCommand alloc] init];
- return oNew;
- }
- a515 46
-
- #ifdef BOOGER
- @@implementation GenericCommand
-
- //M+ GenericCommand +new
- //M-
- + new
- {
- GenericCommand *oNew = [[GenericCommand alloc] init];
- return oNew;
- }
-
- //M+ GenericCommand -init
- //M-
- - init
- {
- [super init];
- mapped = FALSE;
- return self;
- }
-
- //M+ GenericCommand -getBaseAddress
- //M-
- - (unsigned long)getBaseAddress
- {
- return GenericCommand->vmaddr;
- }
-
- //M+ GenericCommand -setLoadCommand
- //M-
- - setLoadCommand: (caddr_t)loadCommandAddress;
- {
- [super setLoadCommand: loadCommandAddress];
- GenericCommand = (struct generic_command *)loadCommandAddress;
- return self;
- }
-
- //M+ GenericCommand -(char *)commandName
- //M-
- - (char *)commandName
- {
- return GenericCommand->segname;
- }
-
- @@end
- #endif
- @
-
-
- 1.3
- log
- @correct a few typos, add better commentary
- @
- text
- @d4 3
- d14 1
- a14 1
- static char rcsident[] = "@@(#) $Id: LoadCommand.m,v 1.2 93/10/27 23:43:04 ediger Exp Locker: ediger $";
- d147 4
- d202 1
- d219 1
- d291 1
- a291 1
- mapped = TRUE;
- d333 1
- a333 1
- //M+ LoadFVMLibCommand -loadOtherFile
- d424 6
- @
-
-
- 1.2
- log
- @changed to one subclass per type of load command
- @
- text
- @d3 4
- a6 1
- * $Log$
- d11 1
- a11 1
- static char rcsident[] = "@@(#) $Id$";
- d22 1
- a22 1
- // Cheesy polymorphism of Mach-O load commands.
- d25 1
- a25 1
- // ecah struct load_command.
- d103 2
- d112 4
- d141 1
- a141 20
- /*
- switch (loadCommand->lc.cmd) {
- case LC_THREAD:
- bpName = "LC_THREAD";
- break;
- case LC_UNIXTHREAD:
- bpName = "LC_UNIXTHREAD";
- break;
- case LC_IDENT:
- bpName = "LC_IDENT";
- break;
- case LC_PREPAGE:
- bpName = "LC_PREPAGE";
- break;
- default:
- bpName = "Bad cmd field";
- break;
- }
- */
- return "mere load_command";
- d167 1
- a167 2
- nextSection = 0;
- mapped = TRUE;
- d172 2
- d240 4
- a243 1
- return segmentCommand->segname;
- d367 2
- d389 1
- a389 1
- // Possibly this object has allocated some memory for it's
- d427 1
- a427 1
- return fvmFileCommand->header_addr;
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d2 3
- a4 1
- #import <stdio.h>
- d6 1
- a6 5
- // This is a bit grosser than it could be. The load commands in a
- // Mach-O file header aren't amenable to the "subclassing" as Objective-C
- // sees it. The variable part of the struct is based on the "cmd" field
- // of a struct load_command. The load_command part becomes the first
- // fields of the type of command specified in cmd.
- d8 1
- d10 1
- a10 3
- @@implementation LoadCommand
-
- //M+ +new
- d18 54
- a71 1
- //M+ -init
- d78 2
- a79 1
- sections = NULL;
- d83 1
- a83 1
- //M+ -free
- d91 1
- a91 1
- //M+ -setSegmentCommand
- d95 3
- a97 1
- loadCommand = (union segment_hdr *)loadCommandAddress;
- d99 6
- a104 2
- if (loadCommand != NULL && loadCommand->lc.cmd == LC_SEGMENT)
- [self fillSections];
- d106 5
- a110 1
- return self;
- d114 1
- a114 1
- //M+ -fillSections
- d116 68
- d188 1
- a188 1
- sizeof(struct section)*loadCommand->segmentc.nsects);
- d193 1
- a193 1
- = (struct section *)((unsigned long)loadCommand
- d196 1
- a196 1
- for (iCC = 0; iCC < loadCommand->segmentc.nsects; ++iCC)
- d204 1
- a204 1
- //M+ -printSections
- d210 1
- a210 1
- for (iCC = loadCommand->segmentc.nsects - 1; iCC >= 0; --iCC)
- d221 1
- a221 2
-
- //M+ -getBaseAddress
- d225 2
- a226 1
- unsigned long lrBaseAddress = 0;
- d228 6
- a233 6
- if (loadCommand != NULL)
- {
- switch (loadCommand->lc.cmd) {
- case LC_SEGMENT:
- lrBaseAddress = loadCommand->segmentc.vmaddr;
- break;
- d235 8
- a242 4
- case LC_LOADFVMLIB:
- case LC_IDFVMLIB:
- lrBaseAddress = loadCommand->fvmlibc.fvmlib.header_addr;
- break;
- a243 3
- case LC_FVMFILE:
- lrBaseAddress = loadCommand->fvmfilec.header_addr;
- break;
- d245 6
- a250 10
- case LC_SYMTAB:
- case LC_SYMSEG:
- case LC_THREAD:
- case LC_UNIXTHREAD:
- case LC_IDENT:
- case LC_PREPAGE:
- default:
- lrBaseAddress = -1;
- }
- }
- d252 5
- a256 1
- return lrBaseAddress;
- d259 2
- a260 1
- //M+ - (unsigned long)commandSize
- d262 1
- a262 1
- - (unsigned long)commandSize
- d264 4
- a267 1
- return loadCommand->lc.cmdsize;
- d270 5
- a274 1
- //M+ - (char *)commandName
- d276 36
- d314 3
- a316 1
- char *bpName = NULL;
- d318 7
- a324 34
- switch (loadCommand->lc.cmd) {
- case LC_SEGMENT:
- bpName = loadCommand->segmentc.segname;
- break;
- case LC_SYMTAB:
- bpName = "LC_SYMTAB";
- break;
- case LC_SYMSEG:
- bpName = "LC_SYMSEG";
- break;
- case LC_THREAD:
- bpName = "LC_THREAD";
- break;
- case LC_UNIXTHREAD:
- bpName = "LC_UNIXTHREAD";
- break;
- case LC_LOADFVMLIB:
- case LC_IDFVMLIB:
- bpName = (char *)((unsigned long)loadCommand
- + loadCommand->fvmlibc.fvmlib.name.offset);
- break;
- case LC_IDENT:
- bpName = "LC_IDENT";
- break;
- case LC_FVMFILE:
- bpName = (char *)((unsigned long)loadCommand
- + loadCommand->fvmfilec.name.offset);
- break;
- case LC_PREPAGE:
- bpName = "LC_PREPAGE";
- break;
- default:
- bpName = "Bad cmd field";
- break;
- d326 2
- a327 2
-
- return bpName;
- d330 1
- a330 3
- //M+ -compareBaseAddress:
- // This didn't work well with the SortedList class.
- // I ended up hacking SortedList to handle unsigned longs.
- d332 1
- a332 2
- /*
- - (int)compareBaseAddress:anotherSegment
- d334 2
- a335 2
- int irComparison;
- unsigned long lBaseAddress = [anotherSegment getBaseAddress];
- d337 7
- d345 1
- a345 3
- if (lBaseAddress == -1)
- irComparison = 1;
- else {
- d347 2
- a348 9
- switch (loadCommand->lc.cmd) {
- case LC_SEGMENT:
- if (loadCommand->segmentc.vmaddr > lBaseAddress)
- irComparison = 1;
- else if (loadCommand->segmentc.vmaddr == lBaseAddress)
- irComparison = 0;
- else if (loadCommand->segmentc.vmaddr < lBaseAddress)
- irComparison = -1;
- break;
- d350 1
- a350 9
- case LC_LOADFVMLIB:
- case LC_IDFVMLIB:
- if (loadCommand->fvmlibc.fvmlib.header_addr > lBaseAddress)
- irComparison = 1;
- else if (loadCommand->fvmlibc.fvmlib.header_addr == lBaseAddress)
- irComparison = 0;
- else if (loadCommand->fvmlibc.fvmlib.header_addr < lBaseAddress)
- irComparison = -1;
- break;
- d352 1
- a352 8
- case LC_FVMFILE:
- if (loadCommand->fvmfilec.header_addr > lBaseAddress)
- irComparison = 1;
- else if (loadCommand->fvmfilec.header_addr == lBaseAddress)
- irComparison = 0;
- else if (loadCommand->fvmfilec.header_addr < lBaseAddress)
- irComparison = -1;
- break;
- d354 7
- a360 4
- default:
- irComparison = 1;
- }
- }
- d362 8
- a369 1
- return irComparison;
- d371 266
- a636 1
- */
- @
-