1a76d60f0SBruce Evans /*- 2df8bae1dSRodney W. Grimes * Copyright (c) 1993 Jan-Simon Pendry 3df8bae1dSRodney W. Grimes * Copyright (c) 1993 4df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 5df8bae1dSRodney W. Grimes * 6df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 7df8bae1dSRodney W. Grimes * Jan-Simon Pendry. 8df8bae1dSRodney W. Grimes * 9df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 10df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 11df8bae1dSRodney W. Grimes * are met: 12df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 14df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 15df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 16df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 17*fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33996c772fSJohn Dyson * @(#)procfs_fpregs.c 8.2 (Berkeley) 6/15/94 34df8bae1dSRodney W. Grimes * 35996c772fSJohn Dyson * From: 36a76d60f0SBruce Evans * $Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $ 37c3aac50fSPeter Wemm * $FreeBSD$ 38df8bae1dSRodney W. Grimes */ 39df8bae1dSRodney W. Grimes 4062919d78SPeter Wemm #include "opt_compat.h" 4162919d78SPeter Wemm 42df8bae1dSRodney W. Grimes #include <sys/param.h> 43fb919e4dSMark Murray #include <sys/systm.h> 44fb919e4dSMark Murray #include <sys/lock.h> 45fb919e4dSMark Murray #include <sys/mutex.h> 46df8bae1dSRodney W. Grimes #include <sys/proc.h> 473da32491SDag-Erling Smørgrav #include <sys/ptrace.h> 482883703eSKonstantin Belousov #include <sys/sysent.h> 493a669c52SDag-Erling Smørgrav #include <sys/uio.h> 50fb919e4dSMark Murray 51df8bae1dSRodney W. Grimes #include <machine/reg.h> 52fb919e4dSMark Murray 533a669c52SDag-Erling Smørgrav #include <fs/pseudofs/pseudofs.h> 5499d300a1SRuslan Ermilov #include <fs/procfs/procfs.h> 55fb919e4dSMark Murray 56841c0c7eSNathan Whitehorn #ifdef COMPAT_FREEBSD32 5762919d78SPeter Wemm #include <sys/procfs.h> 5862919d78SPeter Wemm #include <machine/fpu.h> 5962919d78SPeter Wemm 6062919d78SPeter Wemm /* 6162919d78SPeter Wemm * PROC(write, fpregs, td2, &r) becomes 6262919d78SPeter Wemm * proc_write_fpregs(td2, &r) or 6362919d78SPeter Wemm * proc_write_fpregs32(td2, &r32) 6462919d78SPeter Wemm * 6562919d78SPeter Wemm * UIOMOVE_FROMBUF(r, uio) becomes 6662919d78SPeter Wemm * uiomove_frombuf(&r, sizeof(r), uio) or 6762919d78SPeter Wemm * uiomove_frombuf(&r32, sizeof(r32), uio) 6862919d78SPeter Wemm */ 6962919d78SPeter Wemm #define PROC(d, w, t, r) wrap32 ? \ 7062919d78SPeter Wemm proc_ ## d ## _ ## w ## 32(t, r ## 32) : \ 7162919d78SPeter Wemm proc_ ## d ## _ ## w(t, r) 7262919d78SPeter Wemm #define UIOMOVE_FROMBUF(k, u) wrap32 ? \ 7362919d78SPeter Wemm uiomove_frombuf(& k ## 32, sizeof(k ## 32), u) : \ 7462919d78SPeter Wemm uiomove_frombuf(& k, sizeof(k), u) 7562919d78SPeter Wemm #else 7662919d78SPeter Wemm #define PROC(d, w, t, r) proc_ ## d ## _ ## w(t, r) 7762919d78SPeter Wemm #define UIOMOVE_FROMBUF(k, u) uiomove_frombuf(& k, sizeof(k), u) 7862919d78SPeter Wemm #endif 7962919d78SPeter Wemm 80df8bae1dSRodney W. Grimes int 813a669c52SDag-Erling Smørgrav procfs_doprocfpregs(PFS_FILL_ARGS) 82df8bae1dSRodney W. Grimes { 83df8bae1dSRodney W. Grimes int error; 84df8bae1dSRodney W. Grimes struct fpreg r; 8562919d78SPeter Wemm struct thread *td2; 86841c0c7eSNathan Whitehorn #ifdef COMPAT_FREEBSD32 8762919d78SPeter Wemm struct fpreg32 r32; 8862919d78SPeter Wemm int wrap32 = 0; 8962919d78SPeter Wemm #endif 90df8bae1dSRodney W. Grimes 91302762c3SDag-Erling Smørgrav if (uio->uio_offset != 0) 92302762c3SDag-Erling Smørgrav return (0); 93302762c3SDag-Erling Smørgrav 94ff7299d9SJohn Baldwin PROC_LOCK(p); 95d2871337SMark Johnston PROC_ASSERT_HELD(p); 96f44d9e24SJohn Baldwin if (p_candebug(td, p)) { 97ff7299d9SJohn Baldwin PROC_UNLOCK(p); 98a76d60f0SBruce Evans return (EPERM); 99ff7299d9SJohn Baldwin } 100847e02e9SKonstantin Belousov if (!P_SHOULDSTOP(p)) { 101847e02e9SKonstantin Belousov PROC_UNLOCK(p); 102847e02e9SKonstantin Belousov return (EBUSY); 103847e02e9SKonstantin Belousov } 104df8bae1dSRodney W. Grimes 105a76d60f0SBruce Evans /* XXXKSE: */ 10662919d78SPeter Wemm td2 = FIRST_THREAD_IN_PROC(p); 107841c0c7eSNathan Whitehorn #ifdef COMPAT_FREEBSD32 1082883703eSKonstantin Belousov if (SV_CURPROC_FLAG(SV_ILP32)) { 109a5c1afadSDmitry Chagin if (SV_PROC_FLAG(td2->td_proc, SV_ILP32) == 0) { 11062919d78SPeter Wemm PROC_UNLOCK(p); 11162919d78SPeter Wemm return (EINVAL); 11262919d78SPeter Wemm } 11362919d78SPeter Wemm wrap32 = 1; 11462919d78SPeter Wemm } 11562919d78SPeter Wemm #endif 11662919d78SPeter Wemm error = PROC(read, fpregs, td2, &r); 117587ffa45SRobert Watson if (error == 0) { 118587ffa45SRobert Watson PROC_UNLOCK(p); 11962919d78SPeter Wemm error = UIOMOVE_FROMBUF(r, uio); 120587ffa45SRobert Watson PROC_LOCK(p); 121587ffa45SRobert Watson } 122df8bae1dSRodney W. Grimes if (error == 0 && uio->uio_rw == UIO_WRITE) { 123e602ba25SJulian Elischer if (!P_SHOULDSTOP(p)) 124df8bae1dSRodney W. Grimes error = EBUSY; 125df8bae1dSRodney W. Grimes else 126a76d60f0SBruce Evans /* XXXKSE: */ 12762919d78SPeter Wemm error = PROC(write, fpregs, td2, &r); 128df8bae1dSRodney W. Grimes } 129ff7299d9SJohn Baldwin PROC_UNLOCK(p); 130df8bae1dSRodney W. Grimes 131df8bae1dSRodney W. Grimes return (error); 132df8bae1dSRodney W. Grimes } 133