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 _ONTRAP_H 28*0Sstevel@tonic-gate #define _ONTRAP_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #if !defined(_ASM) 33*0Sstevel@tonic-gate #include <sys/types.h> 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #ifdef __cplusplus 37*0Sstevel@tonic-gate extern "C" { 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* 41*0Sstevel@tonic-gate * on_trap() provides protection against various kinds of machine exceptions, 42*0Sstevel@tonic-gate * and must be used with extreme caution. Like setjmp(), on_trap() returns 43*0Sstevel@tonic-gate * zero when explicitly called and non-zero when it returns as the result of 44*0Sstevel@tonic-gate * an exception. The caller should not attempt to interpret the actual integer 45*0Sstevel@tonic-gate * return value except to test whether it is zero or non-zero. on_trap() and 46*0Sstevel@tonic-gate * no_trap() are NOT DDI interfaces for public consumption. For now, the 47*0Sstevel@tonic-gate * on_trap() mechanism is separate from on_fault() protection and the t_lofault 48*0Sstevel@tonic-gate * protection used by the various copy routines. 49*0Sstevel@tonic-gate * 50*0Sstevel@tonic-gate * Calls to on_trap() may be nested, but only the most recently installed bits 51*0Sstevel@tonic-gate * apply. Protection bits may be OR-ed together if the caller wishes to 52*0Sstevel@tonic-gate * protect against more than one type of trap. If on_trap() returns non-zero, 53*0Sstevel@tonic-gate * the bit corresponding to the trap that triggered return to on_trap() will 54*0Sstevel@tonic-gate * be stored in the ot_trap field of the caller's on_trap_data. 55*0Sstevel@tonic-gate * 56*0Sstevel@tonic-gate * After calling on_trap(), the caller may elect to modify ot_trampoline to 57*0Sstevel@tonic-gate * install a custom trampoline routine prior to executing the protected code 58*0Sstevel@tonic-gate * region. No other fields of the on_trap_data should be modified by the 59*0Sstevel@tonic-gate * caller. The trampoline may not be applicable on all platforms. 60*0Sstevel@tonic-gate * 61*0Sstevel@tonic-gate * The on_trap_data structures are kept in a stack (linked list) whose top 62*0Sstevel@tonic-gate * is pointed to by the current thread's t_ontrap field. A no_trap() call 63*0Sstevel@tonic-gate * pops the top element from the stack and resets t_ontrap to ot_prev. 64*0Sstevel@tonic-gate * We assume the caller has allocated the on_trap_data on the stack or 65*0Sstevel@tonic-gate * made other arrangements, so we do not need to worry about deallocation. 66*0Sstevel@tonic-gate * 67*0Sstevel@tonic-gate * If repeated calls to on_trap() are made using the same on_trap_data address, 68*0Sstevel@tonic-gate * the topmost stack element is modified in-place (the same on_trap_data is 69*0Sstevel@tonic-gate * not pushed twice), allowing callers to use on_trap() in a loop. The act 70*0Sstevel@tonic-gate * of catching an exception does NOT modify t_ontrap. Even if on_trap() 71*0Sstevel@tonic-gate * returns non-zero, the caller must use no_trap() to clear trap protection. 72*0Sstevel@tonic-gate * 73*0Sstevel@tonic-gate * Calls to no_trap() are permitted when the on_trap_data stack is empty; they 74*0Sstevel@tonic-gate * have no effect. no_trap() only modifies t_ontrap; it does not modify the 75*0Sstevel@tonic-gate * internals of the topmost on_trap_data element. It is therefore legal for 76*0Sstevel@tonic-gate * callers to examine the contents of the on_trap_data (specifically ot_trap) 77*0Sstevel@tonic-gate * after the data is popped using no_trap(). 78*0Sstevel@tonic-gate * 79*0Sstevel@tonic-gate * A given platform may not implement all the forms of on_trap() protection. 80*0Sstevel@tonic-gate * The on_trap_data will be pushed on the t_ontrap stack with ot_prot set 81*0Sstevel@tonic-gate * regardless. We must guarantee that if the platform does not implement 82*0Sstevel@tonic-gate * a trap protection, the exceptional condition will trigger a panic. We do 83*0Sstevel@tonic-gate * not permit a platform to allow the exceptional condition to occur silently 84*0Sstevel@tonic-gate * and then continue to execute the caller's protected code region. 85*0Sstevel@tonic-gate */ 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate #define OT_DATA_ACCESS 0x01 /* data access exception protection */ 88*0Sstevel@tonic-gate #define OT_DATA_EC 0x02 /* error correction trap protection */ 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate #if !defined(_ASM) 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate typedef struct on_trap_data { 93*0Sstevel@tonic-gate ushort_t ot_prot; /* active protection bits (see above) */ 94*0Sstevel@tonic-gate ushort_t ot_trap; /* bit of actual trap that occurred */ 95*0Sstevel@tonic-gate uintptr_t ot_trampoline; /* %pc for trap return (if any) */ 96*0Sstevel@tonic-gate label_t ot_jmpbuf; /* label for longjmp back to on_trap */ 97*0Sstevel@tonic-gate struct on_trap_data *ot_prev; /* pointer to previous on_trap_data */ 98*0Sstevel@tonic-gate void *ot_handle; /* access handle */ 99*0Sstevel@tonic-gate void *ot_pad1; /* reserved for future use */ 100*0Sstevel@tonic-gate } on_trap_data_t; 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate #if defined(_KERNEL) 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate extern int on_trap(on_trap_data_t *, uint_t); 105*0Sstevel@tonic-gate #pragma unknown_control_flow(on_trap) 106*0Sstevel@tonic-gate extern void no_trap(void); 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate extern void on_trap_trampoline(void); /* default trampoline */ 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate #endif /* _KERNEL */ 111*0Sstevel@tonic-gate #endif /* !_ASM */ 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate #ifdef __cplusplus 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate #endif 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate #endif /* _ONTRAP_H */ 118