xref: /titanic_41/usr/src/lib/libast/common/vmalloc/vmwalk.c (revision 0485cf53f277ad1364b39e092bfa2480dbcac144)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
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 
24 void _STUB_vmwalk(){}
25 
26 #else
27 
28 #include	"vmhdr.h"
29 
30 /*	Walks all segments created in region(s)
31 **
32 **	Written by Kiem-Phong Vo, kpv@research.att.com (02/08/96)
33 */
34 
35 #if __STD_C
36 int vmwalk(Vmalloc_t* vm, int(*segf)(Vmalloc_t*, Void_t*, size_t, Vmdisc_t*) )
37 #else
38 int vmwalk(vm, segf)
39 Vmalloc_t*	vm;
40 int(*		segf)(/* Vmalloc_t*, Void_t*, size_t, Vmdisc_t* */);
41 #endif
42 {
43 	reg Seg_t*	seg;
44 	reg int		rv;
45 
46 	if(!vm)
47 	{	for(vm = Vmheap; vm; vm = vm->next)
48 		{	if(!(vm->data->mode&VM_TRUST) && ISLOCK(vm->data,0) )
49 				continue;
50 
51 			SETLOCK(vm->data,0);
52 			for(seg = vm->data->seg; seg; seg = seg->next)
53 			{	rv = (*segf)(vm, seg->addr, seg->extent, vm->disc);
54 				if(rv < 0)
55 					return rv;
56 			}
57 			CLRLOCK(vm->data,0);
58 		}
59 	}
60 	else
61 	{	if(!(vm->data->mode&VM_TRUST) && ISLOCK(vm->data,0) )
62 			return -1;
63 
64 		SETLOCK(vm->data,0);
65 		for(seg = vm->data->seg; seg; seg = seg->next)
66 		{	rv = (*segf)(vm, seg->addr, seg->extent, vm->disc);
67 			if(rv < 0)
68 				return rv;
69 		}
70 		CLRLOCK(vm->data,0);
71 	}
72 
73 	return 0;
74 }
75 
76 #endif
77