/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1993 Jan-Simon Pendry4* Copyright (c) 19935* The Regents of the University of California. All rights reserved.6*7* This code is derived from software contributed to Berkeley by8* Jan-Simon Pendry.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*34* From:35* $Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $36*/3738#include <sys/param.h>39#include <sys/systm.h>40#include <sys/lock.h>41#include <sys/mutex.h>42#include <sys/proc.h>43#include <sys/ptrace.h>44#include <sys/uio.h>4546#include <fs/pseudofs/pseudofs.h>47#include <fs/procfs/procfs.h>4849#ifdef COMPAT_FREEBSD3250#include <sys/procfs.h>51#include <sys/sysent.h>52#include <machine/fpu.h>5354/*55* PROC(write, regs, td2, &r) becomes56* proc_write_regs(td2, &r) or57* proc_write_regs32(td2, &r32)58*59* UIOMOVE_FROMBUF(r, uio) becomes60* uiomove_frombuf(&r, sizeof(r), uio) or61* uiomove_frombuf(&r32, sizeof(r32), uio)62*/63#define PROC(d, w, t, r) wrap32 ? \64proc_ ## d ## _ ## w ## 32(t, r ## 32) : \65proc_ ## d ## _ ## w(t, r)66#define UIOMOVE_FROMBUF(k, u) wrap32 ? \67uiomove_frombuf(& k ## 32, sizeof(k ## 32), u) : \68uiomove_frombuf(& k, sizeof(k), u)69#else70#define PROC(d, w, t, r) proc_ ## d ## _ ## w(t, r)71#define UIOMOVE_FROMBUF(k, u) uiomove_frombuf(& k, sizeof(k), u)72#endif7374int75procfs_doprocregs(PFS_FILL_ARGS)76{77int error;78struct reg r;79struct thread *td2;80#ifdef COMPAT_FREEBSD3281struct reg32 r32;82int wrap32 = 0;83#endif8485if (uio->uio_offset != 0)86return (0);8788PROC_LOCK(p);89PROC_ASSERT_HELD(p);90if (p_candebug(td, p)) {91PROC_UNLOCK(p);92return (EPERM);93}94if (!P_SHOULDSTOP(p)) {95PROC_UNLOCK(p);96return (EBUSY);97}9899td2 = FIRST_THREAD_IN_PROC(p);100#ifdef COMPAT_FREEBSD32101if (SV_CURPROC_FLAG(SV_ILP32)) {102if ((SV_PROC_FLAG(td2->td_proc, SV_ILP32)) == 0) {103PROC_UNLOCK(p);104return (EINVAL);105}106wrap32 = 1;107memset(&r32, 0, sizeof(r32));108} else109#endif110memset(&r, 0, sizeof(r));111error = PROC(read, regs, td2, &r);112if (error == 0) {113PROC_UNLOCK(p);114error = UIOMOVE_FROMBUF(r, uio);115PROC_LOCK(p);116}117if (error == 0 && uio->uio_rw == UIO_WRITE) {118if (!P_SHOULDSTOP(p))119error = EBUSY;120else121/* XXXKSE: */122error = PROC(write, regs, td2, &r);123}124PROC_UNLOCK(p);125126return (error);127}128129130