/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1999 Brian Scott Dean, [email protected].4* All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Jan-Simon Pendry under the following copyrights and conditions:8*9* Copyright (c) 1993 Jan-Simon Pendry10* Copyright (c) 199311* The Regents of the University of California. All rights reserved.12*13* This code is derived from software contributed to Berkeley by14* Jan-Simon Pendry.15*16* Redistribution and use in source and binary forms, with or without17* modification, are permitted provided that the following conditions18* are met:19* 1. Redistributions of source code must retain the above copyright20* notice, this list of conditions and the following disclaimer.21* 2. Redistributions in binary form must reproduce the above copyright22* notice, this list of conditions and the following disclaimer in the23* documentation and/or other materials provided with the distribution.24* 3. Neither the name of the University nor the names of its contributors25* may be used to endorse or promote products derived from this software26* without specific prior written permission.27*28* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND29* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE30* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE31* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE32* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL33* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS34* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)35* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT36* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY37* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF38* SUCH DAMAGE.39*40* From:41* $Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $42*/4344#include <sys/param.h>45#include <sys/systm.h>46#include <sys/lock.h>47#include <sys/mutex.h>48#include <sys/proc.h>49#include <sys/ptrace.h>50#include <sys/uio.h>5152#include <fs/pseudofs/pseudofs.h>53#include <fs/procfs/procfs.h>5455#ifdef COMPAT_FREEBSD3256#include <sys/sysent.h>57#include <sys/procfs.h>58#include <machine/fpu.h>5960/*61* PROC(write, dbregs, td2, &r) becomes62* proc_write_dbregs(td2, &r) or63* proc_write_dbregs32(td2, &r32)64*65* UIOMOVE_FROMBUF(r, uio) becomes66* uiomove_frombuf(&r, sizeof(r), uio) or67* uiomove_frombuf(&r32, sizeof(r32), uio)68*/69#define PROC(d, w, t, r) wrap32 ? \70proc_ ## d ## _ ## w ## 32(t, r ## 32) : \71proc_ ## d ## _ ## w(t, r)72#define UIOMOVE_FROMBUF(k, u) wrap32 ? \73uiomove_frombuf(& k ## 32, sizeof(k ## 32), u) : \74uiomove_frombuf(& k, sizeof(k), u)75#else76#define PROC(d, w, t, r) proc_ ## d ## _ ## w(t, r)77#define UIOMOVE_FROMBUF(k, u) uiomove_frombuf(& k, sizeof(k), u)78#endif7980int81procfs_doprocdbregs(PFS_FILL_ARGS)82{83int error;84struct dbreg r;85struct thread *td2;86#ifdef COMPAT_FREEBSD3287struct dbreg32 r32;88int wrap32 = 0;89#endif9091if (uio->uio_offset != 0)92return (0);9394PROC_LOCK(p);95PROC_ASSERT_HELD(p);96if (p_candebug(td, p) != 0) {97PROC_UNLOCK(p);98return (EPERM);99}100101td2 = FIRST_THREAD_IN_PROC(p);102#ifdef COMPAT_FREEBSD32103if (SV_CURPROC_FLAG(SV_ILP32)) {104if (SV_PROC_FLAG(td2->td_proc, SV_ILP32) == 0) {105PROC_UNLOCK(p);106return (EINVAL);107}108wrap32 = 1;109memset(&r32, 0, sizeof(r32));110} else111#endif112memset(&r, 0, sizeof(r));113error = PROC(read, dbregs, td2, &r);114if (error == 0) {115PROC_UNLOCK(p);116error = UIOMOVE_FROMBUF(r, uio);117PROC_LOCK(p);118}119if (error == 0 && uio->uio_rw == UIO_WRITE) {120if (!P_SHOULDSTOP(p)) /* XXXKSE should be P_TRACED? */121error = EBUSY;122else123/* XXXKSE: */124error = PROC(write, dbregs, td2, &r);125}126PROC_UNLOCK(p);127128return (error);129}130131132