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 /* 28*0Sstevel@tonic-gate * Public interface for AMD64 Unwind context 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ifndef _UNWIND_CONTEXT_H 32*0Sstevel@tonic-gate #define _UNWIND_CONTEXT_H 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate /* 37*0Sstevel@tonic-gate * implementation of context structure 38*0Sstevel@tonic-gate * 39*0Sstevel@tonic-gate * Register arrays are indexed as specified in reg_num.h 40*0Sstevel@tonic-gate */ 41*0Sstevel@tonic-gate struct _Unwind_Context { 42*0Sstevel@tonic-gate uint64_t entry_regs[16]; 43*0Sstevel@tonic-gate uint64_t current_regs[16]; 44*0Sstevel@tonic-gate uint64_t cfa; 45*0Sstevel@tonic-gate uint64_t pc; 46*0Sstevel@tonic-gate uint64_t ra; 47*0Sstevel@tonic-gate void *fde; 48*0Sstevel@tonic-gate _Unwind_Personality_Fn pfn; 49*0Sstevel@tonic-gate uint64_t func; 50*0Sstevel@tonic-gate void *lsda; 51*0Sstevel@tonic-gate uint64_t range; 52*0Sstevel@tonic-gate }; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate enum register_rule { 55*0Sstevel@tonic-gate undefined_rule, 56*0Sstevel@tonic-gate same_value_rule, /* target_reg = target_reg */ 57*0Sstevel@tonic-gate offset_rule, /* target_reg = *(offset + CFA) */ 58*0Sstevel@tonic-gate is_offset_rule, /* target_reg = offset + CFA */ 59*0Sstevel@tonic-gate register_rule, /* target_reg = offset + source_reg */ 60*0Sstevel@tonic-gate constant_rule, /* target_reg = offset */ 61*0Sstevel@tonic-gate indirect_rule /* target_reg = *(offset + source_reg) */ 62*0Sstevel@tonic-gate }; 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate struct register_state { 65*0Sstevel@tonic-gate uint64_t offset; 66*0Sstevel@tonic-gate enum register_rule rule; 67*0Sstevel@tonic-gate unsigned char source_reg; 68*0Sstevel@tonic-gate }; 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate struct eh_frame_fields { 71*0Sstevel@tonic-gate void *cie_ops; 72*0Sstevel@tonic-gate void *cie_ops_end; 73*0Sstevel@tonic-gate ptrdiff_t cie_reloc; 74*0Sstevel@tonic-gate int code_align; 75*0Sstevel@tonic-gate int data_align; 76*0Sstevel@tonic-gate int code_enc; 77*0Sstevel@tonic-gate void *fde_ops; 78*0Sstevel@tonic-gate void *fde_ops_end; 79*0Sstevel@tonic-gate ptrdiff_t fde_reloc; 80*0Sstevel@tonic-gate }; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate _Unwind_Reason_Code 83*0Sstevel@tonic-gate _Unw_very_boring_personality(int version, int actions, uint64_t exclass, 84*0Sstevel@tonic-gate struct _Unwind_Exception *exception_object, 85*0Sstevel@tonic-gate struct _Unwind_Context *ctx); 86*0Sstevel@tonic-gate /* 87*0Sstevel@tonic-gate * Starting withe an initialized context (from a ucontext) 88*0Sstevel@tonic-gate * the following routines are sufficient to implement a non-destructive 89*0Sstevel@tonic-gate * stack walk if modified to access the target processes memory. These 90*0Sstevel@tonic-gate * routines refer to the local address of an item using names containing 91*0Sstevel@tonic-gate * `data' names containing `reloc' give the correction to get target 92*0Sstevel@tonic-gate * process location. 93*0Sstevel@tonic-gate */ 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* ================== find function ====================== */ 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate /* 98*0Sstevel@tonic-gate * Computes the func and fde fields using pc as the lookup key. 99*0Sstevel@tonic-gate * Return is 0 or address of fde 100*0Sstevel@tonic-gate * 101*0Sstevel@tonic-gate * This is the only function that look into .eh_frame_hdr 102*0Sstevel@tonic-gate */ 103*0Sstevel@tonic-gate void *_Unw_EhfhLookup(struct _Unwind_Context *ctx); 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate /* =================== analyze function ================== */ 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate /* 108*0Sstevel@tonic-gate * Fills in personality_fn and lsda fields of the context based 109*0Sstevel@tonic-gate * the fde entry which must be valid and also partially unpacks 110*0Sstevel@tonic-gate * fde and cie into *f 111*0Sstevel@tonic-gate * 112*0Sstevel@tonic-gate * This is one of two functions that look inside fde's 113*0Sstevel@tonic-gate */ 114*0Sstevel@tonic-gate struct eh_frame_fields *_Unw_Decode_FDE(struct eh_frame_fields *f, 115*0Sstevel@tonic-gate struct _Unwind_Context *ctx); 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate /* 118*0Sstevel@tonic-gate * Computes register values at entry to function based on current 119*0Sstevel@tonic-gate * register values, pc and fde values in a context 120*0Sstevel@tonic-gate * 121*0Sstevel@tonic-gate * This is the other function which looks inside fde's and 122*0Sstevel@tonic-gate * the only one to look at CFA operations 123*0Sstevel@tonic-gate * 124*0Sstevel@tonic-gate * If 'f' is NULL (because no fde was found), a default calculation 125*0Sstevel@tonic-gate * assuming an FP is done. 126*0Sstevel@tonic-gate */ 127*0Sstevel@tonic-gate uint64_t _Unw_Rollback_Registers(struct eh_frame_fields *f, 128*0Sstevel@tonic-gate struct _Unwind_Context *ctx); 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* ================= register propagation =============== */ 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate /* 133*0Sstevel@tonic-gate * Fills in the current register context for the caller 134*0Sstevel@tonic-gate * based on computed at-entry state of callee 135*0Sstevel@tonic-gate */ 136*0Sstevel@tonic-gate void 137*0Sstevel@tonic-gate _Unw_Propagate_Registers(struct _Unwind_Context *old_ctx, 138*0Sstevel@tonic-gate struct _Unwind_Context *new_ctx); 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate /* ================================================= */ 141*0Sstevel@tonic-gate enum operand_desc { 142*0Sstevel@tonic-gate NO_OPR, 143*0Sstevel@tonic-gate ULEB128_FAC, 144*0Sstevel@tonic-gate ULEB128, 145*0Sstevel@tonic-gate ULEB128_SREG, 146*0Sstevel@tonic-gate SLEB128, 147*0Sstevel@tonic-gate SLEB128_FAC, 148*0Sstevel@tonic-gate ADDR, 149*0Sstevel@tonic-gate SIZE, 150*0Sstevel@tonic-gate ZTSTRING, 151*0Sstevel@tonic-gate UNUM6, 152*0Sstevel@tonic-gate UNUM6_CFAC, 153*0Sstevel@tonic-gate UNUM8, 154*0Sstevel@tonic-gate UNUM8_CFAC, 155*0Sstevel@tonic-gate UNUM16, 156*0Sstevel@tonic-gate UNUM16_CFAC, 157*0Sstevel@tonic-gate UNUM32, 158*0Sstevel@tonic-gate UNUM32_CFAC, 159*0Sstevel@tonic-gate UNUM64, 160*0Sstevel@tonic-gate SNUM8, 161*0Sstevel@tonic-gate SNUM16, 162*0Sstevel@tonic-gate SNUM32, 163*0Sstevel@tonic-gate SNUM64, 164*0Sstevel@tonic-gate BLOCK 165*0Sstevel@tonic-gate }; 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate uint64_t _Unw_get_val(void **datap, ptrdiff_t reloc, 168*0Sstevel@tonic-gate enum operand_desc opr, 169*0Sstevel@tonic-gate int daf, int caf, int enc); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate #endif /* _UNWIND_CONTEXT_H */ 172