[plain text]
#ifndef RLD
#include <string.h>
#include <mach-o/ldsyms.h>
#include <mach-o/getsect.h>
#ifndef __OPENSTEP__
#ifdef __LP64__
extern struct mach_header_64 *_NSGetMachExecuteHeader(void);
#else
#include <crt_externs.h>
#endif
#else
#ifdef __DYNAMIC__
#include "mach-o/dyld.h"
#endif
#if !defined(__DYNAMIC__)
#define DECLARE_VAR(var, type) \
extern type var
#define SETUP_VAR(var)
#define USE_VAR(var) var
#else
#define STRINGIFY(a) # a
#define DECLARE_VAR(var, type) \
static type * var ## _pointer = 0
#define SETUP_VAR(var) \
if ( var ## _pointer == 0) { \
_dyld_lookup_and_bind( STRINGIFY(_ ## var), \
(unsigned long *) & var ## _pointer, 0); \
}
#define USE_VAR(var) (* var ## _pointer)
#endif
#endif
unsigned long
get_end(void)
{
#ifndef __LP64__
static struct mach_header *mhp = NULL;
struct segment_command *sgp;
unsigned long i, _end;
#ifndef __OPENSTEP__
if(mhp == NULL)
mhp = _NSGetMachExecuteHeader();
#else
DECLARE_VAR(_mh_execute_header, struct mach_header);
SETUP_VAR(_mh_execute_header);
mhp = (struct mach_header *)(& USE_VAR(_mh_execute_header));
#endif
_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);
#else
static struct mach_header_64 *mhp = NULL;
struct segment_command_64 *sgp;
unsigned long i, _end;
if(mhp == NULL)
mhp = _NSGetMachExecuteHeader();
_end = 0;
sgp = (struct segment_command_64 *)
((char *)mhp + sizeof(struct mach_header_64));
for(i = 0; i < mhp->ncmds; i++){
if(sgp->cmd == LC_SEGMENT_64)
if(sgp->vmaddr + sgp->vmsize > _end)
_end = sgp->vmaddr + sgp->vmsize;
sgp = (struct segment_command_64 *)((char *)sgp + sgp->cmdsize);
}
return(_end);
#endif
}
unsigned long
get_etext(void)
{
#ifndef __LP64__
const struct section *sp;
#else
const struct section_64 *sp;
#endif
sp = getsectbyname(SEG_TEXT, SECT_TEXT);
if(sp)
return(sp->addr + sp->size);
else
return(0);
}
unsigned long
get_edata(void)
{
#ifndef __LP64__
const struct section *sp;
#else
const struct section_64 *sp;
#endif
sp = getsectbyname(SEG_DATA, SECT_DATA);
if(sp)
return(sp->addr + sp->size);
else
return(0);
}
#endif
Generated by GNU enscript 1.6.4.