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

« back to all changes in this revision

Viewing changes to tools/vmalloc/vmclear.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
/*      Clear out all allocated space.
 
4
**
 
5
**      Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
 
6
*/
 
7
#if __STD_C
 
8
int vmclear(Vmalloc_t* vm)
 
9
#else
 
10
int vmclear(vm)
 
11
Vmalloc_t*      vm;
 
12
#endif
 
13
{
 
14
        reg Seg_t*      seg;
 
15
        reg Seg_t*      next;
 
16
        reg Block_t*    tp;
 
17
        reg size_t      size, s;
 
18
        reg Vmdata_t*   vd = vm->data;
 
19
 
 
20
        if(!(vd->mode&VM_TRUST) )
 
21
        {       if(ISLOCK(vd,0))
 
22
                        return -1;
 
23
                SETLOCK(vd,0);
 
24
        }
 
25
 
 
26
        vd->free = vd->wild = NIL(Block_t*);
 
27
        vd->pool = 0;
 
28
 
 
29
        if(vd->mode&(VM_MTBEST|VM_MTDEBUG|VM_MTPROFILE) )
 
30
        {       vd->root = NIL(Block_t*);
 
31
                for(s = 0; s < S_TINY; ++s)
 
32
                        TINY(vd)[s] = NIL(Block_t*);
 
33
                for(s = 0; s <= S_CACHE; ++s)
 
34
                        CACHE(vd)[s] = NIL(Block_t*);
 
35
        }
 
36
 
 
37
        for(seg = vd->seg; seg; seg = next)
 
38
        {       next = seg->next;
 
39
 
 
40
                tp = SEGBLOCK(seg);
 
41
                size = seg->baddr - ((Vmuchar_t*)tp) - 2*sizeof(Head_t);
 
42
 
 
43
                SEG(tp) = seg;
 
44
                SIZE(tp) = size;
 
45
                if((vd->mode&(VM_MTLAST|VM_MTPOOL)) )
 
46
                        seg->free = tp;
 
47
                else
 
48
                {       SIZE(tp) |= BUSY|JUNK;
 
49
                        LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))];
 
50
                        CACHE(vd)[C_INDEX(SIZE(tp))] = tp;
 
51
                }
 
52
 
 
53
                tp = BLOCK(seg->baddr);
 
54
                SEG(tp) = seg;
 
55
                SIZE(tp) = BUSY;
 
56
        }
 
57
 
 
58
        CLRLOCK(vd,0);
 
59
        return 0;
 
60
}