1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <strings.h> 29 #include <dwarf.h> 30 #include "_conv.h" 31 #include <dwarf_ehe_msg.h> 32 33 #define FLAGSZ MSG_GBL_OSQBRKT_SIZE + \ 34 MSG_DWEHE_SLEB128_SIZE + \ 35 MSG_DWEHE_INDIRECT_SIZE + \ 36 CONV_INV_BUFSIZE + MSG_GBL_CSQBRKT_SIZE 37 38 /* 39 * Ensure that Conv_dwarf_ehe_buf_t is large enough: 40 * 41 * FLAGSZ is the real minimum size of the buffer required by conv_dwarf_ehe(). 42 * However, Conv_dwarf_ehe_buf_t uses CONV_EHDR_FLAG_BUFSIZE to set the 43 * buffer size. We do things this way because the definition of FLAGSZ uses 44 * information that is not available in the environment of other programs 45 * that include the conv.h header file. 46 */ 47 #if (CONV_DWARF_EHE_BUFSIZE < FLAGSZ) && !defined(__lint) 48 #error "CONV_DWARF_EHE_BUFSIZE is not large enough" 49 #endif 50 51 const char * 52 conv_dwarf_ehe(uint_t flags, Conv_dwarf_ehe_buf_t *dwarf_ehe_buf) 53 { 54 char *buf = dwarf_ehe_buf->buf; 55 size_t ret = 0; 56 57 (void) strncpy(buf, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ); 58 59 if (flags == DW_EH_PE_omit) 60 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_OMIT), FLAGSZ); 61 else if (flags == DW_EH_PE_absptr) 62 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ABSPTR), FLAGSZ); 63 64 if (ret >= FLAGSZ) 65 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 66 67 if ((flags == DW_EH_PE_omit) || (flags == DW_EH_PE_absptr)) { 68 (void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ); 69 return (buf); 70 } 71 72 switch (flags & 0x0f) { 73 case DW_EH_PE_uleb128: 74 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ULEB128), FLAGSZ); 75 break; 76 case DW_EH_PE_udata2: 77 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA2), FLAGSZ); 78 break; 79 case DW_EH_PE_udata4: 80 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA4), FLAGSZ); 81 break; 82 case DW_EH_PE_udata8: 83 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA8), FLAGSZ); 84 break; 85 case DW_EH_PE_sleb128: 86 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SLEB128), FLAGSZ); 87 break; 88 case DW_EH_PE_sdata2: 89 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA2), FLAGSZ); 90 break; 91 case DW_EH_PE_sdata4: 92 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA4), FLAGSZ); 93 break; 94 case DW_EH_PE_sdata8: 95 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA8), FLAGSZ); 96 break; 97 } 98 if (ret >= FLAGSZ) 99 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 100 101 switch (flags & 0xf0) { 102 case DW_EH_PE_pcrel: 103 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_PCREL), FLAGSZ); 104 break; 105 case DW_EH_PE_textrel: 106 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_TEXTREL), FLAGSZ); 107 break; 108 case DW_EH_PE_datarel: 109 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_DATAREL), FLAGSZ); 110 break; 111 case DW_EH_PE_funcrel: 112 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_FUNCREL), FLAGSZ); 113 break; 114 case DW_EH_PE_aligned: 115 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ALIGNED), FLAGSZ); 116 break; 117 case DW_EH_PE_indirect: 118 ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_INDIRECT), FLAGSZ); 119 break; 120 } 121 if (ret >= FLAGSZ) 122 return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0)); 123 124 (void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ); 125 return (buf); 126 } 127