xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/vmalloc/vmclear.c (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #if defined(_UWIN) && defined(_BLD_ast)
23 
_STUB_vmclear()24 void _STUB_vmclear(){}
25 
26 #else
27 
28 #include	"vmhdr.h"
29 
30 /*	Clear out all allocated space.
31 **
32 **	Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
33 */
34 #if __STD_C
vmclear(Vmalloc_t * vm)35 int vmclear(Vmalloc_t* vm)
36 #else
37 int vmclear(vm)
38 Vmalloc_t*	vm;
39 #endif
40 {
41 	Seg_t		*seg, *next;
42 	Block_t		*tp;
43 	size_t		size, s;
44 	Vmdata_t	*vd = vm->data;
45 
46 	SETLOCK(vm, 0);
47 
48 	vd->free = vd->wild = NIL(Block_t*);
49 	vd->pool = 0;
50 
51 	if(vd->mode&(VM_MTBEST|VM_MTDEBUG|VM_MTPROFILE) )
52 	{	vd->root = NIL(Block_t*);
53 		for(s = 0; s < S_TINY; ++s)
54 			TINY(vd)[s] = NIL(Block_t*);
55 		for(s = 0; s <= S_CACHE; ++s)
56 			CACHE(vd)[s] = NIL(Block_t*);
57 	}
58 
59 	for(seg = vd->seg; seg; seg = next)
60 	{	next = seg->next;
61 
62 		tp = SEGBLOCK(seg);
63 		size = seg->baddr - ((Vmuchar_t*)tp) - 2*sizeof(Head_t);
64 
65 		SEG(tp) = seg;
66 		SIZE(tp) = size;
67 		if((vd->mode&(VM_MTLAST|VM_MTPOOL)) )
68 			seg->free = tp;
69 		else
70 		{	SIZE(tp) |= BUSY|JUNK;
71 			LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))];
72 			CACHE(vd)[C_INDEX(SIZE(tp))] = tp;
73 		}
74 
75 		tp = BLOCK(seg->baddr);
76 		SEG(tp) = seg;
77 		SIZE(tp) = BUSY;
78 	}
79 
80 	CLRLOCK(vm, 0);
81 
82 	return 0;
83 }
84 
85 #endif
86