procfs_fpregs.c revision 189282
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 189282 2009-03-02 18:43:50Z kib $ 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 56147692Speter#ifdef COMPAT_IA32 57147692Speter#include <sys/procfs.h> 58147692Speter#include <machine/fpu.h> 59147692Speter#include <compat/ia32/ia32_reg.h> 60147692Speter 61147692Speter/* 62147692Speter * PROC(write, fpregs, td2, &r) becomes 63147692Speter * proc_write_fpregs(td2, &r) or 64147692Speter * proc_write_fpregs32(td2, &r32) 65147692Speter * 66147692Speter * UIOMOVE_FROMBUF(r, uio) becomes 67147692Speter * uiomove_frombuf(&r, sizeof(r), uio) or 68147692Speter * uiomove_frombuf(&r32, sizeof(r32), uio) 69147692Speter */ 70147692Speter#define PROC(d, w, t, r) wrap32 ? \ 71147692Speter proc_ ## d ## _ ## w ## 32(t, r ## 32) : \ 72147692Speter proc_ ## d ## _ ## w(t, r) 73147692Speter#define UIOMOVE_FROMBUF(k, u) wrap32 ? \ 74147692Speter uiomove_frombuf(& k ## 32, sizeof(k ## 32), u) : \ 75147692Speter uiomove_frombuf(& k, sizeof(k), u) 76147692Speter#else 77147692Speter#define PROC(d, w, t, r) proc_ ## d ## _ ## w(t, r) 78147692Speter#define UIOMOVE_FROMBUF(k, u) uiomove_frombuf(& k, sizeof(k), u) 79147692Speter#endif 80147692Speter 811541Srgrimesint 8287321Sdesprocfs_doprocfpregs(PFS_FILL_ARGS) 831541Srgrimes{ 841541Srgrimes int error; 851541Srgrimes struct fpreg r; 86147692Speter struct thread *td2; 87147692Speter#ifdef COMPAT_IA32 88147692Speter struct fpreg32 r32; 89147692Speter int wrap32 = 0; 90147692Speter#endif 911541Srgrimes 92168759Sdes if (uio->uio_offset != 0) 93168759Sdes return (0); 94168759Sdes 9594622Sjhb PROC_LOCK(p); 96136004Sdas KASSERT(p->p_lock > 0, ("proc not held")); 9796886Sjhb if (p_candebug(td, p)) { 9894622Sjhb PROC_UNLOCK(p); 9990716Sbde return (EPERM); 10094622Sjhb } 1011541Srgrimes 102120665Snectar /* XXXKSE: */ 103147692Speter td2 = FIRST_THREAD_IN_PROC(p); 104147692Speter#ifdef COMPAT_IA32 105189282Skib if (SV_CURPROC_FLAG(SV_ILP32)) { 106189282Skib if ((td2->td_proc->p_sysent->sv_flags & SV_ILP32) == 0) { 107147692Speter PROC_UNLOCK(p); 108147692Speter return (EINVAL); 109147692Speter } 110147692Speter wrap32 = 1; 111147692Speter } 112147692Speter#endif 113147692Speter error = PROC(read, fpregs, td2, &r); 114114734Srwatson if (error == 0) { 115114734Srwatson PROC_UNLOCK(p); 116147692Speter error = UIOMOVE_FROMBUF(r, uio); 117114734Srwatson PROC_LOCK(p); 118114734Srwatson } 1191541Srgrimes if (error == 0 && uio->uio_rw == UIO_WRITE) { 12099072Sjulian if (!P_SHOULDSTOP(p)) 1211541Srgrimes error = EBUSY; 1221541Srgrimes else 12390716Sbde /* XXXKSE: */ 124147692Speter error = PROC(write, fpregs, td2, &r); 1251541Srgrimes } 12694622Sjhb PROC_UNLOCK(p); 1271541Srgrimes 1281541Srgrimes return (error); 1291541Srgrimes} 130