xref: /titanic_51/usr/src/uts/common/sys/watchpoint.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_WATCHPOINT_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_WATCHPOINT_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <vm/seg_enum.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/avl.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * Definitions for the VM implementation of watchpoints.
43*7c478bd9Sstevel@tonic-gate  * See proc(4) and <sys/procfs.h> for definitions of the user interface.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate  * Each process with watchpoints has a linked list of watched areas.
48*7c478bd9Sstevel@tonic-gate  * The list is kept sorted by user-level virtual address.
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate typedef struct watched_area {
51*7c478bd9Sstevel@tonic-gate 	avl_node_t wa_link;	/* link in AVL tree */
52*7c478bd9Sstevel@tonic-gate 	caddr_t	wa_vaddr;	/* virtual address of watched area */
53*7c478bd9Sstevel@tonic-gate 	caddr_t	wa_eaddr;	/* virtual address plus size */
54*7c478bd9Sstevel@tonic-gate 	ulong_t	wa_flags;	/* watch type flags (see <sys/procfs.h>) */
55*7c478bd9Sstevel@tonic-gate } watched_area_t;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * The list of watched areas maps into a list of pages with modified
59*7c478bd9Sstevel@tonic-gate  * protections.  The list is kept sorted by user-level virtual address.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate typedef struct watched_page {
62*7c478bd9Sstevel@tonic-gate 	avl_node_t wp_link;	/* Link in AVL tree */
63*7c478bd9Sstevel@tonic-gate 	struct watched_page *wp_list;	/* link in p_wprot */
64*7c478bd9Sstevel@tonic-gate 	caddr_t	wp_vaddr;	/* virtual address of this page */
65*7c478bd9Sstevel@tonic-gate 	uchar_t	wp_prot;	/* modified protection bits */
66*7c478bd9Sstevel@tonic-gate 	uchar_t	wp_oprot;	/* original protection bits */
67*7c478bd9Sstevel@tonic-gate 	uchar_t	wp_umap[3];	/* reference counts of user pr_mappage()s */
68*7c478bd9Sstevel@tonic-gate 	uchar_t	wp_kmap[3];	/* reference counts of kernel pr_mappage()s */
69*7c478bd9Sstevel@tonic-gate 	ushort_t wp_flags;	/* see below */
70*7c478bd9Sstevel@tonic-gate 	short	wp_read;	/* number of WA_READ areas in this page */
71*7c478bd9Sstevel@tonic-gate 	short	wp_write;	/* number of WA_WRITE areas in this page */
72*7c478bd9Sstevel@tonic-gate 	short	wp_exec;	/* number of WA_EXEC areas in this page */
73*7c478bd9Sstevel@tonic-gate } watched_page_t;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /* wp_flags */
76*7c478bd9Sstevel@tonic-gate #define	WP_NOWATCH	0x01	/* protections temporarily restored */
77*7c478bd9Sstevel@tonic-gate #define	WP_SETPROT	0x02	/* SEGOP_SETPROT() needed on this page */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate  * These functions handle the necessary logic to perform the copy operation
83*7c478bd9Sstevel@tonic-gate  * while ignoring watchpoints.
84*7c478bd9Sstevel@tonic-gate  */
85*7c478bd9Sstevel@tonic-gate extern int copyin_nowatch(const void *, void *, size_t);
86*7c478bd9Sstevel@tonic-gate extern int copyout_nowatch(const void *, void *, size_t);
87*7c478bd9Sstevel@tonic-gate extern int fuword32_nowatch(const void *, uint32_t *);
88*7c478bd9Sstevel@tonic-gate extern int suword32_nowatch(void *, uint32_t);
89*7c478bd9Sstevel@tonic-gate #ifdef _LP64
90*7c478bd9Sstevel@tonic-gate extern int suword64_nowatch(void *, uint64_t);
91*7c478bd9Sstevel@tonic-gate extern int fuword64_nowatch(const void *, uint64_t *);
92*7c478bd9Sstevel@tonic-gate #endif
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate  * Disable watchpoints for a given region of memory.  When bracketed by these
96*7c478bd9Sstevel@tonic-gate  * calls, functions can use copyops and ignore watchpoints.
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate extern int watch_disable_addr(const void *, size_t, enum seg_rw);
99*7c478bd9Sstevel@tonic-gate extern void watch_enable_addr(const void *, size_t, enum seg_rw);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * Enable/Disable watchpoints for an entire thread.
103*7c478bd9Sstevel@tonic-gate  */
104*7c478bd9Sstevel@tonic-gate extern	void	watch_enable(kthread_id_t);
105*7c478bd9Sstevel@tonic-gate extern	void	watch_disable(kthread_id_t);
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate struct as;
108*7c478bd9Sstevel@tonic-gate struct proc;
109*7c478bd9Sstevel@tonic-gate struct k_siginfo;
110*7c478bd9Sstevel@tonic-gate extern	void	setallwatch(void);
111*7c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpage(caddr_t, enum seg_rw);
112*7c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpage_as(caddr_t, enum seg_rw, struct as *);
113*7c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpoint(caddr_t *, int *, size_t, size_t *,
114*7c478bd9Sstevel@tonic-gate 			enum seg_rw);
115*7c478bd9Sstevel@tonic-gate extern	void	do_watch_step(caddr_t, size_t, enum seg_rw, int, greg_t);
116*7c478bd9Sstevel@tonic-gate extern	int	undo_watch_step(struct k_siginfo *);
117*7c478bd9Sstevel@tonic-gate extern	int	wp_compare(const void *, const void *);
118*7c478bd9Sstevel@tonic-gate extern	int	wa_compare(const void *, const void *);
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate extern	struct copyops watch_copyops;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate extern watched_area_t *pr_find_watched_area(struct proc *, watched_area_t *,
123*7c478bd9Sstevel@tonic-gate     avl_index_t *);
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate #endif
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate #endif
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_WATCHPOINT_H */
132