~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tools/vmalloc/vmclose.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include        "vmhdr.h"
 
2
 
 
3
/*      Close down a region.
 
4
**
 
5
**      Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
 
6
*/
 
7
#if __STD_C
 
8
int vmclose(Vmalloc_t* vm)
 
9
#else
 
10
int vmclose(vm)
 
11
Vmalloc_t*      vm;
 
12
#endif
 
13
{
 
14
        reg Seg_t       *seg, *vmseg;
 
15
        reg Vmemory_f   memoryf;
 
16
        reg Vmdata_t*   vd = vm->data;
 
17
        reg Vmalloc_t   *v, *last;
 
18
 
 
19
        if(vm == Vmheap)
 
20
                return -1;
 
21
 
 
22
        if(!(vd->mode&VM_TRUST) && ISLOCK(vd,0))
 
23
                return -1;
 
24
 
 
25
        if(vm->disc->exceptf &&
 
26
           (*vm->disc->exceptf)(vm,VM_CLOSE,NIL(Void_t*),vm->disc) < 0)
 
27
                return -1;
 
28
 
 
29
        /* make this region inaccessible until it disappears */
 
30
        vd->mode &= ~VM_TRUST;
 
31
        SETLOCK(vd,0);
 
32
 
 
33
        if((vd->mode&VM_MTPROFILE) && _Vmpfclose)
 
34
                (*_Vmpfclose)(vm);
 
35
 
 
36
        /* remove from linked list of regions   */
 
37
        for(last = Vmheap, v = last->next; v; last = v, v = v->next)
 
38
        {       if(v == vm)
 
39
                {       last->next = v->next;
 
40
                        break;
 
41
                }
 
42
        }
 
43
 
 
44
        /* free all non-region segments */
 
45
        memoryf = vm->disc->memoryf;
 
46
        vmseg = NIL(Seg_t*);
 
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);
 
51
                else    vmseg = seg;
 
52
                seg = next;
 
53
        }
 
54
 
 
55
        /* this must be done here because even though this region is freed,
 
56
           there may still be others that share this space.
 
57
        */
 
58
        CLRLOCK(vd,0);
 
59
 
 
60
        /* free the segment that contains the region data */
 
61
        if(vmseg)
 
62
                (void)(*memoryf)(vm,vmseg->addr,vmseg->extent,0,vm->disc);
 
63
 
 
64
        /* free the region itself */
 
65
        vmfree(Vmheap,vm);
 
66
 
 
67
        return 0;
 
68
}