procfs_regs.c revision 27845
1194140Simp/* 2194140Simp * Copyright (c) 1993 Jan-Simon Pendry 3194140Simp * Copyright (c) 1993 4206721Sjmallett * The Regents of the University of California. All rights reserved. 5210311Sjmallett * 6202063Simp * This code is derived from software contributed to Berkeley by 7210311Sjmallett * Jan-Simon Pendry. 8202063Simp * 9202063Simp * Redistribution and use in source and binary forms, with or without 10206721Sjmallett * modification, are permitted provided that the following conditions 11210311Sjmallett * are met: 12202063Simp * 1. Redistributions of source code must retain the above copyright 13202063Simp * notice, this list of conditions and the following disclaimer. 14202063Simp * 2. Redistributions in binary form must reproduce the above copyright 15198154Srrs * notice, this list of conditions and the following disclaimer in the 16198669Srrs * documentation and/or other materials provided with the distribution. 17210311Sjmallett * 3. All advertising materials mentioning features or use of this software 18210311Sjmallett * must display the following acknowledgement: 19215989Sgonzo * This product includes software developed by the University of 20215989Sgonzo * California, Berkeley and its contributors. 21210311Sjmallett * 4. Neither the name of the University nor the names of its contributors 22210312Sjmallett * may be used to endorse or promote products derived from this software 23210312Sjmallett * without specific prior written permission. 24210312Sjmallett * 25210311Sjmallett * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26213346Sjmallett * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27210311Sjmallett * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28210311Sjmallett * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29210311Sjmallett * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30210311Sjmallett * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31210311Sjmallett * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32210311Sjmallett * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33210311Sjmallett * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34210311Sjmallett * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35210311Sjmallett * SUCH DAMAGE. 36213762Sjmallett * 37210311Sjmallett * @(#)procfs_regs.c 8.4 (Berkeley) 6/15/94 38210311Sjmallett * 39210311Sjmallett * From: 40210311Sjmallett * $Id: procfs_regs.c,v 1.6 1997/02/22 09:40:29 peter Exp $ 41210311Sjmallett */ 42210311Sjmallett 43210312Sjmallett#include <sys/param.h> 44210312Sjmallett#include <sys/proc.h> 45210312Sjmallett#include <sys/vnode.h> 46210312Sjmallett#include <machine/reg.h> 47210312Sjmallett#include <miscfs/procfs/procfs.h> 48210311Sjmallett#include <vm/vm.h> 49210311Sjmallett#include <vm/vm_extern.h> 50213140Sjmallett 51210311Sjmallettint 52213140Sjmallettprocfs_doregs(curp, p, pfs, uio) 53213140Sjmallett struct proc *curp; 54213140Sjmallett struct proc *p; 55213140Sjmallett struct pfsnode *pfs; 56213140Sjmallett struct uio *uio; 57213140Sjmallett{ 58213140Sjmallett int error; 59213140Sjmallett struct reg r; 60213140Sjmallett char *kv; 61213140Sjmallett int kl; 62213140Sjmallett 63213140Sjmallett kl = sizeof(r); 64213140Sjmallett kv = (char *) &r; 65213140Sjmallett 66213140Sjmallett kv += uio->uio_offset; 67210311Sjmallett kl -= uio->uio_offset; 68210311Sjmallett if (kl > uio->uio_resid) 69213140Sjmallett kl = uio->uio_resid; 70210311Sjmallett 71210311Sjmallett PHOLD(p); 72 73 if (kl < 0) 74 error = EINVAL; 75 else 76 error = procfs_read_regs(p, &r); 77 if (error == 0) 78 error = uiomove(kv, kl, uio); 79 if (error == 0 && uio->uio_rw == UIO_WRITE) { 80 if (p->p_stat != SSTOP) 81 error = EBUSY; 82 else 83 error = procfs_write_regs(p, &r); 84 } 85 PRELE(p); 86 87 uio->uio_offset = 0; 88 return (error); 89} 90 91int 92procfs_validregs(p) 93 struct proc *p; 94{ 95 return ((p->p_flag & P_SYSTEM) == 0); 96} 97