xref: /freebsd/sys/fs/procfs/procfs_dbregs.c (revision f44d9e24fbb396076ebabf326c6f80e166d3d4a5)
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  *
43a76d60f0SBruce Evans  *	From: @(#)procfs_regs.c	8.4 (Berkeley) 6/15/94
44a76d60f0SBruce Evans  *
45a76d60f0SBruce Evans  * From:
46a76d60f0SBruce Evans  *	$Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
47c3aac50fSPeter Wemm  * $FreeBSD$
48d6c4f011SJonathan Lemon  */
49d6c4f011SJonathan Lemon 
50d6c4f011SJonathan Lemon #include <sys/param.h>
51fb919e4dSMark Murray #include <sys/systm.h>
52fb919e4dSMark Murray #include <sys/lock.h>
53fb919e4dSMark Murray #include <sys/mutex.h>
54d6c4f011SJonathan Lemon #include <sys/proc.h>
553da32491SDag-Erling Smørgrav #include <sys/ptrace.h>
563a669c52SDag-Erling Smørgrav #include <sys/uio.h>
57fb919e4dSMark Murray 
58d6c4f011SJonathan Lemon #include <machine/reg.h>
59fb919e4dSMark Murray 
603a669c52SDag-Erling Smørgrav #include <fs/pseudofs/pseudofs.h>
6199d300a1SRuslan Ermilov #include <fs/procfs/procfs.h>
62fb919e4dSMark Murray 
63d6c4f011SJonathan Lemon int
643a669c52SDag-Erling Smørgrav procfs_doprocdbregs(PFS_FILL_ARGS)
65d6c4f011SJonathan Lemon {
66d6c4f011SJonathan Lemon 	int error;
67d6c4f011SJonathan Lemon 	struct dbreg r;
68d6c4f011SJonathan Lemon 	char *kv;
69d6c4f011SJonathan Lemon 	int kl;
70d6c4f011SJonathan Lemon 
71ff7299d9SJohn Baldwin 	PROC_LOCK(p);
72f44d9e24SJohn Baldwin 	if (p_candebug(td, p) != 0) {
73ff7299d9SJohn Baldwin 		PROC_UNLOCK(p);
74d6c4f011SJonathan Lemon 		return (EPERM);
75ff7299d9SJohn Baldwin 	}
76d6c4f011SJonathan Lemon 	kl = sizeof(r);
77d6c4f011SJonathan Lemon 	kv = (char *) &r;
78d6c4f011SJonathan Lemon 
79d6c4f011SJonathan Lemon 	kv += uio->uio_offset;
80d6c4f011SJonathan Lemon 	kl -= uio->uio_offset;
81d6c4f011SJonathan Lemon 	if (kl > uio->uio_resid)
82d6c4f011SJonathan Lemon 		kl = uio->uio_resid;
83d6c4f011SJonathan Lemon 
84ff7299d9SJohn Baldwin 	_PHOLD(p);
85d6c4f011SJonathan Lemon 	if (kl < 0)
86d6c4f011SJonathan Lemon 		error = EINVAL;
87d6c4f011SJonathan Lemon 	else
88a76d60f0SBruce Evans 		/* XXXKSE: */
89a76d60f0SBruce Evans 		error = proc_read_dbregs(FIRST_THREAD_IN_PROC(p), &r);
90d6c4f011SJonathan Lemon 	if (error == 0)
91d6c4f011SJonathan Lemon 		error = uiomove(kv, kl, uio);
92d6c4f011SJonathan Lemon 	if (error == 0 && uio->uio_rw == UIO_WRITE) {
93d6c4f011SJonathan Lemon 		if (p->p_stat != SSTOP)
94d6c4f011SJonathan Lemon 			error = EBUSY;
95d6c4f011SJonathan Lemon 		else
96a76d60f0SBruce Evans 			/* XXXKSE: */
97a76d60f0SBruce Evans 			error = proc_write_dbregs(FIRST_THREAD_IN_PROC(p), &r);
98d6c4f011SJonathan Lemon 	}
99ff7299d9SJohn Baldwin 	_PRELE(p);
100ff7299d9SJohn Baldwin 	PROC_UNLOCK(p);
101d6c4f011SJonathan Lemon 
102d6c4f011SJonathan Lemon 	uio->uio_offset = 0;
103d6c4f011SJonathan Lemon 	return (error);
104d6c4f011SJonathan Lemon }
105