allow randomization of initial address, this enables testing restore routine.

This commit is contained in:
Vitor Santos Costa 2009-11-18 23:32:00 +00:00
parent 7155fbec22
commit 6c887452e6
2 changed files with 19 additions and 25 deletions

View File

@ -1401,13 +1401,28 @@ void
Yap_InitMemory(UInt Trail, UInt Heap, UInt Stack)
{
UInt pm, sa, ta;
void *addr;
pm = (Trail + Heap + Stack); /* memory to be
* requested */
sa = Stack; /* stack area size */
ta = Trail; /* trail area size */
InitHeap(InitWorkSpace(pm));
#if RANDOMIZE_START_ADDRESS
srand(time(NULL));
UInt x = (rand()% 100)*YAP_ALLOC_SIZE ;
fprintf(stderr,"x=%ulx\n", (unsigned long int)x);
pm += x;
#endif
addr = InitWorkSpace(pm);
#if RANDOMIZE_START_ADDRESS
addr = (char *)addr+x;
pm -= x;
fprintf(stderr,"addr=%p\n", addr);
#endif
InitHeap(addr);
Yap_TrailTop = Yap_HeapBase + pm;
Yap_LocalBase = Yap_TrailTop - ta;

27
H/Yap.h
View File

@ -254,11 +254,13 @@ extern char Yap_Option[20];
#endif
#endif /* !IN_SECOND_QUADRANT */
/* #define RANDOMIZE_START_ADDRESS 1 */
#ifdef USE_SYSTEM_MALLOC
#define HEAP_INIT_BASE 0L
#define AtomBase NULL
#else
#if defined(MMAP_ADDR) && (defined(USE_MMAP) || USE_SHMAT) && !defined(__simplescalar__)
#if defined(MMAP_ADDR) && (defined(USE_MMAP) || USE_SHMAT) && !defined(__simplescalar__) && !defined(RANDOMIZE_START_ADDRESS)
#define HEAP_INIT_BASE (MMAP_ADDR)
#define AtomBase ((char *)MMAP_ADDR)
#else
@ -850,7 +852,6 @@ FunctorOfTerm (Term t)
}
#if (defined(USE_SYSTEM_MALLOC) || USE_DL_MALLOC) && !defined(__LP64__)
#if USE_LOW32_TAGS
inline EXTERN Term MkAtomTerm (Atom);
@ -893,28 +894,6 @@ AtomOfTerm (Term t)
}
#endif
#else
inline EXTERN Term MkAtomTerm (Atom);
inline EXTERN Term
MkAtomTerm (Atom a)
{
return (Term) (TAGGEDA (AtomTag, (CELL) (a) - HEAP_INIT_BASE));
}
inline EXTERN Atom AtomOfTerm (Term t);
inline EXTERN Atom
AtomOfTerm (Term t)
{
return (Atom) (HEAP_INIT_BASE + NonTagPart (t));
}
#endif
inline EXTERN int IsAtomTerm (Term);