procfs_regs.c revision 65237
1238438Sdteske/* 2238438Sdteske * Copyright (c) 1993 Jan-Simon Pendry 3238438Sdteske * Copyright (c) 1993 4238438Sdteske * The Regents of the University of California. All rights reserved. 5238438Sdteske * 6238438Sdteske * This code is derived from software contributed to Berkeley by 7238438Sdteske * Jan-Simon Pendry. 8238438Sdteske * 9238438Sdteske * Redistribution and use in source and binary forms, with or without 10238438Sdteske * modification, are permitted provided that the following conditions 11238438Sdteske * are met: 12238438Sdteske * 1. Redistributions of source code must retain the above copyright 13238438Sdteske * notice, this list of conditions and the following disclaimer. 14238438Sdteske * 2. Redistributions in binary form must reproduce the above copyright 15238438Sdteske * notice, this list of conditions and the following disclaimer in the 16238438Sdteske * documentation and/or other materials provided with the distribution. 17238438Sdteske * 3. All advertising materials mentioning features or use of this software 18238438Sdteske * must display the following acknowledgement: 19238438Sdteske * This product includes software developed by the University of 20238438Sdteske * California, Berkeley and its contributors. 21238438Sdteske * 4. Neither the name of the University nor the names of its contributors 22238438Sdteske * may be used to endorse or promote products derived from this software 23238438Sdteske * without specific prior written permission. 24238438Sdteske * 25238438Sdteske * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26238438Sdteske * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27238438Sdteske * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28238438Sdteske * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29238438Sdteske * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30238438Sdteske * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31240684Sdteske * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32240684Sdteske * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33244675Sdteske * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34240684Sdteske * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35240684Sdteske * SUCH DAMAGE. 36240684Sdteske * 37238438Sdteske * @(#)procfs_regs.c 8.4 (Berkeley) 6/15/94 38240684Sdteske * 39238438Sdteske * From: 40238438Sdteske * $FreeBSD: head/sys/fs/procfs/procfs_regs.c 65237 2000-08-30 04:49:09Z rwatson $ 41242107Sdteske */ 42242107Sdteske 43243112Sdteske#include <sys/param.h> 44238438Sdteske#include <sys/proc.h> 45238438Sdteske#include <sys/vnode.h> 46238438Sdteske#include <machine/reg.h> 47238438Sdteske#include <miscfs/procfs/procfs.h> 48238438Sdteske#include <vm/vm.h> 49238438Sdteske#include <vm/vm_extern.h> 50238438Sdteske 51238438Sdteskeint 52238438Sdteskeprocfs_doregs(curp, p, pfs, uio) 53238438Sdteske struct proc *curp; 54238438Sdteske struct proc *p; 55238438Sdteske struct pfsnode *pfs; 56238438Sdteske struct uio *uio; 57238438Sdteske{ 58238438Sdteske int error; 59238438Sdteske struct reg r; 60238438Sdteske char *kv; 61238438Sdteske int kl; 62238438Sdteske 63238438Sdteske if (p_can(curp, p, P_CAN_DEBUG, NULL)) 64238438Sdteske return EPERM; 65238438Sdteske kl = sizeof(r); 66238438Sdteske kv = (char *) &r; 67238438Sdteske 68238438Sdteske kv += uio->uio_offset; 69238438Sdteske kl -= uio->uio_offset; 70238438Sdteske if (kl > uio->uio_resid) 71238438Sdteske kl = uio->uio_resid; 72238438Sdteske 73240768Sdteske PHOLD(p); 74240768Sdteske 75238438Sdteske if (kl < 0) 76238438Sdteske error = EINVAL; 77238438Sdteske else 78238438Sdteske error = procfs_read_regs(p, &r); 79238438Sdteske if (error == 0) 80241899Sdteske error = uiomove(kv, kl, uio); 81242096Sdteske if (error == 0 && uio->uio_rw == UIO_WRITE) { 82238438Sdteske if (p->p_stat != SSTOP) 83238438Sdteske error = EBUSY; 84240768Sdteske else 85240768Sdteske error = procfs_write_regs(p, &r); 86240768Sdteske } 87240768Sdteske PRELE(p); 88240768Sdteske 89238438Sdteske uio->uio_offset = 0; 90238438Sdteske return (error); 91238438Sdteske} 92238438Sdteske 93238438Sdteskeint 94238438Sdteskeprocfs_validregs(p) 95238438Sdteske struct proc *p; 96238438Sdteske{ 97238438Sdteske return ((p->p_flag & P_SYSTEM) == 0); 98238438Sdteske} 99238438Sdteske