10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211618Srie 220Sstevel@tonic-gate /* 23*4734Sab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <strings.h> 290Sstevel@tonic-gate #include <dwarf.h> 30*4734Sab196087 #include "_conv.h" 310Sstevel@tonic-gate #include <dwarf_ehe_msg.h> 320Sstevel@tonic-gate 331618Srie #define FLAGSZ MSG_GBL_OSQBRKT_SIZE + \ 341618Srie MSG_DWEHE_SLEB128_SIZE + \ 351618Srie MSG_DWEHE_INDIRECT_SIZE + \ 36*4734Sab196087 CONV_INV_BUFSIZE + MSG_GBL_CSQBRKT_SIZE 37*4734Sab196087 38*4734Sab196087 /* 39*4734Sab196087 * Ensure that Conv_dwarf_ehe_buf_t is large enough: 40*4734Sab196087 * 41*4734Sab196087 * FLAGSZ is the real minimum size of the buffer required by conv_dwarf_ehe(). 42*4734Sab196087 * However, Conv_dwarf_ehe_buf_t uses CONV_EHDR_FLAG_BUFSIZE to set the 43*4734Sab196087 * buffer size. We do things this way because the definition of FLAGSZ uses 44*4734Sab196087 * information that is not available in the environment of other programs 45*4734Sab196087 * that include the conv.h header file. 46*4734Sab196087 */ 47*4734Sab196087 #if (CONV_DWARF_EHE_BUFSIZE < FLAGSZ) && !defined(__lint) 48*4734Sab196087 #error "CONV_DWARF_EHE_BUFSIZE is not large enough" 49*4734Sab196087 #endif 501618Srie 510Sstevel@tonic-gate const char * 52*4734Sab196087 conv_dwarf_ehe(uint_t flags, Conv_dwarf_ehe_buf_t *dwarf_ehe_buf) 530Sstevel@tonic-gate { 54*4734Sab196087 char *buf = dwarf_ehe_buf->buf; 55*4734Sab196087 size_t ret = 0; 560Sstevel@tonic-gate 57*4734Sab196087 (void) strncpy(buf, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ); 581618Srie 591618Srie if (flags == DW_EH_PE_omit) 60*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_OMIT), FLAGSZ); 611618Srie else if (flags == DW_EH_PE_absptr) 62*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ABSPTR), FLAGSZ); 631618Srie 641618Srie if (ret >= FLAGSZ) 65*4734Sab196087 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 661618Srie 671618Srie if ((flags == DW_EH_PE_omit) || (flags == DW_EH_PE_absptr)) { 68*4734Sab196087 (void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ); 69*4734Sab196087 return (buf); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 720Sstevel@tonic-gate switch (flags & 0x0f) { 730Sstevel@tonic-gate case DW_EH_PE_uleb128: 74*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ULEB128), FLAGSZ); 750Sstevel@tonic-gate break; 760Sstevel@tonic-gate case DW_EH_PE_udata2: 77*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA2), FLAGSZ); 780Sstevel@tonic-gate break; 790Sstevel@tonic-gate case DW_EH_PE_udata4: 80*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA4), FLAGSZ); 810Sstevel@tonic-gate break; 820Sstevel@tonic-gate case DW_EH_PE_udata8: 83*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA8), FLAGSZ); 840Sstevel@tonic-gate break; 850Sstevel@tonic-gate case DW_EH_PE_sleb128: 86*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SLEB128), FLAGSZ); 870Sstevel@tonic-gate break; 880Sstevel@tonic-gate case DW_EH_PE_sdata2: 89*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA2), FLAGSZ); 900Sstevel@tonic-gate break; 910Sstevel@tonic-gate case DW_EH_PE_sdata4: 92*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA4), FLAGSZ); 930Sstevel@tonic-gate break; 940Sstevel@tonic-gate case DW_EH_PE_sdata8: 95*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA8), FLAGSZ); 960Sstevel@tonic-gate break; 970Sstevel@tonic-gate } 981618Srie if (ret >= FLAGSZ) 99*4734Sab196087 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate switch (flags & 0xf0) { 1020Sstevel@tonic-gate case DW_EH_PE_pcrel: 103*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_PCREL), FLAGSZ); 1040Sstevel@tonic-gate break; 1050Sstevel@tonic-gate case DW_EH_PE_textrel: 106*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_TEXTREL), FLAGSZ); 1070Sstevel@tonic-gate break; 1080Sstevel@tonic-gate case DW_EH_PE_datarel: 109*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_DATAREL), FLAGSZ); 1100Sstevel@tonic-gate break; 1110Sstevel@tonic-gate case DW_EH_PE_funcrel: 112*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_FUNCREL), FLAGSZ); 1130Sstevel@tonic-gate break; 1140Sstevel@tonic-gate case DW_EH_PE_aligned: 115*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ALIGNED), FLAGSZ); 1160Sstevel@tonic-gate break; 1170Sstevel@tonic-gate case DW_EH_PE_indirect: 118*4734Sab196087 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_INDIRECT), FLAGSZ); 1190Sstevel@tonic-gate break; 1200Sstevel@tonic-gate } 1211618Srie if (ret >= FLAGSZ) 122*4734Sab196087 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 1230Sstevel@tonic-gate 124*4734Sab196087 (void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ); 125*4734Sab196087 return (buf); 1260Sstevel@tonic-gate } 127