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 * 43c3aac50fSPeter Wemm * $FreeBSD$ 44d6c4f011SJonathan Lemon */ 45d6c4f011SJonathan Lemon 46d6c4f011SJonathan Lemon #include <sys/param.h> 47fb919e4dSMark Murray #include <sys/systm.h> 48fb919e4dSMark Murray #include <sys/lock.h> 49fb919e4dSMark Murray #include <sys/mutex.h> 50d6c4f011SJonathan Lemon #include <sys/proc.h> 51d6c4f011SJonathan Lemon #include <sys/vnode.h> 52fb919e4dSMark Murray 53d6c4f011SJonathan Lemon #include <machine/reg.h> 54fb919e4dSMark Murray 55d6c4f011SJonathan Lemon #include <miscfs/procfs/procfs.h> 56fb919e4dSMark Murray 57d6c4f011SJonathan Lemon #include <vm/vm.h> 58d6c4f011SJonathan Lemon 59d6c4f011SJonathan Lemon int 60d6c4f011SJonathan Lemon procfs_dodbregs(curp, p, pfs, uio) 61d6c4f011SJonathan Lemon struct proc *curp; 62d6c4f011SJonathan Lemon struct proc *p; 63d6c4f011SJonathan Lemon struct pfsnode *pfs; 64d6c4f011SJonathan Lemon struct uio *uio; 65d6c4f011SJonathan Lemon { 66d6c4f011SJonathan Lemon int error; 67d6c4f011SJonathan Lemon struct dbreg r; 68d6c4f011SJonathan Lemon char *kv; 69d6c4f011SJonathan Lemon int kl; 70d6c4f011SJonathan Lemon 71387d2c03SRobert Watson if (p_can(curp, p, P_CAN_DEBUG, NULL)) 72d6c4f011SJonathan Lemon return (EPERM); 73d6c4f011SJonathan Lemon kl = sizeof(r); 74d6c4f011SJonathan Lemon kv = (char *) &r; 75d6c4f011SJonathan Lemon 76d6c4f011SJonathan Lemon kv += uio->uio_offset; 77d6c4f011SJonathan Lemon kl -= uio->uio_offset; 78d6c4f011SJonathan Lemon if (kl > uio->uio_resid) 79d6c4f011SJonathan Lemon kl = uio->uio_resid; 80d6c4f011SJonathan Lemon 81d6c4f011SJonathan Lemon PHOLD(p); 82d6c4f011SJonathan Lemon 83d6c4f011SJonathan Lemon if (kl < 0) 84d6c4f011SJonathan Lemon error = EINVAL; 85d6c4f011SJonathan Lemon else 86d6c4f011SJonathan Lemon error = procfs_read_dbregs(p, &r); 87d6c4f011SJonathan Lemon if (error == 0) 88d6c4f011SJonathan Lemon error = uiomove(kv, kl, uio); 89d6c4f011SJonathan Lemon if (error == 0 && uio->uio_rw == UIO_WRITE) { 90d6c4f011SJonathan Lemon if (p->p_stat != SSTOP) 91d6c4f011SJonathan Lemon error = EBUSY; 92d6c4f011SJonathan Lemon else 93d6c4f011SJonathan Lemon error = procfs_write_dbregs(p, &r); 94d6c4f011SJonathan Lemon } 95d6c4f011SJonathan Lemon PRELE(p); 96d6c4f011SJonathan Lemon 97d6c4f011SJonathan Lemon uio->uio_offset = 0; 98d6c4f011SJonathan Lemon return (error); 99d6c4f011SJonathan Lemon } 100d6c4f011SJonathan Lemon 101d6c4f011SJonathan Lemon int 102d6c4f011SJonathan Lemon procfs_validdbregs(p) 103d6c4f011SJonathan Lemon struct proc *p; 104d6c4f011SJonathan Lemon { 10500873747SJohn Baldwin 10633a9ed9dSJohn Baldwin return ((p->p_flag & P_SYSTEM) == 0); 107d6c4f011SJonathan Lemon } 108