1d6c4f011SJonathan Lemon /*- 2d6c4f011SJonathan Lemon * Copyright (c) 1999 Brian Scott Dean, brdean@unx.sas.com. 3d6c4f011SJonathan Lemon * All rights reserved. 4d6c4f011SJonathan Lemon * 5d6c4f011SJonathan Lemon * This code is derived from software contributed to Berkeley by 6d6c4f011SJonathan Lemon * Jan-Simon Pendry under the following copyrights and conditions: 7d6c4f011SJonathan Lemon * 8d6c4f011SJonathan Lemon * Copyright (c) 1993 Jan-Simon Pendry 9d6c4f011SJonathan Lemon * Copyright (c) 1993 10d6c4f011SJonathan Lemon * The Regents of the University of California. All rights reserved. 11d6c4f011SJonathan Lemon * 12d6c4f011SJonathan Lemon * This code is derived from software contributed to Berkeley by 13d6c4f011SJonathan Lemon * Jan-Simon Pendry. 14d6c4f011SJonathan Lemon * 15d6c4f011SJonathan Lemon * Redistribution and use in source and binary forms, with or without 16d6c4f011SJonathan Lemon * modification, are permitted provided that the following conditions 17d6c4f011SJonathan Lemon * are met: 18d6c4f011SJonathan Lemon * 1. Redistributions of source code must retain the above copyright 19d6c4f011SJonathan Lemon * notice, this list of conditions and the following disclaimer. 20d6c4f011SJonathan Lemon * 2. Redistributions in binary form must reproduce the above copyright 21d6c4f011SJonathan Lemon * notice, this list of conditions and the following disclaimer in the 22d6c4f011SJonathan Lemon * documentation and/or other materials provided with the distribution. 23d6c4f011SJonathan Lemon * 3. All advertising materials mentioning features or use of this software 24d6c4f011SJonathan Lemon * must display the following acknowledgement: 25d6c4f011SJonathan Lemon * This product includes software developed by the University of 26d6c4f011SJonathan Lemon * California, Berkeley and its contributors. 27d6c4f011SJonathan Lemon * 4. Neither the name of the University nor the names of its contributors 28d6c4f011SJonathan Lemon * may be used to endorse or promote products derived from this software 29d6c4f011SJonathan Lemon * without specific prior written permission. 30d6c4f011SJonathan Lemon * 31d6c4f011SJonathan Lemon * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32d6c4f011SJonathan Lemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33d6c4f011SJonathan Lemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34d6c4f011SJonathan Lemon * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35d6c4f011SJonathan Lemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36d6c4f011SJonathan Lemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37d6c4f011SJonathan Lemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38d6c4f011SJonathan Lemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39d6c4f011SJonathan Lemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40d6c4f011SJonathan Lemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41d6c4f011SJonathan Lemon * SUCH DAMAGE. 42d6c4f011SJonathan Lemon * 43d6c4f011SJonathan Lemon * $Id$ 44d6c4f011SJonathan Lemon */ 45d6c4f011SJonathan Lemon 46d6c4f011SJonathan Lemon #include <sys/param.h> 47d6c4f011SJonathan Lemon #include <sys/proc.h> 48d6c4f011SJonathan Lemon #include <sys/vnode.h> 49d6c4f011SJonathan Lemon #include <machine/reg.h> 50d6c4f011SJonathan Lemon #include <miscfs/procfs/procfs.h> 51d6c4f011SJonathan Lemon #include <vm/vm.h> 52d6c4f011SJonathan Lemon #include <vm/vm_extern.h> 53d6c4f011SJonathan Lemon 54d6c4f011SJonathan Lemon int 55d6c4f011SJonathan Lemon procfs_dodbregs(curp, p, pfs, uio) 56d6c4f011SJonathan Lemon struct proc *curp; 57d6c4f011SJonathan Lemon struct proc *p; 58d6c4f011SJonathan Lemon struct pfsnode *pfs; 59d6c4f011SJonathan Lemon struct uio *uio; 60d6c4f011SJonathan Lemon { 61d6c4f011SJonathan Lemon int error; 62d6c4f011SJonathan Lemon struct dbreg r; 63d6c4f011SJonathan Lemon char *kv; 64d6c4f011SJonathan Lemon int kl; 65d6c4f011SJonathan Lemon 66d6c4f011SJonathan Lemon if (!CHECKIO(curp, p)) 67d6c4f011SJonathan Lemon return (EPERM); 68d6c4f011SJonathan Lemon kl = sizeof(r); 69d6c4f011SJonathan Lemon kv = (char *) &r; 70d6c4f011SJonathan Lemon 71d6c4f011SJonathan Lemon kv += uio->uio_offset; 72d6c4f011SJonathan Lemon kl -= uio->uio_offset; 73d6c4f011SJonathan Lemon if (kl > uio->uio_resid) 74d6c4f011SJonathan Lemon kl = uio->uio_resid; 75d6c4f011SJonathan Lemon 76d6c4f011SJonathan Lemon PHOLD(p); 77d6c4f011SJonathan Lemon 78d6c4f011SJonathan Lemon if (kl < 0) 79d6c4f011SJonathan Lemon error = EINVAL; 80d6c4f011SJonathan Lemon else 81d6c4f011SJonathan Lemon error = procfs_read_dbregs(p, &r); 82d6c4f011SJonathan Lemon if (error == 0) 83d6c4f011SJonathan Lemon error = uiomove(kv, kl, uio); 84d6c4f011SJonathan Lemon if (error == 0 && uio->uio_rw == UIO_WRITE) { 85d6c4f011SJonathan Lemon if (p->p_stat != SSTOP) 86d6c4f011SJonathan Lemon error = EBUSY; 87d6c4f011SJonathan Lemon else 88d6c4f011SJonathan Lemon error = procfs_write_dbregs(p, &r); 89d6c4f011SJonathan Lemon } 90d6c4f011SJonathan Lemon PRELE(p); 91d6c4f011SJonathan Lemon 92d6c4f011SJonathan Lemon uio->uio_offset = 0; 93d6c4f011SJonathan Lemon return (error); 94d6c4f011SJonathan Lemon } 95d6c4f011SJonathan Lemon 96d6c4f011SJonathan Lemon int 97d6c4f011SJonathan Lemon procfs_validdbregs(p) 98d6c4f011SJonathan Lemon struct proc *p; 99d6c4f011SJonathan Lemon { 100d6c4f011SJonathan Lemon return ((p->p_flag & P_SYSTEM) == 0); 101d6c4f011SJonathan Lemon } 102