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 5*1618Srie * Common Development and Distribution License (the "License"). 6*1618Srie * 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 */ 21*1618Srie 220Sstevel@tonic-gate /* 23*1618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*1618Srie * 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 320Sstevel@tonic-gate #define MODESZ MSG_GBL_OSQBRKT_SIZE + \ 330Sstevel@tonic-gate MSG_RTLD_LAZY_SIZE + \ 34*1618Srie MSG_RTLD_GLOBAL_SIZE + \ 350Sstevel@tonic-gate MSG_RTLD_NOLOAD_SIZE + \ 360Sstevel@tonic-gate MSG_RTLD_PARENT_SIZE + \ 370Sstevel@tonic-gate MSG_RTLD_GROUP_SIZE + \ 380Sstevel@tonic-gate MSG_RTLD_WORLD_SIZE + \ 390Sstevel@tonic-gate MSG_RTLD_NODELETE_SIZE + \ 400Sstevel@tonic-gate MSG_RTLD_FIRST_SIZE + \ 410Sstevel@tonic-gate MSG_RTLD_CONFGEN_SIZE + \ 42*1618Srie CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE 43*1618Srie 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * String conversion routine for dlopen() attributes. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate const char * 49*1618Srie conv_dl_mode(int mode, int fabricate) 500Sstevel@tonic-gate { 51*1618Srie static char string[MODESZ]; 52*1618Srie static Val_desc vda[] = { 53*1618Srie { RTLD_NOLOAD, MSG_ORIG(MSG_RTLD_NOLOAD) }, 54*1618Srie { RTLD_PARENT, MSG_ORIG(MSG_RTLD_PARENT) }, 55*1618Srie { RTLD_GROUP, MSG_ORIG(MSG_RTLD_GROUP) }, 56*1618Srie { RTLD_WORLD, MSG_ORIG(MSG_RTLD_WORLD) }, 57*1618Srie { RTLD_NODELETE, MSG_ORIG(MSG_RTLD_NODELETE) }, 58*1618Srie { RTLD_FIRST, MSG_ORIG(MSG_RTLD_FIRST) }, 59*1618Srie { RTLD_CONFGEN, MSG_ORIG(MSG_RTLD_CONFGEN) }, 60*1618Srie { 0, 0 } 61*1618Srie }; 62*1618Srie int _mode = mode; 630Sstevel@tonic-gate 640Sstevel@tonic-gate (void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT)); 650Sstevel@tonic-gate 66*1618Srie if (mode & RTLD_NOW) { 67*1618Srie if (strlcat(string, MSG_ORIG(MSG_RTLD_NOW), MODESZ) >= MODESZ) 68*1618Srie return (conv_invalid_val(string, MODESZ, mode, 0)); 69*1618Srie } else if (fabricate) { 70*1618Srie if (strlcat(string, MSG_ORIG(MSG_RTLD_LAZY), MODESZ) >= MODESZ) 71*1618Srie return (conv_invalid_val(string, MODESZ, mode, 0)); 72*1618Srie } 73*1618Srie if (mode & RTLD_GLOBAL) { 74*1618Srie if (strlcat(string, MSG_ORIG(MSG_RTLD_GLOBAL), MODESZ) >= MODESZ) 75*1618Srie return (conv_invalid_val(string, MODESZ, mode, 0)); 76*1618Srie } else if (fabricate) { 77*1618Srie if (strlcat(string, MSG_ORIG(MSG_RTLD_LOCAL), MODESZ) >= MODESZ) 78*1618Srie return (conv_invalid_val(string, MODESZ, mode, 0)); 79*1618Srie } 80*1618Srie _mode &= ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL); 810Sstevel@tonic-gate 82*1618Srie if (conv_expn_field(string, MODESZ, vda, mode, _mode, 0, 0)) 83*1618Srie (void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), MODESZ); 840Sstevel@tonic-gate 850Sstevel@tonic-gate return ((const char *)string); 860Sstevel@tonic-gate } 870Sstevel@tonic-gate 880Sstevel@tonic-gate #define FLAGSZ MSG_GBL_OSQBRKT_SIZE + \ 89*1618Srie MSG_RTLD_REL_RELATIVE_SIZE + MSG_GBL_SEP_SIZE + \ 90*1618Srie MSG_RTLD_REL_EXEC_SIZE + MSG_GBL_SEP_SIZE + \ 91*1618Srie MSG_RTLD_REL_DEPENDS_SIZE + MSG_GBL_SEP_SIZE + \ 92*1618Srie MSG_RTLD_REL_PRELOAD_SIZE + MSG_GBL_SEP_SIZE + \ 93*1618Srie MSG_RTLD_REL_SELF_SIZE + MSG_GBL_SEP_SIZE + \ 94*1618Srie MSG_RTLD_REL_WEAK_SIZE + MSG_GBL_SEP_SIZE + \ 95*1618Srie MSG_RTLD_MEMORY_SIZE + MSG_GBL_SEP_SIZE + \ 96*1618Srie MSG_RTLD_STRIP_SIZE + MSG_GBL_SEP_SIZE + \ 97*1618Srie MSG_RTLD_NOHEAP_SIZE + MSG_GBL_SEP_SIZE + \ 980Sstevel@tonic-gate MSG_RTLD_CONFSET_SIZE + \ 99*1618Srie CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * String conversion routine for dldump() flags. 1030Sstevel@tonic-gate * crle(1) uses this routine to generate update information, and in this case 1040Sstevel@tonic-gate * we build a "|" separated string. 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate const char * 107*1618Srie conv_dl_flag(int flags, int separator) 1080Sstevel@tonic-gate { 109*1618Srie static char string[FLAGSZ]; 110*1618Srie static Val_desc vda[] = { 111*1618Srie { RTLD_REL_RELATIVE, MSG_ORIG(MSG_RTLD_REL_RELATIVE) }, 112*1618Srie { RTLD_REL_EXEC, MSG_ORIG(MSG_RTLD_REL_EXEC) }, 113*1618Srie { RTLD_REL_DEPENDS, MSG_ORIG(MSG_RTLD_REL_DEPENDS) }, 114*1618Srie { RTLD_REL_PRELOAD, MSG_ORIG(MSG_RTLD_REL_PRELOAD) }, 115*1618Srie { RTLD_REL_SELF, MSG_ORIG(MSG_RTLD_REL_SELF) }, 116*1618Srie { RTLD_REL_WEAK, MSG_ORIG(MSG_RTLD_REL_WEAK) }, 117*1618Srie { RTLD_MEMORY, MSG_ORIG(MSG_RTLD_MEMORY) }, 118*1618Srie { RTLD_STRIP, MSG_ORIG(MSG_RTLD_STRIP) }, 119*1618Srie { RTLD_NOHEAP, MSG_ORIG(MSG_RTLD_NOHEAP) }, 120*1618Srie { RTLD_CONFSET, MSG_ORIG(MSG_RTLD_CONFSET) }, 121*1618Srie { 0, 0 } 122*1618Srie }; 123*1618Srie int _flags = flags, element = 0; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate if (flags == 0) 1260Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate if (separator) 129*1618Srie (void) strlcpy(string, MSG_ORIG(MSG_GBL_QUOTE), FLAGSZ); 1300Sstevel@tonic-gate else 131*1618Srie (void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) { 134*1618Srie if (strlcat(string, MSG_ORIG(MSG_RTLD_REL_ALL), FLAGSZ) >= FLAGSZ) 135*1618Srie return (conv_invalid_val(string, FLAGSZ, flags, 0)); 136*1618Srie element++; 137*1618Srie flags = _flags &= ~RTLD_REL_ALL; 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 140*1618Srie if (conv_expn_field(string, FLAGSZ, vda, flags, _flags, 141*1618Srie (separator ? MSG_ORIG(MSG_GBL_SEP) : 0), element)) { 142*1618Srie if (separator) 143*1618Srie (void) strlcat(string, MSG_ORIG(MSG_GBL_QUOTE), FLAGSZ); 144*1618Srie else 145*1618Srie (void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate return ((const char *)string); 1490Sstevel@tonic-gate } 150