xref: /onnv-gate/usr/src/lib/libast/common/vmalloc/vmclear.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #if defined(_UWIN) && defined(_BLD_ast)
234887Schin 
_STUB_vmclear()244887Schin void _STUB_vmclear(){}
254887Schin 
264887Schin #else
274887Schin 
284887Schin #include	"vmhdr.h"
294887Schin 
304887Schin /*	Clear out all allocated space.
314887Schin **
324887Schin **	Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
334887Schin */
344887Schin #if __STD_C
vmclear(Vmalloc_t * vm)354887Schin int vmclear(Vmalloc_t* vm)
364887Schin #else
374887Schin int vmclear(vm)
384887Schin Vmalloc_t*	vm;
394887Schin #endif
404887Schin {
414887Schin 	reg Seg_t*	seg;
424887Schin 	reg Seg_t*	next;
434887Schin 	reg Block_t*	tp;
444887Schin 	reg size_t	size, s;
454887Schin 	reg Vmdata_t*	vd = vm->data;
468462SApril.Chin@Sun.COM 	reg int		inuse;
474887Schin 
488462SApril.Chin@Sun.COM 	SETINUSE(vd, inuse);
494887Schin 	if(!(vd->mode&VM_TRUST) )
504887Schin 	{	if(ISLOCK(vd,0))
518462SApril.Chin@Sun.COM 		{	CLRINUSE(vd, inuse);
524887Schin 			return -1;
538462SApril.Chin@Sun.COM 		}
544887Schin 		SETLOCK(vd,0);
554887Schin 	}
564887Schin 
574887Schin 	vd->free = vd->wild = NIL(Block_t*);
584887Schin 	vd->pool = 0;
594887Schin 
604887Schin 	if(vd->mode&(VM_MTBEST|VM_MTDEBUG|VM_MTPROFILE) )
614887Schin 	{	vd->root = NIL(Block_t*);
624887Schin 		for(s = 0; s < S_TINY; ++s)
634887Schin 			TINY(vd)[s] = NIL(Block_t*);
644887Schin 		for(s = 0; s <= S_CACHE; ++s)
654887Schin 			CACHE(vd)[s] = NIL(Block_t*);
664887Schin 	}
674887Schin 
684887Schin 	for(seg = vd->seg; seg; seg = next)
694887Schin 	{	next = seg->next;
704887Schin 
714887Schin 		tp = SEGBLOCK(seg);
724887Schin 		size = seg->baddr - ((Vmuchar_t*)tp) - 2*sizeof(Head_t);
734887Schin 
744887Schin 		SEG(tp) = seg;
754887Schin 		SIZE(tp) = size;
764887Schin 		if((vd->mode&(VM_MTLAST|VM_MTPOOL)) )
774887Schin 			seg->free = tp;
784887Schin 		else
794887Schin 		{	SIZE(tp) |= BUSY|JUNK;
804887Schin 			LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))];
814887Schin 			CACHE(vd)[C_INDEX(SIZE(tp))] = tp;
824887Schin 		}
834887Schin 
844887Schin 		tp = BLOCK(seg->baddr);
854887Schin 		SEG(tp) = seg;
864887Schin 		SIZE(tp) = BUSY;
874887Schin 	}
884887Schin 
894887Schin 	CLRLOCK(vd,0);
908462SApril.Chin@Sun.COM 	CLRINUSE(vd, inuse);
914887Schin 	return 0;
924887Schin }
934887Schin 
944887Schin #endif
95