190716Sbde/*- 21541Srgrimes * Copyright (c) 1993 Jan-Simon Pendry 31541Srgrimes * Copyright (c) 1993 41541Srgrimes * The Regents of the University of California. All rights reserved. 51541Srgrimes * 61541Srgrimes * This code is derived from software contributed to Berkeley by 71541Srgrimes * Jan-Simon Pendry. 81541Srgrimes * 91541Srgrimes * Redistribution and use in source and binary forms, with or without 101541Srgrimes * modification, are permitted provided that the following conditions 111541Srgrimes * are met: 121541Srgrimes * 1. Redistributions of source code must retain the above copyright 131541Srgrimes * notice, this list of conditions and the following disclaimer. 141541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151541Srgrimes * notice, this list of conditions and the following disclaimer in the 161541Srgrimes * documentation and/or other materials provided with the distribution. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 3322521Sdyson * @(#)procfs_regs.c 8.4 (Berkeley) 6/15/94 341541Srgrimes * 3522521Sdyson * From: 3690716Sbde * $Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $ 3750477Speter * $FreeBSD: stable/11/sys/fs/procfs/procfs_regs.c 341491 2018-12-04 19:07:10Z markj $ 381541Srgrimes */ 391541Srgrimes 40147692Speter#include "opt_compat.h" 41147692Speter 421541Srgrimes#include <sys/param.h> 4376166Smarkm#include <sys/systm.h> 4476166Smarkm#include <sys/lock.h> 4576166Smarkm#include <sys/mutex.h> 461541Srgrimes#include <sys/proc.h> 4784637Sdes#include <sys/ptrace.h> 48189282Skib#include <sys/sysent.h> 4987321Sdes#include <sys/uio.h> 5076166Smarkm 511541Srgrimes#include <machine/reg.h> 5276166Smarkm 5387321Sdes#include <fs/pseudofs/pseudofs.h> 5477031Sru#include <fs/procfs/procfs.h> 5576166Smarkm 56205014Snwhitehorn#ifdef COMPAT_FREEBSD32 57147692Speter#include <sys/procfs.h> 58147692Speter#include <machine/fpu.h> 59147692Speter 60147692Speter/* 61147692Speter * PROC(write, regs, td2, &r) becomes 62147692Speter * proc_write_regs(td2, &r) or 63147692Speter * proc_write_regs32(td2, &r32) 64147692Speter * 65147692Speter * UIOMOVE_FROMBUF(r, uio) becomes 66147692Speter * uiomove_frombuf(&r, sizeof(r), uio) or 67147692Speter * uiomove_frombuf(&r32, sizeof(r32), uio) 68147692Speter */ 69147692Speter#define PROC(d, w, t, r) wrap32 ? \ 70147692Speter proc_ ## d ## _ ## w ## 32(t, r ## 32) : \ 71147692Speter proc_ ## d ## _ ## w(t, r) 72147692Speter#define UIOMOVE_FROMBUF(k, u) wrap32 ? \ 73147692Speter uiomove_frombuf(& k ## 32, sizeof(k ## 32), u) : \ 74147692Speter uiomove_frombuf(& k, sizeof(k), u) 75147692Speter#else 76147692Speter#define PROC(d, w, t, r) proc_ ## d ## _ ## w(t, r) 77147692Speter#define UIOMOVE_FROMBUF(k, u) uiomove_frombuf(& k, sizeof(k), u) 78147692Speter#endif 79147692Speter 801541Srgrimesint 8187321Sdesprocfs_doprocregs(PFS_FILL_ARGS) 821541Srgrimes{ 831541Srgrimes int error; 841541Srgrimes struct reg r; 85147692Speter struct thread *td2; 86205014Snwhitehorn#ifdef COMPAT_FREEBSD32 87147692Speter struct reg32 r32; 88147692Speter int wrap32 = 0; 89147692Speter#endif 901541Srgrimes 91168758Sdes if (uio->uio_offset != 0) 92168758Sdes return (0); 93168758Sdes 9494622Sjhb PROC_LOCK(p); 95168758Sdes PROC_ASSERT_HELD(p); 9696886Sjhb if (p_candebug(td, p)) { 9794622Sjhb PROC_UNLOCK(p); 9890716Sbde return (EPERM); 9994622Sjhb } 100216120Skib if (!P_SHOULDSTOP(p)) { 101216120Skib PROC_UNLOCK(p); 102216120Skib return (EBUSY); 103216120Skib } 1041541Srgrimes 105147692Speter td2 = FIRST_THREAD_IN_PROC(p); 106205014Snwhitehorn#ifdef COMPAT_FREEBSD32 107189282Skib if (SV_CURPROC_FLAG(SV_ILP32)) { 108217896Sdchagin if ((SV_PROC_FLAG(td2->td_proc, SV_ILP32)) == 0) { 109147692Speter PROC_UNLOCK(p); 110147692Speter return (EINVAL); 111147692Speter } 112147692Speter wrap32 = 1; 113341491Smarkj memset(&r32, 0, sizeof(r32)); 114341491Smarkj } else 115147692Speter#endif 116341491Smarkj memset(&r, 0, sizeof(r)); 117147692Speter error = PROC(read, regs, td2, &r); 118114734Srwatson if (error == 0) { 119114734Srwatson PROC_UNLOCK(p); 120147692Speter error = UIOMOVE_FROMBUF(r, uio); 121114734Srwatson PROC_LOCK(p); 122114734Srwatson } 1231541Srgrimes if (error == 0 && uio->uio_rw == UIO_WRITE) { 12499072Sjulian if (!P_SHOULDSTOP(p)) 1251541Srgrimes error = EBUSY; 1261541Srgrimes else 12790716Sbde /* XXXKSE: */ 128147692Speter error = PROC(write, regs, td2, &r); 1291541Srgrimes } 13094622Sjhb PROC_UNLOCK(p); 1311541Srgrimes 1321541Srgrimes return (error); 1331541Srgrimes} 134