1 /*************************************************************************
2 *									 *
3 *	 YAP Prolog 	%W% %G% 					 *
4 *	Yap Prolog was developed at NCCUP - Universidade do Porto	 *
5 *									 *
6 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997	 *
7 *									 *
8 **************************************************************************
9 *									 *
10 * File:		YapHeap.h      						 *
11 * mods:									 *
12 * comments:	Heap Init Structure					 *
13 * version:      $Id: Heap.h,v 1.136 2008-08-08 14:05:34 vsc Exp $	 *
14 *************************************************************************/
15 
16 /* information that can be stored in Code Space */
17 
18 #ifndef HEAP_H
19 #define HEAP_H 1
20 
21 #if LOW_PROF
22 #include <stdio.h>
23 #endif
24 
25 typedef int (*SWI_PutFunction)(int, void *);
26 typedef int (*SWI_GetFunction)(void *);
27 typedef int (*SWI_PutWideFunction)(int, void *);
28 typedef int (*SWI_GetWideFunction)(void *);
29 typedef int (*SWI_CloseFunction)(void *);
30 typedef int (*SWI_FlushFunction)(void *);
31 typedef int (*SWI_PLGetStreamFunction)(void *);
32 typedef int (*SWI_PLGetStreamPositionFunction)(void *);
33 
34 #include "../include/dswiatoms.h"
35 
36 #ifndef INT_KEYS_DEFAULT_SIZE
37 #define INT_KEYS_DEFAULT_SIZE 256
38 #endif
39 
40 #if USE_DL_MALLOC
41 
42 #define MAX_DLMALLOC_HOLES 32
43 
44 typedef struct memory_hole {
45   ADDR start;
46   ADDR end;
47 } memory_hole_type;
48 #endif
49 
50 typedef struct swi_reverse_hash {
51   ADDR key;
52   Int pos;
53 } swi_rev_hash;
54 
55 #define GC_MAVARS_HASH_SIZE 512
56 
57 typedef struct gc_ma_hash_entry_struct {
58   UInt timestmp;
59 #ifdef TABLING
60   tr_fr_ptr loc;
61   struct gc_ma_hash_entry_struct *more;
62 #endif
63   CELL* addr;
64   struct gc_ma_hash_entry_struct *next;
65 } gc_ma_hash_entry;
66 
67 typedef void (*HaltHookFunc)(int, void *);
68 
69 typedef struct halt_hook {
70   void * environment;
71   HaltHookFunc hook;
72   struct halt_hook *next;
73 } halt_hook_entry;
74 
75 int	STD_PROTO(Yap_HaltRegisterHook,(HaltHookFunc, void *));
76 
77 typedef struct atom_hash_entry {
78 #if defined(YAPOR) || defined(THREADS)
79   rwlock_t AERWLock;
80 #endif
81   Atom Entry;
82 } AtomHashEntry;
83 
84 typedef struct reduction_counters {
85   YAP_ULONG_LONG reductions;
86   YAP_ULONG_LONG reductions_retries;
87   YAP_ULONG_LONG retries;
88   int reductions_on;
89   int reductions_retries_on;
90   int retries_on;
91 } red_counters;
92 
93 typedef struct scratch_block_struct {
94   char *ptr;
95   UInt sz, msz;
96 } scratch_block;
97 
98 typedef struct record_list {
99   /* a list of dbterms associated with a clause */
100   struct DB_TERM *dbrecord;
101   struct record_list *next_rec, *prev_rec;
102 } DBRecordList;
103 
104 typedef struct restore_info {
105   Int base_diff;
106   Int cl_diff;
107   Int g_diff;
108   Int g_diff0;
109   Int h_diff;
110   Int l_diff;
111   Int tr_diff;
112   Int x_diff;
113   Int delay_diff;
114   CELL *old_ASP;
115   CELL *old_LCL0;
116   CELL *g_split;
117   tr_fr_ptr old_TR;
118   CELL *old_GlobalBase;
119   CELL *old_H;
120   CELL *old_H0;
121   ADDR old_TrailBase;
122   ADDR old_TrailTop;
123   ADDR old_HeapBase;
124   ADDR old_HeapTop;
125 } restoreinfo;
126 
127 /* SWI Emulation */
128 #define SWI_BUF_SIZE 512
129 #define SWI_TMP_BUF_SIZE 2*SWI_BUF_SIZE
130 #define SWI_BUF_RINGS 16
131 
132 #ifdef THREADS
133 typedef struct thandle {
134   int in_use;
135   int zombie;
136   UInt ssize;
137   UInt tsize;
138   UInt sysize;
139   void *stack_address;
140   Term tdetach;
141   Term  cmod, texit_mod;
142   struct DB_TERM *tgoal, *texit;
143   int id;
144   int ret;
145   REGSTORE *default_yaam_regs;
146   REGSTORE *current_yaam_regs;
147   struct pred_entry *local_preds;
148   pthread_t pthread_handle;
149   int ref_count;
150 #ifdef LOW_LEVEL_TRACER
151   long long int thread_inst_count;
152   int been_here1;
153   int been_here2;
154 #endif
155 #ifdef DEBUG
156   int been_here;
157 #endif
158   pthread_mutex_t tlock;
159   pthread_mutex_t tlock_status;
160 #if HAVE_GETRUSAGE||defined(_WIN32)
161   struct timeval *start_of_timesp;
162   struct timeval *last_timep;
163 #endif
164 } yap_thandle;
165 #endif
166 
167 typedef int   (*Agc_hook)(Atom);
168 
169 /*******************
170   this is the data base: everything here should be possible to restore
171 ********************/
172 typedef struct various_codes {
173   /* memory allocation and management */
174   special_functors funcs;
175 
176 #include "hstruct.h"
177 
178 } all_heap_codes;
179 
180 #include "hglobals.h"
181 
182 #if defined(YAPOR) && !defined(THREADS)
183 extern struct worker_shared *Yap_global;
184 #else
185 extern struct worker_shared Yap_Global;
186 #define Yap_global (&Yap_Global)
187 #endif
188 
189 #if defined(YAPOR) || defined(THREADS)
190 #if defined(THREADS)
191 extern struct worker_local	Yap_WLocal[MAX_AGENTS];
192 #else
193 extern struct worker_local	*Yap_WLocal;
194 #endif
195 #define WL (Yap_WLocal+worker_id)
196 #define FOREIGN_WL(wid) (Yap_WLocal+(wid))
197 #else
198 extern struct worker_local	Yap_WLocal;
199 #define WL (&Yap_WLocal)
200 #define FOREIGN_WL(wid) (&Yap_WLocal)
201 #endif
202 
203 
204 #ifdef USE_SYSTEM_MALLOC
205 extern struct various_codes *Yap_heap_regs;
206 #else
207 #define Yap_heap_regs  ((all_heap_codes *)HEAP_INIT_BASE)
208 #endif
209 
210 #include "dhstruct.h"
211 #include "dglobals.h"
212 
213 /*******************
214   these are the global variables: they need not be restored...
215 ********************/
216 
217 #define UPDATE_MODE_IMMEDIATE          0
218 #define UPDATE_MODE_LOGICAL            1
219 #define UPDATE_MODE_LOGICAL_ASSERT     2
220 
221 
222 
223 
224 /* initially allow for files with up to 1024 predicates. This number
225    is extended whenever needed */
226 #define  InitialConsultCapacity    1024
227 
228 
229 #if (defined(USE_SYSTEM_MALLOC) && HAVE_MALLINFO)||USE_DL_MALLOC
230 UInt STD_PROTO(Yap_givemallinfo, (void));
231 #endif
232 
233 ADDR    STD_PROTO(Yap_ExpandPreAllocCodeSpace, (UInt, void *, int));
234 #define Yap_ReleasePreAllocCodeSpace(x)
235 ADDR    STD_PROTO(Yap_InitPreAllocCodeSpace, (void));
236 EXTERN inline ADDR
Yap_PreAllocCodeSpace(void)237 Yap_PreAllocCodeSpace(void)
238 {
239   return AuxBase;
240 }
241 
242 #endif /* HEAP_H */
243