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 /* 234734Sab196087 * Copyright 2007 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 322352Sab196087 #define MODESZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 332352Sab196087 MSG_RTLD_LAZY_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 342352Sab196087 MSG_RTLD_GLOBAL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 352352Sab196087 MSG_RTLD_NOLOAD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 362352Sab196087 MSG_RTLD_PARENT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 372352Sab196087 MSG_RTLD_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 382352Sab196087 MSG_RTLD_WORLD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 392352Sab196087 MSG_RTLD_NODELETE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 402352Sab196087 MSG_RTLD_FIRST_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 412352Sab196087 MSG_RTLD_CONFGEN_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 424734Sab196087 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 434734Sab196087 441618Srie 454734Sab196087 /* 464734Sab196087 * Ensure that Conv_dl_mode_buf_t is large enough: 474734Sab196087 * 484734Sab196087 * MODESZ is the real minimum size of the buffer required by conv_dl_mode(). 494734Sab196087 * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the 504734Sab196087 * buffer size. We do things this way because the definition of MODESZ uses 514734Sab196087 * information that is not available in the environment of other programs 524734Sab196087 * that include the conv.h header file. 534734Sab196087 */ 54*5152Sab196087 #if (CONV_DL_MODE_BUFSIZE != MODESZ) && !defined(__lint) 55*5152Sab196087 #define REPORT_BUFSIZE MODESZ 56*5152Sab196087 #include "report_bufsize.h" 57*5152Sab196087 #error "CONV_DL_MODE_BUFSIZE does not match MODESZ" 584734Sab196087 #endif 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * String conversion routine for dlopen() attributes. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate const char * 644734Sab196087 conv_dl_mode(int mode, int fabricate, Conv_dl_mode_buf_t *dl_mode_buf) 650Sstevel@tonic-gate { 661618Srie static Val_desc vda[] = { 671618Srie { RTLD_NOLOAD, MSG_ORIG(MSG_RTLD_NOLOAD) }, 681618Srie { RTLD_PARENT, MSG_ORIG(MSG_RTLD_PARENT) }, 691618Srie { RTLD_GROUP, MSG_ORIG(MSG_RTLD_GROUP) }, 701618Srie { RTLD_WORLD, MSG_ORIG(MSG_RTLD_WORLD) }, 711618Srie { RTLD_NODELETE, MSG_ORIG(MSG_RTLD_NODELETE) }, 721618Srie { RTLD_FIRST, MSG_ORIG(MSG_RTLD_FIRST) }, 731618Srie { RTLD_CONFGEN, MSG_ORIG(MSG_RTLD_CONFGEN) }, 741618Srie { 0, 0 } 751618Srie }; 762352Sab196087 static const char *leading_str_arr[3]; 774734Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { 784734Sab196087 NULL, sizeof (dl_mode_buf->buf), vda, leading_str_arr }; 790Sstevel@tonic-gate 802352Sab196087 const char **lstr = leading_str_arr; 812352Sab196087 824734Sab196087 conv_arg.buf = dl_mode_buf->buf; 832352Sab196087 conv_arg.oflags = conv_arg.rflags = mode; 842352Sab196087 850Sstevel@tonic-gate 861618Srie if (mode & RTLD_NOW) { 872352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_NOW); 881618Srie } else if (fabricate) { 892352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_LAZY); 901618Srie } 911618Srie if (mode & RTLD_GLOBAL) { 922352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_GLOBAL); 931618Srie } else if (fabricate) { 942352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_LOCAL); 951618Srie } 962352Sab196087 *lstr = NULL; 972352Sab196087 conv_arg.oflags = mode; 982352Sab196087 conv_arg.rflags = mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL); 990Sstevel@tonic-gate 1005088Sab196087 (void) conv_expn_field(&conv_arg, 0); 1010Sstevel@tonic-gate 1024734Sab196087 return ((const char *)dl_mode_buf->buf); 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate 1052352Sab196087 /* 1062352Sab196087 * Note: We can use two different sets of prefix/separator/suffix 1072352Sab196087 * strings in conv_dl_flag(), depending on the value of the separator 1082352Sab196087 * argument. To size the buffer, I use the default prefix and suffix 1092352Sab196087 * sizes, and the alternate separator size, because they are larger. 1102352Sab196087 */ 1112352Sab196087 1122352Sab196087 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 1131618Srie MSG_RTLD_REL_RELATIVE_SIZE + MSG_GBL_SEP_SIZE + \ 1141618Srie MSG_RTLD_REL_EXEC_SIZE + MSG_GBL_SEP_SIZE + \ 1151618Srie MSG_RTLD_REL_DEPENDS_SIZE + MSG_GBL_SEP_SIZE + \ 1161618Srie MSG_RTLD_REL_PRELOAD_SIZE + MSG_GBL_SEP_SIZE + \ 1171618Srie MSG_RTLD_REL_SELF_SIZE + MSG_GBL_SEP_SIZE + \ 1181618Srie MSG_RTLD_REL_WEAK_SIZE + MSG_GBL_SEP_SIZE + \ 1191618Srie MSG_RTLD_MEMORY_SIZE + MSG_GBL_SEP_SIZE + \ 1201618Srie MSG_RTLD_STRIP_SIZE + MSG_GBL_SEP_SIZE + \ 1211618Srie MSG_RTLD_NOHEAP_SIZE + MSG_GBL_SEP_SIZE + \ 1220Sstevel@tonic-gate MSG_RTLD_CONFSET_SIZE + \ 1234734Sab196087 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 1244734Sab196087 1254734Sab196087 /* 1264734Sab196087 * Ensure that Conv_dl_flag_buf_t is large enough: 1274734Sab196087 * 1284734Sab196087 * FLAGSZ is the real minimum size of the buffer required by conv_dl_flag(). 1294734Sab196087 * However, Conv_dl_flag_buf_t uses CONV_DL_FLAG_BUFSIZE to set the 1304734Sab196087 * buffer size. We do things this way because the definition of FLAGSZ uses 1314734Sab196087 * information that is not available in the environment of other programs 1324734Sab196087 * that include the conv.h header file. 1334734Sab196087 */ 134*5152Sab196087 #if (CONV_DL_FLAG_BUFSIZE != FLAGSZ) && !defined(__lint) 135*5152Sab196087 #define REPORT_BUFSIZE FLAGSZ 136*5152Sab196087 #include "report_bufsize.h" 137*5152Sab196087 #error "CONV_DL_FLAG_BUFSIZE does not match FLAGSZ" 1384734Sab196087 #endif 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * String conversion routine for dldump() flags. 1420Sstevel@tonic-gate * crle(1) uses this routine to generate update information, and in this case 1430Sstevel@tonic-gate * we build a "|" separated string. 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate const char * 1465088Sab196087 conv_dl_flag(int flags, Conv_fmt_flags_t fmt_flags, 1475088Sab196087 Conv_dl_flag_buf_t *dl_flag_buf) 1480Sstevel@tonic-gate { 1491618Srie static Val_desc vda[] = { 1501618Srie { RTLD_REL_RELATIVE, MSG_ORIG(MSG_RTLD_REL_RELATIVE) }, 1511618Srie { RTLD_REL_EXEC, MSG_ORIG(MSG_RTLD_REL_EXEC) }, 1521618Srie { RTLD_REL_DEPENDS, MSG_ORIG(MSG_RTLD_REL_DEPENDS) }, 1531618Srie { RTLD_REL_PRELOAD, MSG_ORIG(MSG_RTLD_REL_PRELOAD) }, 1541618Srie { RTLD_REL_SELF, MSG_ORIG(MSG_RTLD_REL_SELF) }, 1551618Srie { RTLD_REL_WEAK, MSG_ORIG(MSG_RTLD_REL_WEAK) }, 1561618Srie { RTLD_MEMORY, MSG_ORIG(MSG_RTLD_MEMORY) }, 1571618Srie { RTLD_STRIP, MSG_ORIG(MSG_RTLD_STRIP) }, 1581618Srie { RTLD_NOHEAP, MSG_ORIG(MSG_RTLD_NOHEAP) }, 1591618Srie { RTLD_CONFSET, MSG_ORIG(MSG_RTLD_CONFSET) }, 1601618Srie { 0, 0 } 1611618Srie }; 1622352Sab196087 static const char *leading_str_arr[2]; 1634734Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { 1644734Sab196087 NULL, sizeof (dl_flag_buf->buf), vda, leading_str_arr }; 1652352Sab196087 1662352Sab196087 const char **lstr = leading_str_arr; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if (flags == 0) 1690Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1700Sstevel@tonic-gate 1714734Sab196087 conv_arg.buf = dl_flag_buf->buf; 1725088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CRLE) { 1732352Sab196087 conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE); 1742352Sab196087 conv_arg.sep = MSG_ORIG(MSG_GBL_SEP); 1752352Sab196087 } else { /* Use default delimiters */ 1764734Sab196087 conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL; 1772352Sab196087 } 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) { 1802352Sab196087 *lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL); 1814734Sab196087 flags &= ~RTLD_REL_ALL; 1820Sstevel@tonic-gate } 1832352Sab196087 *lstr = NULL; 1842352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1850Sstevel@tonic-gate 1865088Sab196087 (void) conv_expn_field(&conv_arg, fmt_flags); 1870Sstevel@tonic-gate 1884734Sab196087 return ((const char *)dl_flag_buf->buf); 1890Sstevel@tonic-gate } 190