dl.c revision 98c080d502548e68bb9815459ea56e6ae282c430
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include "_conv.h"
2N/A#include "dl_msg.h"
2N/A
2N/A#define MODESZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
2N/A MSG_RTLD_LAZY_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_GLOBAL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_NOLOAD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_PARENT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_WORLD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_NODELETE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_FIRST_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A MSG_RTLD_CONFGEN_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
2N/A CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
2N/A
2N/A
2N/A/*
2N/A * Ensure that Conv_dl_mode_buf_t is large enough:
2N/A *
2N/A * MODESZ is the real minimum size of the buffer required by conv_dl_mode().
2N/A * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the
2N/A * buffer size. We do things this way because the definition of MODESZ uses
2N/A * information that is not available in the environment of other programs
2N/A * that include the conv.h header file.
2N/A */
2N/A#if (CONV_DL_MODE_BUFSIZE != MODESZ) && !defined(__lint)
2N/A#define REPORT_BUFSIZE MODESZ
2N/A#include "report_bufsize.h"
2N/A#error "CONV_DL_MODE_BUFSIZE does not match MODESZ"
2N/A#endif
2N/A
2N/A/*
2N/A * String conversion routine for dlopen() attributes.
2N/A */
2N/Aconst char *
2N/Aconv_dl_mode(int mode, int fabricate, Conv_dl_mode_buf_t *dl_mode_buf)
2N/A{
2N/A static const Val_desc vda[] = {
2N/A { RTLD_NOLOAD, MSG_RTLD_NOLOAD },
2N/A { RTLD_PARENT, MSG_RTLD_PARENT },
2N/A { RTLD_GROUP, MSG_RTLD_GROUP },
2N/A { RTLD_WORLD, MSG_RTLD_WORLD },
2N/A { RTLD_NODELETE, MSG_RTLD_NODELETE },
2N/A { RTLD_FIRST, MSG_RTLD_FIRST },
2N/A { RTLD_CONFGEN, MSG_RTLD_CONFGEN },
2N/A { 0, 0 }
2N/A };
2N/A static const char *leading_str_arr[3];
2N/A static CONV_EXPN_FIELD_ARG conv_arg = {
2N/A NULL, sizeof (dl_mode_buf->buf), leading_str_arr };
2N/A
2N/A const char **lstr = leading_str_arr;
2N/A
2N/A conv_arg.buf = dl_mode_buf->buf;
2N/A conv_arg.oflags = conv_arg.rflags = mode;
2N/A
2N/A
2N/A if (mode & RTLD_NOW) {
2N/A *lstr++ = MSG_ORIG(MSG_RTLD_NOW);
2N/A } else if ((mode & RTLD_LAZY) || fabricate) {
2N/A *lstr++ = MSG_ORIG(MSG_RTLD_LAZY);
2N/A }
2N/A if (mode & RTLD_GLOBAL) {
2N/A *lstr++ = MSG_ORIG(MSG_RTLD_GLOBAL);
2N/A } else if (fabricate) {
2N/A *lstr++ = MSG_ORIG(MSG_RTLD_LOCAL);
2N/A }
2N/A *lstr = NULL;
2N/A conv_arg.oflags = mode;
2N/A conv_arg.rflags = mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL);
2N/A
2N/A (void) conv_expn_field(&conv_arg, vda, 0);
2N/A
2N/A return ((const char *)dl_mode_buf->buf);
2N/A}
2N/A
2N/A/*
2N/A * Note: We can use two different sets of prefix/separator/suffix
2N/A * strings in conv_dl_flag(), depending on the value of the separator
2N/A * argument. To size the buffer, I use the default prefix and suffix
2N/A * sizes, and the alternate separator size, because they are larger.
2N/A */
2N/A
2N/A#define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
2N/A MSG_RTLD_REL_RELATIVE_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_REL_EXEC_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_REL_DEPENDS_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_REL_PRELOAD_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_REL_SELF_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_REL_WEAK_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_MEMORY_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_STRIP_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_NOHEAP_SIZE + MSG_GBL_SEP_SIZE + \
2N/A MSG_RTLD_CONFSET_SIZE + \
2N/A CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
2N/A
2N/A/*
2N/A * Ensure that Conv_dl_flag_buf_t is large enough:
2N/A *
2N/A * FLAGSZ is the real minimum size of the buffer required by conv_dl_flag().
2N/A * However, Conv_dl_flag_buf_t uses CONV_DL_FLAG_BUFSIZE to set the
2N/A * buffer size. We do things this way because the definition of FLAGSZ uses
2N/A * information that is not available in the environment of other programs
2N/A * that include the conv.h header file.
2N/A */
2N/A#if (CONV_DL_FLAG_BUFSIZE != FLAGSZ) && !defined(__lint)
2N/A#define REPORT_BUFSIZE FLAGSZ
2N/A#include "report_bufsize.h"
2N/A#error "CONV_DL_FLAG_BUFSIZE does not match FLAGSZ"
2N/A#endif
2N/A
2N/A/*
2N/A * String conversion routine for dldump() flags.
2N/A * crle(1) uses this routine to generate update information, and in this case
2N/A * we build a "|" separated string.
2N/A */
2N/Aconst char *
2N/Aconv_dl_flag(int flags, Conv_fmt_flags_t fmt_flags,
2N/A Conv_dl_flag_buf_t *dl_flag_buf)
2N/A{
2N/A static const Val_desc vda[] = {
2N/A { RTLD_REL_RELATIVE, MSG_RTLD_REL_RELATIVE },
2N/A { RTLD_REL_EXEC, MSG_RTLD_REL_EXEC },
2N/A { RTLD_REL_DEPENDS, MSG_RTLD_REL_DEPENDS },
2N/A { RTLD_REL_PRELOAD, MSG_RTLD_REL_PRELOAD },
2N/A { RTLD_REL_SELF, MSG_RTLD_REL_SELF },
2N/A { RTLD_REL_WEAK, MSG_RTLD_REL_WEAK },
2N/A { RTLD_MEMORY, MSG_RTLD_MEMORY },
2N/A { RTLD_STRIP, MSG_RTLD_STRIP },
2N/A { RTLD_NOHEAP, MSG_RTLD_NOHEAP },
2N/A { RTLD_CONFSET, MSG_RTLD_CONFSET },
2N/A { 0, 0 }
2N/A };
2N/A static const char *leading_str_arr[2];
2N/A static CONV_EXPN_FIELD_ARG conv_arg = {
2N/A NULL, sizeof (dl_flag_buf->buf), leading_str_arr };
2N/A
2N/A const char **lstr = leading_str_arr;
2N/A
2N/A if (flags == 0)
2N/A return (MSG_ORIG(MSG_GBL_ZERO));
2N/A
2N/A conv_arg.buf = dl_flag_buf->buf;
2N/A if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CRLE) {
2N/A conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE);
2N/A conv_arg.sep = MSG_ORIG(MSG_GBL_SEP);
2N/A } else { /* Use default delimiters */
2N/A conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL;
2N/A }
2N/A
2N/A if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
2N/A *lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL);
2N/A flags &= ~RTLD_REL_ALL;
2N/A }
2N/A *lstr = NULL;
2N/A conv_arg.oflags = conv_arg.rflags = flags;
2N/A
2N/A (void) conv_expn_field(&conv_arg, vda, fmt_flags);
2N/A
2N/A return ((const char *)dl_flag_buf->buf);
2N/A}
2N/A
2N/Aconst char *
2N/Aconv_dl_info(int request)
2N/A{
2N/A static const Msg requests[RTLD_DI_MAX] = {
2N/A MSG_RTLD_DI_LMID, /* MSG_ORIG(MSG_RTLD_DI_LMID) */
2N/A MSG_RTLD_DI_LINKMAP, /* MSG_ORIG(MSG_RTLD_DI_LINKMAP) */
2N/A MSG_RTLD_DI_CONFIGADDR, /* MSG_ORIG(MSG_RTLD_DI_CONFIGADDR) */
2N/A MSG_RTLD_DI_SERINFO, /* MSG_ORIG(MSG_RTLD_DI_SERINFO) */
2N/A MSG_RTLD_DI_SERINFOSIZE, /* MSG_ORIG(MSG_RTLD_DI_SERINFOSIZE) */
2N/A MSG_RTLD_DI_ORIGIN, /* MSG_ORIG(MSG_RTLD_DI_ORIGIN) */
2N/A MSG_RTLD_DI_PROFILENAME, /* MSG_ORIG(MSG_RTLD_DI_PROFILENAME) */
2N/A MSG_RTLD_DI_PROFILEOUT, /* MSG_ORIG(MSG_RTLD_DI_PROFILEOUT) */
2N/A MSG_RTLD_DI_GETSIGNAL, /* MSG_ORIG(MSG_RTLD_DI_GETSIGNAL) */
2N/A MSG_RTLD_DI_SETSIGNAL, /* MSG_ORIG(MSG_RTLD_DI_SETSIGNAL) */
2N/A MSG_RTLD_DI_ARGSINFO, /* MSG_ORIG(MSG_RTLD_DI_ARGSINFO) */
2N/A MSG_RTLD_DI_MMAPS, /* MSG_ORIG(MSG_RTLD_DI_MMAPS) */
2N/A MSG_RTLD_DI_MMAPCNT /* MSG_ORIG(MSG_RTLD_DI_MMAPCNT) */
2N/A };
2N/A static Conv_inv_buf_t inv_buf;
#if (RTLD_DI_MAX != RTLD_DI_MMAPCNT)
#error "RTLD_DI_MAX has grown"
#endif
if (request && (request <= RTLD_DI_MAX))
return (MSG_ORIG(requests[request - 1]));
(void) conv_invalid_val(&inv_buf, EC_NATPTR(request), 0);
return (inv_buf.buf);
}