xref: /illumos-gate/usr/src/uts/common/sys/watchpoint.h (revision bbf21555)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_WATCHPOINT_H
287c478bd9Sstevel@tonic-gate #define	_SYS_WATCHPOINT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <vm/seg_enum.h>
327c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
337c478bd9Sstevel@tonic-gate #include <sys/avl.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Definitions for the VM implementation of watchpoints.
41*bbf21555SRichard Lowe  * See proc(5) and <sys/procfs.h> for definitions of the user interface.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Each process with watchpoints has a linked list of watched areas.
467c478bd9Sstevel@tonic-gate  * The list is kept sorted by user-level virtual address.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate typedef struct watched_area {
497c478bd9Sstevel@tonic-gate 	avl_node_t wa_link;	/* link in AVL tree */
507c478bd9Sstevel@tonic-gate 	caddr_t	wa_vaddr;	/* virtual address of watched area */
517c478bd9Sstevel@tonic-gate 	caddr_t	wa_eaddr;	/* virtual address plus size */
527c478bd9Sstevel@tonic-gate 	ulong_t	wa_flags;	/* watch type flags (see <sys/procfs.h>) */
537c478bd9Sstevel@tonic-gate } watched_area_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * The list of watched areas maps into a list of pages with modified
577c478bd9Sstevel@tonic-gate  * protections.  The list is kept sorted by user-level virtual address.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate typedef struct watched_page {
607c478bd9Sstevel@tonic-gate 	avl_node_t wp_link;	/* Link in AVL tree */
617c478bd9Sstevel@tonic-gate 	struct watched_page *wp_list;	/* link in p_wprot */
627c478bd9Sstevel@tonic-gate 	caddr_t	wp_vaddr;	/* virtual address of this page */
637c478bd9Sstevel@tonic-gate 	uchar_t	wp_prot;	/* modified protection bits */
647c478bd9Sstevel@tonic-gate 	uchar_t	wp_oprot;	/* original protection bits */
657c478bd9Sstevel@tonic-gate 	uchar_t	wp_umap[3];	/* reference counts of user pr_mappage()s */
667c478bd9Sstevel@tonic-gate 	uchar_t	wp_kmap[3];	/* reference counts of kernel pr_mappage()s */
677c478bd9Sstevel@tonic-gate 	ushort_t wp_flags;	/* see below */
687c478bd9Sstevel@tonic-gate 	short	wp_read;	/* number of WA_READ areas in this page */
697c478bd9Sstevel@tonic-gate 	short	wp_write;	/* number of WA_WRITE areas in this page */
707c478bd9Sstevel@tonic-gate 	short	wp_exec;	/* number of WA_EXEC areas in this page */
717c478bd9Sstevel@tonic-gate } watched_page_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /* wp_flags */
747c478bd9Sstevel@tonic-gate #define	WP_NOWATCH	0x01	/* protections temporarily restored */
757c478bd9Sstevel@tonic-gate #define	WP_SETPROT	0x02	/* SEGOP_SETPROT() needed on this page */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * These functions handle the necessary logic to perform the copy operation
817c478bd9Sstevel@tonic-gate  * while ignoring watchpoints.
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate extern int copyin_nowatch(const void *, void *, size_t);
847c478bd9Sstevel@tonic-gate extern int copyout_nowatch(const void *, void *, size_t);
857c478bd9Sstevel@tonic-gate extern int fuword32_nowatch(const void *, uint32_t *);
867c478bd9Sstevel@tonic-gate extern int suword32_nowatch(void *, uint32_t);
877c478bd9Sstevel@tonic-gate #ifdef _LP64
887c478bd9Sstevel@tonic-gate extern int suword64_nowatch(void *, uint64_t);
897c478bd9Sstevel@tonic-gate extern int fuword64_nowatch(const void *, uint64_t *);
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * Disable watchpoints for a given region of memory.  When bracketed by these
947c478bd9Sstevel@tonic-gate  * calls, functions can use copyops and ignore watchpoints.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate extern int watch_disable_addr(const void *, size_t, enum seg_rw);
977c478bd9Sstevel@tonic-gate extern void watch_enable_addr(const void *, size_t, enum seg_rw);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * Enable/Disable watchpoints for an entire thread.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate extern	void	watch_enable(kthread_id_t);
1037c478bd9Sstevel@tonic-gate extern	void	watch_disable(kthread_id_t);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate struct as;
1067c478bd9Sstevel@tonic-gate struct proc;
1077c478bd9Sstevel@tonic-gate struct k_siginfo;
1087c478bd9Sstevel@tonic-gate extern	void	setallwatch(void);
1097c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpage(caddr_t, enum seg_rw);
1107c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpage_as(caddr_t, enum seg_rw, struct as *);
1117c478bd9Sstevel@tonic-gate extern	int	pr_is_watchpoint(caddr_t *, int *, size_t, size_t *,
1127c478bd9Sstevel@tonic-gate 			enum seg_rw);
1137c478bd9Sstevel@tonic-gate extern	void	do_watch_step(caddr_t, size_t, enum seg_rw, int, greg_t);
1147c478bd9Sstevel@tonic-gate extern	int	undo_watch_step(struct k_siginfo *);
1157c478bd9Sstevel@tonic-gate extern	int	wp_compare(const void *, const void *);
1167c478bd9Sstevel@tonic-gate extern	int	wa_compare(const void *, const void *);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate extern	struct copyops watch_copyops;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate extern watched_area_t *pr_find_watched_area(struct proc *, watched_area_t *,
1217c478bd9Sstevel@tonic-gate     avl_index_t *);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #endif
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate #endif
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #endif	/* _SYS_WATCHPOINT_H */
130