procfs_regs.c revision 85297
1194140Simp/*
2194140Simp * Copyright (c) 1993 Jan-Simon Pendry
3194140Simp * Copyright (c) 1993
4206721Sjmallett *	The Regents of the University of California.  All rights reserved.
5210311Sjmallett *
6202063Simp * This code is derived from software contributed to Berkeley by
7210311Sjmallett * Jan-Simon Pendry.
8202063Simp *
9202063Simp * Redistribution and use in source and binary forms, with or without
10206721Sjmallett * modification, are permitted provided that the following conditions
11233336Sgonzo * are met:
12210311Sjmallett * 1. Redistributions of source code must retain the above copyright
13202063Simp *    notice, this list of conditions and the following disclaimer.
14202063Simp * 2. Redistributions in binary form must reproduce the above copyright
15202063Simp *    notice, this list of conditions and the following disclaimer in the
16198154Srrs *    documentation and/or other materials provided with the distribution.
17198669Srrs * 3. All advertising materials mentioning features or use of this software
18210311Sjmallett *    must display the following acknowledgement:
19210311Sjmallett *	This product includes software developed by the University of
20215989Sgonzo *	California, Berkeley and its contributors.
21215989Sgonzo * 4. Neither the name of the University nor the names of its contributors
22210311Sjmallett *    may be used to endorse or promote products derived from this software
23210312Sjmallett *    without specific prior written permission.
24210312Sjmallett *
25229677Sgonzo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26229677Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27210312Sjmallett * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28231987Sgonzo * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29231987Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30231987Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31210311Sjmallett * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32213346Sjmallett * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33210311Sjmallett * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34210311Sjmallett * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35210311Sjmallett * SUCH DAMAGE.
36210311Sjmallett *
37210311Sjmallett *	@(#)procfs_regs.c	8.4 (Berkeley) 6/15/94
38210311Sjmallett *
39210311Sjmallett * From:
40210311Sjmallett * $FreeBSD: head/sys/fs/procfs/procfs_regs.c 85297 2001-10-21 23:57:24Z des $
41210311Sjmallett */
42213762Sjmallett
43210311Sjmallett#include <sys/param.h>
44210311Sjmallett#include <sys/systm.h>
45210311Sjmallett#include <sys/lock.h>
46210311Sjmallett#include <sys/mutex.h>
47210311Sjmallett#include <sys/proc.h>
48210311Sjmallett#include <sys/ptrace.h>
49210312Sjmallett#include <sys/vnode.h>
50210312Sjmallett
51210312Sjmallett#include <machine/reg.h>
52210312Sjmallett
53210312Sjmallett#include <vm/vm.h>
54228925Sgonzo#include <vm/vm_extern.h>
55228925Sgonzo
56210311Sjmallett#include <fs/procfs/procfs.h>
57210311Sjmallett
58213140Sjmallettint
59210311Sjmallettprocfs_doregs(curp, p, pfs, uio)
60215990Sjmallett	struct proc *curp;
61213140Sjmallett	struct proc *p;
62213140Sjmallett	struct pfsnode *pfs;
63213140Sjmallett	struct uio *uio;
64232812Sjmallett{
65213140Sjmallett	int error;
66213140Sjmallett	struct reg r;
67232812Sjmallett	char *kv;
68215990Sjmallett	int kl;
69213140Sjmallett
70213140Sjmallett	if (p_candebug(curp, p))
71213140Sjmallett		return EPERM;
72213140Sjmallett	kl = sizeof(r);
73213140Sjmallett	kv = (char *) &r;
74215990Sjmallett
75213140Sjmallett	kv += uio->uio_offset;
76213140Sjmallett	kl -= uio->uio_offset;
77232812Sjmallett	if (kl > uio->uio_resid)
78232812Sjmallett		kl = uio->uio_resid;
79215990Sjmallett
80215990Sjmallett	PHOLD(p);
81213140Sjmallett
82232812Sjmallett	if (kl < 0)
83232812Sjmallett		error = EINVAL;
84213140Sjmallett	else
85213140Sjmallett		error = proc_read_regs(&p->p_thread, &r); /* XXXKSE */
86215990Sjmallett	if (error == 0)
87210311Sjmallett		error = uiomove(kv, kl, uio);
88210311Sjmallett	if (error == 0 && uio->uio_rw == UIO_WRITE) {
89213140Sjmallett		if (p->p_stat != SSTOP)
90210311Sjmallett			error = EBUSY;
91210311Sjmallett		else
92233336Sgonzo			error = proc_write_regs(&p->p_thread, &r); /* XXXKSE */
93233336Sgonzo	}
94233336Sgonzo	PRELE(p);
95
96	uio->uio_offset = 0;
97	return (error);
98}
99
100int
101procfs_validregs(struct thread *td)
102{
103
104	return ((td->td_proc->p_flag & P_SYSTEM) == 0);
105}
106