3
/* Close down a region.
5
** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
8
int vmclose(Vmalloc_t* vm)
14
reg Seg_t *seg, *vmseg;
15
reg Vmemory_f memoryf;
16
reg Vmdata_t* vd = vm->data;
17
reg Vmalloc_t *v, *last;
22
if(!(vd->mode&VM_TRUST) && ISLOCK(vd,0))
25
if(vm->disc->exceptf &&
26
(*vm->disc->exceptf)(vm,VM_CLOSE,NIL(Void_t*),vm->disc) < 0)
29
/* make this region inaccessible until it disappears */
30
vd->mode &= ~VM_TRUST;
33
if((vd->mode&VM_MTPROFILE) && _Vmpfclose)
36
/* remove from linked list of regions */
37
for(last = Vmheap, v = last->next; v; last = v, v = v->next)
39
{ last->next = v->next;
44
/* free all non-region segments */
45
memoryf = vm->disc->memoryf;
47
for(seg = vd->seg; seg; )
48
{ reg Seg_t* next = seg->next;
49
if(seg->extent != seg->size)
50
(void)(*memoryf)(vm,seg->addr,seg->extent,0,vm->disc);
55
/* this must be done here because even though this region is freed,
56
there may still be others that share this space.
60
/* free the segment that contains the region data */
62
(void)(*memoryf)(vm,vmseg->addr,vmseg->extent,0,vm->disc);
64
/* free the region itself */