Beispiel #1
0
/*
 * This routine returns the highest address of the segments in the program (NOT
 * the shared libraries).  It is intended to be used as a stop gap for programs
 * that make UNIX style assumptions about how memory is allocated.  Typicly the
 * asumptions under which this is used is that memory is contiguously allocated
 * by the program's text and data from address 0 with no gaps.  The value of
 * this differs from the value of &_end in a UNIX program in that this routine
 * returns the address of the end of the segment not the end of the last section
 * in that segment as would be the value of the symbol &_end.
 */
unsigned long
get_end(void)
{
    static struct mach_header *mhp = (struct mach_header *)0;
    struct segment_command *sgp;
    unsigned long i, _end;
#ifndef __OPENSTEP__
	if (mhp  == (struct mach_header *)0) {
	    mhp = _NSGetMachExecuteHeader();
	}
#else /* defined(__OPENSTEP__) */
    DECLARE_VAR(_mh_execute_header, struct mach_header);
    SETUP_VAR(_mh_execute_header);

	mhp = (struct mach_header *)(& USE_VAR(_mh_execute_header));
#endif /* __OPENSTEP__ */
	_end = 0;
	sgp = (struct segment_command *)
	      ((char *)mhp + sizeof(struct mach_header));
	for(i = 0; i < mhp->ncmds; i++){
	    if(sgp->cmd == LC_SEGMENT)
		if(sgp->vmaddr + sgp->vmsize > _end)
		    _end = sgp->vmaddr + sgp->vmsize;
	    sgp = (struct segment_command *)((char *)sgp + sgp->cmdsize);
	}
	return(_end);
}
const struct segment_command *
getsegbyname(
char *segname)
{
    struct segment_command *sgp;
    uint32_t i;
#ifndef RLD
#ifndef __OPENSTEP__
    struct mach_header *mhp = _NSGetMachExecuteHeader();
#else /* defined(__OPENSTEP__) */
    static struct mach_header *mhp = NULL;
        DECLARE_VAR(_mh_execute_header, struct mach_header);
        SETUP_VAR(_mh_execute_header);
	mhp = (struct mach_header *)(& USE_VAR(_mh_execute_header));
#endif /* __OPENSTEP__ */
#else /* defined(RLD) */
	mhp = (struct mach_header *)(&_mh_execute_header);
#endif /* defined(RLD) */
        
	sgp = (struct segment_command *)
	      ((char *)mhp + sizeof(struct mach_header));
	for(i = 0; i < mhp->ncmds; i++){
	    if(sgp->cmd == LC_SEGMENT)
		if(strncmp(sgp->segname, segname, sizeof(sgp->segname)) == 0)
		    return(sgp);
	    sgp = (struct segment_command *)((char *)sgp + sgp->cmdsize);
	}
	return(NULL);
}
Beispiel #3
0
const struct section *
getsectbyname(
    const char *segname,
    const char *sectname)
{
#ifndef __OPENSTEP__
    struct mach_header *mhp = _NSGetMachExecuteHeader();
#else /* defined(__OPENSTEP__) */
    static struct mach_header *mhp = NULL;
    DECLARE_VAR(_mh_execute_header, struct mach_header);
    SETUP_VAR(_mh_execute_header);
    mhp = (struct mach_header *)(& USE_VAR(_mh_execute_header));
#endif /* __OPENSTEP__ */
    return(getsectbynamefromheader(mhp, segname, sectname));
}