Home | History | Annotate | Line # | Download | only in procfs
procfs_map.c revision 1.5.12.1
      1  1.5.12.1        he /*	$NetBSD: procfs_map.c,v 1.5.12.1 2001/03/30 21:48:32 he Exp $	*/
      2       1.1   msaitoh 
      3       1.1   msaitoh /*
      4       1.1   msaitoh  * Copyright (c) 1993 Jan-Simon Pendry
      5       1.1   msaitoh  * Copyright (c) 1993
      6       1.1   msaitoh  *	The Regents of the University of California.  All rights reserved.
      7       1.1   msaitoh  *
      8       1.1   msaitoh  * This code is derived from software contributed to Berkeley by
      9       1.1   msaitoh  * Jan-Simon Pendry.
     10       1.1   msaitoh  *
     11       1.1   msaitoh  * Redistribution and use in source and binary forms, with or without
     12       1.1   msaitoh  * modification, are permitted provided that the following conditions
     13       1.1   msaitoh  * are met:
     14       1.1   msaitoh  * 1. Redistributions of source code must retain the above copyright
     15       1.1   msaitoh  *    notice, this list of conditions and the following disclaimer.
     16       1.1   msaitoh  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1   msaitoh  *    notice, this list of conditions and the following disclaimer in the
     18       1.1   msaitoh  *    documentation and/or other materials provided with the distribution.
     19       1.1   msaitoh  * 3. All advertising materials mentioning features or use of this software
     20       1.1   msaitoh  *    must display the following acknowledgement:
     21       1.1   msaitoh  *	This product includes software developed by the University of
     22       1.1   msaitoh  *	California, Berkeley and its contributors.
     23       1.1   msaitoh  * 4. Neither the name of the University nor the names of its contributors
     24       1.1   msaitoh  *    may be used to endorse or promote products derived from this software
     25       1.1   msaitoh  *    without specific prior written permission.
     26       1.1   msaitoh  *
     27       1.1   msaitoh  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28       1.1   msaitoh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29       1.1   msaitoh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30       1.1   msaitoh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31       1.1   msaitoh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32       1.1   msaitoh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33       1.1   msaitoh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34       1.1   msaitoh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35       1.1   msaitoh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36       1.1   msaitoh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37       1.1   msaitoh  * SUCH DAMAGE.
     38       1.1   msaitoh  *
     39       1.1   msaitoh  *	@(#)procfs_status.c	8.3 (Berkeley) 2/17/94
     40       1.1   msaitoh  *
     41       1.1   msaitoh  *	$FreeBSD: procfs_map.c,v 1.18 1998/12/04 22:54:51 archie Exp $
     42       1.1   msaitoh  */
     43       1.1   msaitoh 
     44       1.1   msaitoh #include <sys/param.h>
     45       1.1   msaitoh #include <sys/systm.h>
     46       1.1   msaitoh #include <sys/proc.h>
     47       1.1   msaitoh #include <sys/vnode.h>
     48       1.1   msaitoh #include <miscfs/procfs/procfs.h>
     49       1.1   msaitoh 
     50       1.1   msaitoh #include <vm/vm.h>
     51       1.1   msaitoh #include <vm/vm_prot.h>
     52       1.1   msaitoh #include <sys/lock.h>
     53       1.1   msaitoh #include <vm/pmap.h>
     54       1.1   msaitoh #include <vm/vm_map.h>
     55       1.1   msaitoh #include <vm/vm_page.h>
     56       1.1   msaitoh 
     57       1.1   msaitoh #include <uvm/uvm.h>
     58       1.1   msaitoh 
     59       1.1   msaitoh #define MEBUFFERSIZE 256
     60       1.1   msaitoh 
     61       1.1   msaitoh /*
     62       1.1   msaitoh  * The map entries can *almost* be read with programs like cat.  However,
     63       1.1   msaitoh  * large maps need special programs to read.  It is not easy to implement
     64       1.1   msaitoh  * a program that can sense the required size of the buffer, and then
     65       1.1   msaitoh  * subsequently do a read with the appropriate size.  This operation cannot
     66       1.1   msaitoh  * be atomic.  The best that we can do is to allow the program to do a read
     67       1.1   msaitoh  * with an arbitrarily large buffer, and return as much as we can.  We can
     68       1.1   msaitoh  * return an error code if the buffer is too small (EFBIG), then the program
     69       1.1   msaitoh  * can try a bigger buffer.
     70       1.1   msaitoh  */
     71       1.1   msaitoh int
     72       1.1   msaitoh procfs_domap(curp, p, pfs, uio)
     73       1.1   msaitoh 	struct proc *curp;
     74       1.1   msaitoh 	struct proc *p;
     75       1.1   msaitoh 	struct pfsnode *pfs;
     76       1.1   msaitoh 	struct uio *uio;
     77       1.1   msaitoh {
     78       1.1   msaitoh 	int len;
     79       1.1   msaitoh 	int error;
     80       1.1   msaitoh 	vm_map_t map = &p->p_vmspace->vm_map;
     81       1.1   msaitoh 	vm_map_entry_t entry;
     82       1.1   msaitoh 	char mebuffer[MEBUFFERSIZE];
     83       1.1   msaitoh 
     84       1.1   msaitoh 	if (uio->uio_rw != UIO_READ)
     85       1.1   msaitoh 		return (EOPNOTSUPP);
     86       1.1   msaitoh 
     87       1.1   msaitoh 	if (uio->uio_offset != 0)
     88       1.1   msaitoh 		return (0);
     89       1.1   msaitoh 
     90       1.1   msaitoh 	error = 0;
     91       1.1   msaitoh 	if (map != &curproc->p_vmspace->vm_map)
     92       1.1   msaitoh 		vm_map_lock_read(map);
     93       1.1   msaitoh 	for (entry = map->header.next;
     94       1.1   msaitoh 		((uio->uio_resid > 0) && (entry != &map->header));
     95       1.1   msaitoh 		entry = entry->next) {
     96       1.1   msaitoh 
     97       1.1   msaitoh 		if (UVM_ET_ISSUBMAP(entry))
     98       1.1   msaitoh 			continue;
     99       1.1   msaitoh 
    100       1.1   msaitoh 		/*
    101       1.1   msaitoh 		 * format:
    102       1.1   msaitoh 		 *  start, end, resident, private resident, cow, access, type.
    103       1.1   msaitoh 		 */
    104       1.1   msaitoh 		snprintf(mebuffer, sizeof(mebuffer),
    105       1.3   msaitoh 		    "0x%lx 0x%lx %c%c%c %c%c%c %s %s %d %d %d\n",
    106       1.1   msaitoh 			entry->start, entry->end,
    107       1.1   msaitoh 
    108       1.3   msaitoh 			(entry->protection & VM_PROT_READ) ? 'r' : '-',
    109       1.3   msaitoh 			(entry->protection & VM_PROT_WRITE) ? 'w' : '-',
    110       1.3   msaitoh 			(entry->protection & VM_PROT_EXECUTE) ? 'x' : '-',
    111       1.3   msaitoh 			(entry->max_protection & VM_PROT_READ) ? 'r' : '-',
    112       1.3   msaitoh 			(entry->max_protection & VM_PROT_WRITE) ? 'w' : '-',
    113       1.3   msaitoh 			(entry->max_protection & VM_PROT_EXECUTE) ? 'x' : '-',
    114       1.1   msaitoh 
    115       1.1   msaitoh 			(entry->etype & UVM_ET_COPYONWRITE) ? "COW" : "NCOW",
    116       1.1   msaitoh 			(entry->etype & UVM_ET_NEEDSCOPY) ? "NC" : "NNC",
    117       1.4       mrg 		    entry->inheritance, entry->wired_count , entry->advice
    118       1.2  drochner 			);
    119       1.1   msaitoh 
    120       1.1   msaitoh 
    121       1.1   msaitoh 		len = strlen(mebuffer);
    122       1.1   msaitoh 		if (len > uio->uio_resid) {
    123       1.1   msaitoh 			error = EFBIG;
    124       1.1   msaitoh 			break;
    125       1.1   msaitoh 		}
    126       1.1   msaitoh 		error = uiomove(mebuffer, len, uio);
    127       1.1   msaitoh 		if (error)
    128       1.1   msaitoh 			break;
    129       1.1   msaitoh 	}
    130       1.1   msaitoh 	if (map != &curproc->p_vmspace->vm_map)
    131       1.1   msaitoh 		vm_map_unlock_read(map);
    132       1.1   msaitoh 	return error;
    133       1.1   msaitoh }
    134       1.1   msaitoh 
    135       1.1   msaitoh int
    136  1.5.12.1        he procfs_validmap(p, mp)
    137       1.1   msaitoh 	struct proc *p;
    138  1.5.12.1        he 	struct mount *mp;
    139       1.1   msaitoh {
    140       1.1   msaitoh 	return ((p->p_flag & P_SYSTEM) == 0);
    141       1.1   msaitoh }
    142