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/* Get the segment containing this address
17**
18** Written by Kiem-Phong Vo, kpv@research.att.com, 02/07/95
19*/
20
21/**
22 * @param vm region
23 * @param addr address
24 */
25void *vmsegment(Vmalloc_t * vm, void * addr)
26{
27 reg Seg_t *seg;
28 reg Vmdata_t *vd = vm->data;
29
30 if (!(vd->mode & VM_TRUST)) {
31 if (ISLOCK(vd, 0))
32 return NIL(void *);
33 SETLOCK(vd, 0);
34 }
35
36 for (seg = vd->seg; seg; seg = seg->next)
37 if ((Vmuchar_t *) addr >= (Vmuchar_t *) seg->addr &&
38 (Vmuchar_t *) addr < (Vmuchar_t *) seg->baddr)
39 break;
40
41 CLRLOCK(vd, 0);
42 return seg ? (void *) seg->addr : NIL(void *);
43}
44