1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14#include "vmhdr.h"
15
16/* Walks all segments created in region(s)
17**
18** Written by Kiem-Phong Vo, kpv@research.att.com (02/08/96)
19*/
20
21int vmwalk(Vmalloc_t * vm,
22 int (*segf) (Vmalloc_t *, void *, size_t, Vmdisc_t *))
23{
24 reg Seg_t *seg;
25 reg int rv;
26
27 if (!vm) {
28 for (vm = Vmheap; vm; vm = vm->next) {
29 if (!(vm->data->mode & VM_TRUST) && ISLOCK(vm->data, 0))
30 continue;
31
32 SETLOCK(vm->data, 0);
33 for (seg = vm->data->seg; seg; seg = seg->next) {
34 rv = (*segf) (vm, seg->addr, seg->extent, vm->disc);
35 if (rv < 0)
36 return rv;
37 }
38 CLRLOCK(vm->data, 0);
39 }
40 } else {
41 if (!(vm->data->mode & VM_TRUST) && ISLOCK(vm->data, 0))
42 return -1;
43
44 SETLOCK(vm->data, 0);
45 for (seg = vm->data->seg; seg; seg = seg->next) {
46 rv = (*segf) (vm, seg->addr, seg->extent, vm->disc);
47 if (rv < 0)
48 return rv;
49 }
50 CLRLOCK(vm->data, 0);
51 }
52
53 return 0;
54}
55