YAP 7.1.0
alloc.h
1/*************************************************************************
2* *
3* YAP Prolog %W% %G% *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: alloc.h *
12* Last rev: *
13* mods: *
14* comments: allocating space *
15* *
16*************************************************************************/
17
18#ifndef ALLOC_H
19#define ALLOC_H 1
20
61typedef CELL YAP_SEG_SIZE;
62
63typedef struct FREEB {
64 YAP_SEG_SIZE b_size;
65 struct FREEB *b_next;
66 struct FREEB *b_next_size;
68
69#define K ((Int) 1024)
70
71#define MinBlockSize (sizeof(BlockHeader)+sizeof(YAP_SEG_SIZE))
72#define MaxBlockSize 0xffffff
73#define InUseFlag 0x80000000
74
75#define MaxTmp(USES_REGS1) (MaxBlockSize+1)
76
77/* the following defines are machine dependant and are used to enforce
78 the correct alignment for allocated blocks */
79
80#if SIZEOF_INT_P==4
81#define YAP_ALIGN 3
82#define YAP_ALIGNMASK ((CELL)(-4))
83#else
84#define YAP_ALIGN 7
85#define YAP_ALIGNMASK ((CELL)(-8))
86#endif /* ALIGN_LONGS */
87
88#define AdjustSize(X) ((X+YAP_ALIGN) & YAP_ALIGNMASK)
89
90/* SIZE should be a power of 2 */
91#define ALIGN_SIZE(X,SIZE) (((CELL)(X)+((SIZE)-1)) & ~((SIZE)-1))
92
93/* I'll assume page size is always a power of two */
94#if defined(_WIN32) || defined(__CYGWIN__)
95/* in WIN32 VirtualAlloc works in multiples of 64K */
96#define YAP_ALLOC_SIZE (64*1024)
97#define LGPAGE_SIZE YAP_ALLOC_SIZE
98
99#else
100#define YAP_ALLOC_SIZE Yap_page_size
101#define LGPAGE_SIZE (16*Yap_page_size)
102#endif
103
104#define AdjustPageSize(X) (((X)+ (YAP_ALLOC_SIZE-1))/YAP_ALLOC_SIZE)*YAP_ALLOC_SIZE;
105#define AdjustLargePageSize(X) (((X)+ (LGPAGE_SIZE-1))/LGPAGE_SIZE)*LGPAGE_SIZE;
106
107#define BlockTrailer(b) ((YAP_SEG_SIZE *)b)[((BlockHeader *) b)->b_size]
108
109/* Operating system and architecture dependent page size */
110extern size_t Yap_page_size;
111
112extern void Yap_InitHeap(void *);
113extern UInt Yap_ExtendWorkSpaceThroughHole(UInt);
114extern void Yap_AllocHole(UInt, UInt);
115extern size_t Yap_HeapUsed(void);
116;
117#if USE_SYSTEM_MMAP && ! defined(__CYGWIN__)
118
119#include <sys/types.h>
120#include <sys/mman.h>
121
122#elif USE_SYSTEM_SHM
123
124
125
126#elif USE_SBRK
127
128#if (defined(__svr4__) || defined(__SVR4))
129#include <unistd.h>
130#elif sun
131#include <sys/types.h>
132#include <malloc.h>
133void *sbrk(caddr_t);
134
135typedef unsigned size_t;
136
137extern MALLOC_T malloc(size_t);
138extern void free(MALLOC_T);
139extern MALLOC_T realloc(MALLOC_T,size_t);
140extern MALLOC_T calloc(size_t,size_t);
141
142#endif
143
144
145#else
146
147
148#endif
149
150void Yap_add_memory_hole(ADDR, ADDR);
151
152#define SCRATCH_START_SIZE K64
153#define SCRATCH_INC_SIZE K64
154
164typedef struct scratch_buf_struct_t {
165 void *data;
166 size_t sz;
167 bool in_use;
169
172 void *data;
174 size_t n_of, size_of;
176
177extern bool get_scratch(scratch_struct_t *handle);
178extern bool Yap_get_scratch_buf( scratch_struct_t *handle, size_t nof, size_t each);
179extern bool Yap_realloc_scratch_buf(scratch_struct_t *handle, size_t nof);
180extern bool Yap_release_scratch_buf(scratch_struct_t *handle);
181
183
184
195extern void *Malloc(size_t sz USES_REGS);
196extern void *Realloc(void *buf, size_t sz USES_REGS);
197extern void Free(void *buf USES_REGS);
198
199extern void *MallocAtLevel(size_t sz, int atL USES_REGS);
200#define BaseMalloc(sz) MallocAtLevel(sz, 1)
201extern const void *MallocExportAsRO(const void *blk);
202
203
204#define MBYTE (1024 * 1024)
205
206/* Character types for tokenizer and write.c */
207extern int AllocLevel(void);
208
209#if 0
210#define push_text_stack() \
211 ( fprintf(stderr, " + *** %d %s:%s:%d\n", AllocLevel(), \
212 __FILE__, __FUNCTION__, __LINE__), \
213 push_text_stack__(PASS_REGS1))
214
215 #define pop_text_stack(lvl) \
216 ( fprintf(stderr, " - *** %d %s:%s:%d\n", AllocLevel()-1, __FILE__, \
217 __FUNCTION__, __LINE__), \
218 pop_text_stack__(lvl PASS_REGS))
219
220 #define pop_output_text_stack(lvl,p) \
221 (fprintf(stderr, "<- *** %d %s:%s:%d\n", AllocLevel()-1, __FILE__, \
222 __FUNCTION__, __LINE__), \
223 pop_output_text_stack__(lvl,p))
224#else
225#define push_text_stack() push_text_stack__(PASS_REGS1)
226#define pop_text_stack(lvl) pop_text_stack__(lvl PASS_REGS)
227#define pop_output_text_stack(lvl,p) pop_output_text_stack__(lvl,p PASS_REGS)
228#endif
229
230extern int push_text_stack__(USES_REGS1);
231extern int pop_text_stack__(int lvl USES_REGS);
232
233
234extern void *pop_output_text_stack__(int lvl, const void *ox USES_REGS);
235
236
237#endif
bool is_thread_scratch_buf
the goods
Definition: alloc.h:173
bool in_use
buffer size
Definition: alloc.h:167
size_t n_of
are we using Local_ScratchBuf for this
Definition: alloc.h:174
size_t sz
buffer data
Definition: alloc.h:166
CELL YAP_SEG_SIZE
definitions required by saver/restorer and memory manager
Definition: alloc.h:61
struct scratch_buf_struct_t scratch_sys_struct_t
thread view of the scratch buffer
struct scratch_user_buf_struct_t scratch_struct_t
user view of the scratch buffer
Definition: alloc.h:63
thread view of the scratch buffer
Definition: alloc.h:164
user view of the scratch buffer
Definition: alloc.h:171
void * Malloc(size_t sz USES_REGS)
allocate a temporary text block
Definition: alloc.c:1759