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