xref: /freebsd/sys/fs/procfs/procfs_dbregs.c (revision 3a669c52a81fa52a7c3aa5ac06ef6f1da5981db9)
1d6c4f011SJonathan Lemon /*-
2d6c4f011SJonathan Lemon  * Copyright (c) 1999 Brian Scott Dean, brdean@unx.sas.com.
3d6c4f011SJonathan Lemon  *                    All rights reserved.
4d6c4f011SJonathan Lemon  *
5d6c4f011SJonathan Lemon  * This code is derived from software contributed to Berkeley by
6d6c4f011SJonathan Lemon  * Jan-Simon Pendry under the following copyrights and conditions:
7d6c4f011SJonathan Lemon  *
8d6c4f011SJonathan Lemon  * Copyright (c) 1993 Jan-Simon Pendry
9d6c4f011SJonathan Lemon  * Copyright (c) 1993
10d6c4f011SJonathan Lemon  *	The Regents of the University of California.  All rights reserved.
11d6c4f011SJonathan Lemon  *
12d6c4f011SJonathan Lemon  * This code is derived from software contributed to Berkeley by
13d6c4f011SJonathan Lemon  * Jan-Simon Pendry.
14d6c4f011SJonathan Lemon  *
15d6c4f011SJonathan Lemon  * Redistribution and use in source and binary forms, with or without
16d6c4f011SJonathan Lemon  * modification, are permitted provided that the following conditions
17d6c4f011SJonathan Lemon  * are met:
18d6c4f011SJonathan Lemon  * 1. Redistributions of source code must retain the above copyright
19d6c4f011SJonathan Lemon  *    notice, this list of conditions and the following disclaimer.
20d6c4f011SJonathan Lemon  * 2. Redistributions in binary form must reproduce the above copyright
21d6c4f011SJonathan Lemon  *    notice, this list of conditions and the following disclaimer in the
22d6c4f011SJonathan Lemon  *    documentation and/or other materials provided with the distribution.
23d6c4f011SJonathan Lemon  * 3. All advertising materials mentioning features or use of this software
24d6c4f011SJonathan Lemon  *    must display the following acknowledgement:
25d6c4f011SJonathan Lemon  *	This product includes software developed by the University of
26d6c4f011SJonathan Lemon  *	California, Berkeley and its contributors.
27d6c4f011SJonathan Lemon  * 4. Neither the name of the University nor the names of its contributors
28d6c4f011SJonathan Lemon  *    may be used to endorse or promote products derived from this software
29d6c4f011SJonathan Lemon  *    without specific prior written permission.
30d6c4f011SJonathan Lemon  *
31d6c4f011SJonathan Lemon  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32d6c4f011SJonathan Lemon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33d6c4f011SJonathan Lemon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34d6c4f011SJonathan Lemon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35d6c4f011SJonathan Lemon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36d6c4f011SJonathan Lemon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37d6c4f011SJonathan Lemon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38d6c4f011SJonathan Lemon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39d6c4f011SJonathan Lemon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40d6c4f011SJonathan Lemon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41d6c4f011SJonathan Lemon  * SUCH DAMAGE.
42d6c4f011SJonathan Lemon  *
43c3aac50fSPeter Wemm  * $FreeBSD$
44d6c4f011SJonathan Lemon  */
45d6c4f011SJonathan Lemon 
46d6c4f011SJonathan Lemon #include <sys/param.h>
47fb919e4dSMark Murray #include <sys/systm.h>
48fb919e4dSMark Murray #include <sys/lock.h>
49fb919e4dSMark Murray #include <sys/mutex.h>
50d6c4f011SJonathan Lemon #include <sys/proc.h>
513da32491SDag-Erling Smørgrav #include <sys/ptrace.h>
523a669c52SDag-Erling Smørgrav #include <sys/uio.h>
53fb919e4dSMark Murray 
54d6c4f011SJonathan Lemon #include <machine/reg.h>
55fb919e4dSMark Murray 
563a669c52SDag-Erling Smørgrav #include <fs/pseudofs/pseudofs.h>
5799d300a1SRuslan Ermilov #include <fs/procfs/procfs.h>
58fb919e4dSMark Murray 
59d6c4f011SJonathan Lemon int
603a669c52SDag-Erling Smørgrav procfs_doprocdbregs(PFS_FILL_ARGS)
61d6c4f011SJonathan Lemon {
62d6c4f011SJonathan Lemon 	int error;
63d6c4f011SJonathan Lemon 	struct dbreg r;
64d6c4f011SJonathan Lemon 	char *kv;
65d6c4f011SJonathan Lemon 	int kl;
66d6c4f011SJonathan Lemon 
673a669c52SDag-Erling Smørgrav 	if (p_candebug(td->td_proc, p) != 0)
68d6c4f011SJonathan Lemon 		return (EPERM);
69d6c4f011SJonathan Lemon 	kl = sizeof(r);
70d6c4f011SJonathan Lemon 	kv = (char *) &r;
71d6c4f011SJonathan Lemon 
72d6c4f011SJonathan Lemon 	kv += uio->uio_offset;
73d6c4f011SJonathan Lemon 	kl -= uio->uio_offset;
74d6c4f011SJonathan Lemon 	if (kl > uio->uio_resid)
75d6c4f011SJonathan Lemon 		kl = uio->uio_resid;
76d6c4f011SJonathan Lemon 
77d6c4f011SJonathan Lemon 	if (kl < 0)
78d6c4f011SJonathan Lemon 		error = EINVAL;
79d6c4f011SJonathan Lemon 	else
807c629906SDag-Erling Smørgrav 		error = proc_read_dbregs(&p->p_thread, &r); /* XXXKSE */
81d6c4f011SJonathan Lemon 	if (error == 0)
82d6c4f011SJonathan Lemon 		error = uiomove(kv, kl, uio);
83d6c4f011SJonathan Lemon 	if (error == 0 && uio->uio_rw == UIO_WRITE) {
84d6c4f011SJonathan Lemon 		if (p->p_stat != SSTOP)
85d6c4f011SJonathan Lemon 			error = EBUSY;
86d6c4f011SJonathan Lemon 		else
877c629906SDag-Erling Smørgrav 			error = proc_write_dbregs(&p->p_thread, &r); /* XXXKSE */
88d6c4f011SJonathan Lemon 	}
89d6c4f011SJonathan Lemon 
90d6c4f011SJonathan Lemon 	uio->uio_offset = 0;
91d6c4f011SJonathan Lemon 	return (error);
92d6c4f011SJonathan Lemon }
93