procfs_regs.c revision 73906
1227569Sphilip/* 2227569Sphilip * Copyright (c) 1993 Jan-Simon Pendry 3227569Sphilip * Copyright (c) 1993 4227569Sphilip * The Regents of the University of California. All rights reserved. 5227569Sphilip * 6227569Sphilip * This code is derived from software contributed to Berkeley by 7227569Sphilip * Jan-Simon Pendry. 8227569Sphilip * 9227569Sphilip * Redistribution and use in source and binary forms, with or without 10227569Sphilip * modification, are permitted provided that the following conditions 11227569Sphilip * are met: 12227569Sphilip * 1. Redistributions of source code must retain the above copyright 13227569Sphilip * notice, this list of conditions and the following disclaimer. 14227569Sphilip * 2. Redistributions in binary form must reproduce the above copyright 15227569Sphilip * notice, this list of conditions and the following disclaimer in the 16227569Sphilip * documentation and/or other materials provided with the distribution. 17227569Sphilip * 3. All advertising materials mentioning features or use of this software 18227569Sphilip * must display the following acknowledgement: 19227569Sphilip * This product includes software developed by the University of 20227569Sphilip * California, Berkeley and its contributors. 21227569Sphilip * 4. Neither the name of the University nor the names of its contributors 22227569Sphilip * may be used to endorse or promote products derived from this software 23227569Sphilip * without specific prior written permission. 24228078Sphilip * 25228078Sphilip * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26227569Sphilip * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27227569Sphilip * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28227569Sphilip * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29227569Sphilip * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30227569Sphilip * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31227569Sphilip * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32227569Sphilip * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33227569Sphilip * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34227569Sphilip * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35227569Sphilip * SUCH DAMAGE. 36227569Sphilip * 37227569Sphilip * @(#)procfs_regs.c 8.4 (Berkeley) 6/15/94 38227569Sphilip * 39227569Sphilip * From: 40227569Sphilip * $FreeBSD: head/sys/fs/procfs/procfs_regs.c 73906 2001-03-07 02:07:56Z jhb $ 41227569Sphilip */ 42227569Sphilip 43227569Sphilip#include <sys/param.h> 44227569Sphilip#include <sys/proc.h> 45227569Sphilip#include <sys/vnode.h> 46227569Sphilip#include <machine/reg.h> 47227569Sphilip#include <miscfs/procfs/procfs.h> 48227569Sphilip#include <vm/vm.h> 49227569Sphilip#include <vm/vm_extern.h> 50227569Sphilip 51227569Sphilipint 52227569Sphilipprocfs_doregs(curp, p, pfs, uio) 53227569Sphilip struct proc *curp; 54227569Sphilip struct proc *p; 55227569Sphilip struct pfsnode *pfs; 56227569Sphilip struct uio *uio; 57227569Sphilip{ 58227569Sphilip int error; 59227569Sphilip struct reg r; 60227569Sphilip char *kv; 61227569Sphilip int kl; 62227569Sphilip 63227569Sphilip if (p_can(curp, p, P_CAN_DEBUG, NULL)) 64227569Sphilip return EPERM; 65227569Sphilip kl = sizeof(r); 66227569Sphilip kv = (char *) &r; 67227569Sphilip 68227569Sphilip kv += uio->uio_offset; 69227569Sphilip kl -= uio->uio_offset; 70227569Sphilip if (kl > uio->uio_resid) 71227569Sphilip kl = uio->uio_resid; 72227569Sphilip 73227569Sphilip PHOLD(p); 74227569Sphilip 75227569Sphilip if (kl < 0) 76227569Sphilip error = EINVAL; 77227569Sphilip else 78227569Sphilip error = procfs_read_regs(p, &r); 79227569Sphilip if (error == 0) 80227569Sphilip error = uiomove(kv, kl, uio); 81227569Sphilip if (error == 0 && uio->uio_rw == UIO_WRITE) { 82227569Sphilip if (p->p_stat != SSTOP) 83227569Sphilip error = EBUSY; 84227569Sphilip else 85227569Sphilip error = procfs_write_regs(p, &r); 86227569Sphilip } 87227569Sphilip PRELE(p); 88227569Sphilip 89227569Sphilip uio->uio_offset = 0; 90227569Sphilip return (error); 91227569Sphilip} 92227569Sphilip 93227569Sphilipint 94227569Sphilipprocfs_validregs(p) 95227569Sphilip struct proc *p; 96227569Sphilip{ 97227569Sphilip int valid; 98227569Sphilip 99227569Sphilip PROC_LOCK(p); 100227569Sphilip valid = (p->p_flag & P_SYSTEM) == 0; 101227569Sphilip PROC_UNLOCK(p); 102227569Sphilip return (valid); 103227569Sphilip} 104227569Sphilip