2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
2002-11-11 17:38:10 +00:00
|
|
|
* YAP Prolog %W% %G% *
|
2001-04-09 20:54:03 +01:00
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: alloc.h *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: allocating space *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
/* Space Organization:
|
|
|
|
The data areas is divided in the following way:
|
|
|
|
|
|
|
|
Lower Addresses
|
|
|
|
HeapBase \
|
|
|
|
| Atom and code space
|
|
|
|
HeapTop-1 /
|
|
|
|
|
|
|
|
HeapTop \
|
|
|
|
| Free Space
|
2004-01-23 02:23:51 +00:00
|
|
|
HeapMax /
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
GlobalBase-1/
|
|
|
|
|
|
|
|
GlobalBase \
|
|
|
|
| Global Stack
|
|
|
|
H /
|
|
|
|
|
|
|
|
ASP \
|
|
|
|
| Local stack
|
|
|
|
LocalBase /
|
|
|
|
|
|
|
|
TRBase /
|
|
|
|
|
|
|
|
TR \
|
|
|
|
| Trail
|
|
|
|
Higher Adresses
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* definitions required by saver/restorer and memory manager */
|
|
|
|
|
|
|
|
typedef CELL YAP_SEG_SIZE;
|
|
|
|
|
|
|
|
typedef struct FREEB {
|
2003-10-30 11:31:05 +00:00
|
|
|
YAP_SEG_SIZE b_size;
|
|
|
|
struct FREEB *b_next;
|
|
|
|
struct FREEB *b_next_size;
|
|
|
|
} BlockHeader;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-03-26 14:41:45 +00:00
|
|
|
#define K ((Int) 1024)
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#define MinBlockSize (sizeof(BlockHeader)+sizeof(YAP_SEG_SIZE))
|
|
|
|
#define MaxBlockSize 0xffffff
|
2004-09-27 21:45:04 +01:00
|
|
|
#define InUseFlag 0x80000000
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* the following defines are machine dependant and are used to enforce
|
|
|
|
the correct alignment for allocated blocks */
|
|
|
|
|
|
|
|
#if SIZEOF_INT_P==4
|
|
|
|
#define YAP_ALIGN 3
|
2012-12-14 19:35:26 +00:00
|
|
|
#define YAP_ALIGNMASK ((CELL)(-4))
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
|
|
|
#define YAP_ALIGN 7
|
2012-12-14 19:35:26 +00:00
|
|
|
#define YAP_ALIGNMASK ((CELL)(-8))
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* ALIGN_LONGS */
|
|
|
|
|
|
|
|
#define AdjustSize(X) ((X+YAP_ALIGN) & YAP_ALIGNMASK)
|
|
|
|
|
2004-09-03 04:11:09 +01:00
|
|
|
/* SIZE should be a power of 2 */
|
|
|
|
#define ALIGN_SIZE(X,SIZE) (((CELL)(X)+((SIZE)-1)) & ~((SIZE)-1))
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* I'll assume page size is always a power of two */
|
2009-02-09 21:56:40 +00:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
2004-10-26 21:16:18 +01:00
|
|
|
/* in WIN32 VirtualAlloc works in multiples of 64K */
|
2008-01-23 17:57:56 +00:00
|
|
|
#define YAP_ALLOC_SIZE (64*1024)
|
2008-01-28 23:35:04 +00:00
|
|
|
#define LGPAGE_SIZE YAP_ALLOC_SIZE
|
2004-10-26 21:16:18 +01:00
|
|
|
|
|
|
|
#else
|
2008-01-23 17:57:56 +00:00
|
|
|
#define YAP_ALLOC_SIZE Yap_page_size
|
|
|
|
#define LGPAGE_SIZE (16*Yap_page_size)
|
2004-10-26 21:16:18 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
#define AdjustPageSize(X) (((X)+ (YAP_ALLOC_SIZE-1))/YAP_ALLOC_SIZE)*YAP_ALLOC_SIZE;
|
|
|
|
#define AdjustLargePageSize(X) (((X)+ (LGPAGE_SIZE-1))/LGPAGE_SIZE)*LGPAGE_SIZE;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#define BlockTrailer(b) ((YAP_SEG_SIZE *)b)[((BlockHeader *) b)->b_size]
|
|
|
|
|
|
|
|
/* Operating system and architecture dependent page size */
|
2002-11-18 18:18:05 +00:00
|
|
|
extern int Yap_page_size;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2013-04-25 23:15:04 +01:00
|
|
|
void Yap_InitHeap(void *);
|
|
|
|
UInt Yap_ExtendWorkSpaceThroughHole(UInt);
|
|
|
|
void Yap_AllocHole(UInt, UInt);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-03-07 23:07:46 +00:00
|
|
|
#if USE_SYSTEM_MMAP && ! defined(__CYGWIN__)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2014-03-07 23:07:46 +00:00
|
|
|
#elif USE_SYSTEM_SHM
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#elif USE_SBRK
|
|
|
|
|
2001-09-24 19:07:16 +01:00
|
|
|
#if (defined(__svr4__) || defined(__SVR4))
|
2001-04-09 20:54:03 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#elif sun
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
void *sbrk(caddr_t);
|
|
|
|
|
|
|
|
typedef unsigned size_t;
|
|
|
|
|
|
|
|
MALLOC_T malloc(size_t);
|
|
|
|
void free(MALLOC_T);
|
|
|
|
MALLOC_T realloc(MALLOC_T,size_t);
|
|
|
|
MALLOC_T calloc(size_t,size_t);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-05-16 19:37:31 +01:00
|
|
|
void Yap_add_memory_hole(ADDR, ADDR);
|
|
|
|
|
2010-05-11 12:25:49 +01:00
|
|
|
#define SCRATCH_START_SIZE K64
|
|
|
|
#define SCRATCH_INC_SIZE K64
|
2004-01-23 02:23:51 +00:00
|
|
|
|