Lines Matching refs:seg
103 // Determines if 'a' is before, within, or after seg's range. Sets 'cmp' to
105 void Seg__cmp(Seg* seg, Addr a, Int* cmp, UWord* n)
107 if (a < seg->addr) {
109 *n = seg->addr - a;
110 } else if (a < seg->addr + seg->szB && seg->szB > 0) {
112 *n = a - seg->addr;
115 *n = a - (seg->addr + seg->szB);
119 /*inline*/ Bool Seg__is_freed(Seg* seg)
121 if (!is_known_segment(seg))
124 return seg->nextfree != (Seg*)1;
127 ExeContext* Seg__where(Seg* seg)
129 tl_assert(is_known_segment(seg));
130 return seg->ec;
133 SizeT Seg__size(Seg* seg)
135 tl_assert(is_known_segment(seg));
136 return seg->szB;
139 Addr Seg__addr(Seg* seg)
141 tl_assert(is_known_segment(seg));
142 return seg->addr;
152 Seg segs[N_SEGS_PER_GROUP];
158 static Seg* freesegs_youngest = NULL;
159 static Seg* freesegs_oldest = NULL;
168 /* Get a completely new Seg */
169 static Seg* new_Seg ( void )
171 Seg* teg;
191 static Seg* get_Seg_for_malloc ( void )
193 Seg* seg;
195 seg = new_Seg();
196 seg->nextfree = (Seg*)1;
197 return seg;
199 /* else recycle the oldest Seg in the free list */
203 seg = freesegs_oldest;
204 freesegs_oldest = seg->nextfree;
206 seg->nextfree = (Seg*)1;
208 return seg;
211 static void set_Seg_freed ( Seg* seg )
213 tl_assert(seg);
214 tl_assert(!Seg__is_freed(seg));
218 seg->nextfree = NULL;
219 freesegs_youngest = seg;
220 freesegs_oldest = seg;
231 tl_assert(seg != freesegs_youngest && seg != freesegs_oldest);
232 seg->nextfree = NULL;
233 freesegs_youngest->nextfree = seg;
234 freesegs_youngest = seg;
239 static WordFM* addr_to_seg_map = NULL; /* GuestAddr -> Seg* */
249 static Seg* find_Seg_by_addr ( Addr ga )
255 return (Seg*)valW;
261 static void bind_addr_to_Seg ( Addr ga, Seg* seg )
265 b = VG_(addToFM)( addr_to_seg_map, (UWord)ga, (UWord)seg );
286 static Seg* add_new_segment ( ThreadId tid, Addr p, SizeT size )
288 Seg* seg = get_Seg_for_malloc();
289 tl_assert(seg != (Seg*)1); /* since we're using 1 as a special value */
290 seg->addr = p;
291 seg->szB = size;
292 seg->ec = VG_(record_ExeContext)( tid, 0/*first_ip_delta*/ );
293 tl_assert(!Seg__is_freed(seg));
295 bind_addr_to_Seg(p, seg);
297 return seg;
319 static void die_and_free_mem_heap ( ThreadId tid, Seg* seg )
322 tl_assert(!Seg__is_freed(seg));
324 VG_(cli_free)( (void*)seg->addr );
327 seg->ec = VG_(record_ExeContext)( tid, 0/*first_ip_delta*/ );
329 set_Seg_freed(seg);
330 unbind_addr_from_Seg( seg->addr );
337 Seg* seg = find_Seg_by_addr( (Addr)p );
338 if (!seg) {
342 die_and_free_mem_heap( tid, seg );
410 Seg* seg;
413 seg = find_Seg_by_addr( (Addr)p_old );
414 if (!seg)
417 tl_assert(seg->addr == (Addr)p_old);
419 if (new_size <= seg->szB) {
425 die_and_free_mem_heap( tid, seg );
436 VG_(memcpy)((void*)p_new, p_old, seg->szB);
439 die_and_free_mem_heap( tid, seg );
454 Seg* seg = find_Seg_by_addr( (Addr)p );
458 return ( seg ? seg->szB : 0 );