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 /* 231618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 241618Srie * 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 <string.h> 290Sstevel@tonic-gate #include "_conv.h" 300Sstevel@tonic-gate #include "dl_msg.h" 310Sstevel@tonic-gate 32*2352Sab196087 #define MODESZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 33*2352Sab196087 MSG_RTLD_LAZY_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 34*2352Sab196087 MSG_RTLD_GLOBAL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 35*2352Sab196087 MSG_RTLD_NOLOAD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 36*2352Sab196087 MSG_RTLD_PARENT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 37*2352Sab196087 MSG_RTLD_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 38*2352Sab196087 MSG_RTLD_WORLD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 39*2352Sab196087 MSG_RTLD_NODELETE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 40*2352Sab196087 MSG_RTLD_FIRST_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 41*2352Sab196087 MSG_RTLD_CONFGEN_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 42*2352Sab196087 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 431618Srie 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * String conversion routine for dlopen() attributes. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate const char * 491618Srie conv_dl_mode(int mode, int fabricate) 500Sstevel@tonic-gate { 511618Srie static char string[MODESZ]; 521618Srie static Val_desc vda[] = { 531618Srie { RTLD_NOLOAD, MSG_ORIG(MSG_RTLD_NOLOAD) }, 541618Srie { RTLD_PARENT, MSG_ORIG(MSG_RTLD_PARENT) }, 551618Srie { RTLD_GROUP, MSG_ORIG(MSG_RTLD_GROUP) }, 561618Srie { RTLD_WORLD, MSG_ORIG(MSG_RTLD_WORLD) }, 571618Srie { RTLD_NODELETE, MSG_ORIG(MSG_RTLD_NODELETE) }, 581618Srie { RTLD_FIRST, MSG_ORIG(MSG_RTLD_FIRST) }, 591618Srie { RTLD_CONFGEN, MSG_ORIG(MSG_RTLD_CONFGEN) }, 601618Srie { 0, 0 } 611618Srie }; 62*2352Sab196087 static const char *leading_str_arr[3]; 63*2352Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda, 64*2352Sab196087 leading_str_arr }; 650Sstevel@tonic-gate 66*2352Sab196087 const char **lstr = leading_str_arr; 67*2352Sab196087 68*2352Sab196087 conv_arg.oflags = conv_arg.rflags = mode; 69*2352Sab196087 700Sstevel@tonic-gate 711618Srie if (mode & RTLD_NOW) { 72*2352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_NOW); 731618Srie } else if (fabricate) { 74*2352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_LAZY); 751618Srie } 761618Srie if (mode & RTLD_GLOBAL) { 77*2352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_GLOBAL); 781618Srie } else if (fabricate) { 79*2352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_LOCAL); 801618Srie } 81*2352Sab196087 *lstr = NULL; 82*2352Sab196087 conv_arg.oflags = mode; 83*2352Sab196087 conv_arg.rflags = mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL); 840Sstevel@tonic-gate 85*2352Sab196087 (void) conv_expn_field(&conv_arg); 860Sstevel@tonic-gate 870Sstevel@tonic-gate return ((const char *)string); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 90*2352Sab196087 /* 91*2352Sab196087 * Note: We can use two different sets of prefix/separator/suffix 92*2352Sab196087 * strings in conv_dl_flag(), depending on the value of the separator 93*2352Sab196087 * argument. To size the buffer, I use the default prefix and suffix 94*2352Sab196087 * sizes, and the alternate separator size, because they are larger. 95*2352Sab196087 */ 96*2352Sab196087 97*2352Sab196087 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 981618Srie MSG_RTLD_REL_RELATIVE_SIZE + MSG_GBL_SEP_SIZE + \ 991618Srie MSG_RTLD_REL_EXEC_SIZE + MSG_GBL_SEP_SIZE + \ 1001618Srie MSG_RTLD_REL_DEPENDS_SIZE + MSG_GBL_SEP_SIZE + \ 1011618Srie MSG_RTLD_REL_PRELOAD_SIZE + MSG_GBL_SEP_SIZE + \ 1021618Srie MSG_RTLD_REL_SELF_SIZE + MSG_GBL_SEP_SIZE + \ 1031618Srie MSG_RTLD_REL_WEAK_SIZE + MSG_GBL_SEP_SIZE + \ 1041618Srie MSG_RTLD_MEMORY_SIZE + MSG_GBL_SEP_SIZE + \ 1051618Srie MSG_RTLD_STRIP_SIZE + MSG_GBL_SEP_SIZE + \ 1061618Srie MSG_RTLD_NOHEAP_SIZE + MSG_GBL_SEP_SIZE + \ 1070Sstevel@tonic-gate MSG_RTLD_CONFSET_SIZE + \ 108*2352Sab196087 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* 1110Sstevel@tonic-gate * String conversion routine for dldump() flags. 1120Sstevel@tonic-gate * crle(1) uses this routine to generate update information, and in this case 1130Sstevel@tonic-gate * we build a "|" separated string. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate const char * 116*2352Sab196087 conv_dl_flag(int flags, int fmt_flags) 1170Sstevel@tonic-gate { 1181618Srie static char string[FLAGSZ]; 1191618Srie static Val_desc vda[] = { 1201618Srie { RTLD_REL_RELATIVE, MSG_ORIG(MSG_RTLD_REL_RELATIVE) }, 1211618Srie { RTLD_REL_EXEC, MSG_ORIG(MSG_RTLD_REL_EXEC) }, 1221618Srie { RTLD_REL_DEPENDS, MSG_ORIG(MSG_RTLD_REL_DEPENDS) }, 1231618Srie { RTLD_REL_PRELOAD, MSG_ORIG(MSG_RTLD_REL_PRELOAD) }, 1241618Srie { RTLD_REL_SELF, MSG_ORIG(MSG_RTLD_REL_SELF) }, 1251618Srie { RTLD_REL_WEAK, MSG_ORIG(MSG_RTLD_REL_WEAK) }, 1261618Srie { RTLD_MEMORY, MSG_ORIG(MSG_RTLD_MEMORY) }, 1271618Srie { RTLD_STRIP, MSG_ORIG(MSG_RTLD_STRIP) }, 1281618Srie { RTLD_NOHEAP, MSG_ORIG(MSG_RTLD_NOHEAP) }, 1291618Srie { RTLD_CONFSET, MSG_ORIG(MSG_RTLD_CONFSET) }, 1301618Srie { 0, 0 } 1311618Srie }; 132*2352Sab196087 static const char *leading_str_arr[2]; 133*2352Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda, 134*2352Sab196087 leading_str_arr }; 135*2352Sab196087 136*2352Sab196087 const char **lstr = leading_str_arr; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (flags == 0) 1390Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1400Sstevel@tonic-gate 141*2352Sab196087 142*2352Sab196087 if (fmt_flags & CONV_FMT_ALTCRLE) { 143*2352Sab196087 conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE); 144*2352Sab196087 conv_arg.sep = MSG_ORIG(MSG_GBL_SEP); 145*2352Sab196087 } else { /* Use default delimiters */ 146*2352Sab196087 conv_arg.prefix = conv_arg.suffix = 147*2352Sab196087 conv_arg.sep = NULL; 148*2352Sab196087 } 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) { 151*2352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL); 152*2352Sab196087 flags &= ~RTLD_REL_ALL; 1530Sstevel@tonic-gate } 154*2352Sab196087 *lstr = NULL; 155*2352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1560Sstevel@tonic-gate 157*2352Sab196087 (void) conv_expn_field(&conv_arg); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate return ((const char *)string); 1600Sstevel@tonic-gate } 161