procfs_fpregs.c revision 217896
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_fpregs.c 8.2 (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: head/sys/fs/procfs/procfs_fpregs.c 217896 2011-01-26 20:03:58Z dchagin $ 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, fpregs, td2, &r) becomes 62147692Speter * proc_write_fpregs(td2, &r) or 63147692Speter * proc_write_fpregs32(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_doprocfpregs(PFS_FILL_ARGS) 821541Srgrimes{ 831541Srgrimes int error; 841541Srgrimes struct fpreg r; 85147692Speter struct thread *td2; 86205014Snwhitehorn#ifdef COMPAT_FREEBSD32 87147692Speter struct fpreg32 r32; 88147692Speter int wrap32 = 0; 89147692Speter#endif 901541Srgrimes 91168759Sdes if (uio->uio_offset != 0) 92168759Sdes return (0); 93168759Sdes 9494622Sjhb PROC_LOCK(p); 95136004Sdas KASSERT(p->p_lock > 0, ("proc not held")); 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 105120665Snectar /* XXXKSE: */ 106147692Speter td2 = FIRST_THREAD_IN_PROC(p); 107205014Snwhitehorn#ifdef COMPAT_FREEBSD32 108189282Skib if (SV_CURPROC_FLAG(SV_ILP32)) { 109217896Sdchagin if (SV_PROC_FLAG(td2->td_proc, SV_ILP32) == 0) { 110147692Speter PROC_UNLOCK(p); 111147692Speter return (EINVAL); 112147692Speter } 113147692Speter wrap32 = 1; 114147692Speter } 115147692Speter#endif 116147692Speter error = PROC(read, fpregs, td2, &r); 117114734Srwatson if (error == 0) { 118114734Srwatson PROC_UNLOCK(p); 119147692Speter error = UIOMOVE_FROMBUF(r, uio); 120114734Srwatson PROC_LOCK(p); 121114734Srwatson } 1221541Srgrimes if (error == 0 && uio->uio_rw == UIO_WRITE) { 12399072Sjulian if (!P_SHOULDSTOP(p)) 1241541Srgrimes error = EBUSY; 1251541Srgrimes else 12690716Sbde /* XXXKSE: */ 127147692Speter error = PROC(write, fpregs, td2, &r); 1281541Srgrimes } 12994622Sjhb PROC_UNLOCK(p); 1301541Srgrimes 1311541Srgrimes return (error); 1321541Srgrimes} 133