cap.c revision d29b2c4438482eb00488be49a1f5d6835f455546
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include <machdep.h>
#include <elfedit.h>
#include <sys/elf_SPARC.h>
#include <strings.h>
#include <debug.h>
#include <conv.h>
#include <cap_msg.h>
/*
* Capabilities section
*/
/*
* This module uses shared code for several of the commands.
* It is sometimes necessary to know which specific command
* is active.
*/
typedef enum {
/* Dump command, used as module default to display dynamic section */
CAP_CMD_T_DUMP = 0, /* cap:dump */
/* Commands that do not correspond directly to a specific DT tag */
/* Commands that embody tag specific knowledge */
} CAP_CMD_T;
#ifndef _ELF64
/*
* We supply this function for the msg module
*/
const char *
{
}
#endif
/*
* This function is supplied to elfedit through our elfedit_module_t
* definition. It translates the opaque elfedit_i18nhdl_t handles
* in our module interface into the actual strings for elfedit to
* use.
*
* note:
* This module uses Msg codes for its i18n handle type.
* So the translation is simply to use MSG_INTL() to turn
* it into a string and return it.
*/
static const char *
{
}
/*
* The cap_opt_t enum specifies a bit value for every optional
* argument allowed by a command in this module.
*/
typedef enum {
/* not name */
} cap_opt_t;
/*
* A variable of type ARGSTATE is used by each command to maintain
* information about the arguments and related things. It is
* initialized by process_args(), and used by the other routines.
*/
typedef struct {
struct {
} cap;
int argc; /* # of plain arguments */
const char **argv; /* Plain arguments */
} ARGSTATE;
/*
* Standard argument processing for cap module
*
* entry
* obj_state, argc, argv - Standard command arguments
* argstate - Address of ARGSTATE block to be initialized
*
* exit:
* On success, *argstate is initialized. On error,
* an error is issued and this routine does not return.
*/
static void
{
/* Add each new option to the options mask */
/* If there may be an arbitrary amount of output, use a pager */
if (argc == 0)
/* Locate the capabilities section */
}
/*
* Print ELF capabilities values, taking the calling command, and output style
* into account.
*
* entry:
* cmd - CAP_CMD_T_* value giving identify of caller
* autoprint - If True, output is only produced if the elfedit
* autoprint flag is set. If False, output is always produced.
* argstate - Argument state block
* print_type - Specifies which capabilities elements to display.
* ndx = If print_type is PRINT_CAP_T_NDX, displays the index specified.
* Otherwise ignored.
*/
typedef enum {
PRINT_CAP_T_ALL = 0, /* Show all indexes */
/* given by arg */
} PRINT_CAP_T;
static void
{
int header_done = 0;
Xword last_c_val = 0;
return;
/*
* Pick an output style. cap:dump is required to use the default
* style. The other commands use the current output style.
*/
/* How many elements do we examine? */
if (print_type == PRINT_CAP_T_NDX) {
return; /* Out of range */
cnt = 1;
} else {
ndx = 0;
}
/*
* If we are only displaying certain tag types and
* this isn't one of those, move on to next element.
*/
continue;
if (outstyle == ELFEDIT_OUTSTYLE_DEFAULT) {
if (header_done == 0) {
header_done = 1;
Elf_cap_title(0);
}
} else {
/*
* In simple or numeric mode under a print type
* that is based on tag type rather than on index,
* quietly: If we've already printed this value,
* don't print it again. A common example of this
* is PRINT_CAP_T_RUNPATH when both CA_RPATH and
* CA_RUNPATH are present with the same value.
*/
continue;
if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) {
union {
} c_buf;
case CA_SUNW_HW_1:
printed = 1;
continue;
case CA_SUNW_SF_1:
printed = 1;
continue;
}
}
}
printed = 1;
}
/*
* If nothing was output under the print types that are
* based on tag type, issue an error saying it doesn't exist.
*/
}
}
/*
* Process the elt argument: This will be a tag type if -capndx is
* not present and this is a print request. It will be an index otherwise.
*
* entry:
* argstate - Argument state block
* arg - Argument string to be converted into an index
* argname - String giving the name by which the argument is
* referred in the online help for the command.
* print_request - True if the command is to print the current
* value(s) and return without changing anything.
* print_type - Address of variable containing PRINT_CAP_T_
* code specifying how the elements will be displayed.
*
* exit:
* If print_request is False: arg is converted into an integer value.
* If -capndx was used, we convert it into an integer. If it was not
* used, then arg is a tag name --- we find the first capabilities entry
* that matches. If no entry matches, and there is an extra CA_NULL,
* it is added. Otherwise an error is issued. *print_type is set
* to PRINT_CAP_T_NDX.
*
* If print_request is True: If -capndx was used, arg is converted into
* an integer value, *print_type is set to PRINT_CAP_T_NDX, and
* the value is returned. If -capndx was not used, *print_type is set to
* PRINT_CAP_T_TAG, and the tag value is returned.
*/
static Word
{
/* Assume we are returning an index, alter as needed below */
/* If -capndx was used, this is a simple numeric index */
/* The argument is a CA_ tag type, not a numeric index */
/*
* If this is a printing request, then we let print_cap() show
* all the items with this tag type.
*/
if (print_request) {
return (ca_value);
}
/* Locate the first entry with the given tag type */
return (ndx);
}
}
/* No room to create one, so we're out of options and must fail */
/*NOTREACHED*/
return (0); /* For lint */
}
/*
* Argument processing for the bitmask commands. Convert the arguments
* to integer form, apply -and/-cmp/-or, and return the resulting value.
*
* entry:
* argstate - Argument state block
* orig - Value of original bitmask
* const_sym - NULL, or array of name->integer mappings for
* applicable symbolic constant names.
*/
static Word
{
int i;
/* Collect the arguments */
/* Complement the value? */
/* Perform any requested bit operations */
return (flags);
}
/*
* Common body for the cap: module commands. These commands
* share a large amount of common behavior, so it is convenient
* to centralize things and use the cmd argument to handle the
* small differences.
*
* entry:
* cmd - One of the CAP_CMD_T_* constants listed above, specifying
* which command to implement.
* obj_state, argc, argv - Standard command arguments
*/
static elfedit_cmdret_t
{
const char *cap_name;
int print_only = 0;
int do_autoprint = 1;
/* Process the optional arguments */
/* Check number of arguments, gather information */
switch (cmd) {
case CAP_CMD_T_DUMP:
/* cap:dump can accept an optional index argument */
print_only = 1;
break;
case CAP_CMD_T_TAG:
case CAP_CMD_T_VALUE:
}
break;
case CAP_CMD_T_DELETE:
0, &print_type);
do_autoprint = 0;
break;
case CAP_CMD_T_MOVE:
do_autoprint = 0;
break;
case CAP_CMD_T_HW1:
break;
case CAP_CMD_T_SF1:
break;
default:
/* Note expected: All commands should have been caught above */
break;
}
/* If this is a request to print current values, do it and return */
if (print_only) {
return (ELFEDIT_CMDRET_NONE);
}
switch (cmd) {
/*
* CAP_CMD_T_DUMP can't get here: It is a print-only
* command.
*/
case CAP_CMD_T_TAG:
{
} else {
}
}
break;
case CAP_CMD_T_VALUE:
{
} else {
}
}
break;
case CAP_CMD_T_DELETE:
{
const char *msg_prefix =
}
break;
case CAP_CMD_T_MOVE:
{
const char *msg_prefix =
NULL);
cnt = 1;
} else {
}
}
break;
case CAP_CMD_T_HW1:
{
/* Set the value */
CONV_FMT_NOBKT, &buf1));
} else {
CONV_FMT_NOBKT, &buf1),
CONV_FMT_NOBKT, &buf2));
}
}
break;
case CAP_CMD_T_SF1:
{
/* Set the value */
CONV_FMT_NOBKT, &buf1));
} else {
CONV_FMT_NOBKT, &buf1),
CONV_FMT_NOBKT, &buf2));
}
}
break;
}
/*
* If we modified the capabilities section header, tell libelf.
*/
if (ret == ELFEDIT_CMDRET_MOD)
/* Do autoprint */
if (do_autoprint)
return (ret);
}
/*
* Command completion functions for the commands
*/
/*
* Command completion for the first argument, which specifies
* the capabilities element to use. Examines the options to see if
* -capndx is present, and if not, supplies the completion
* strings for argument 1.
*/
/*ARGSUSED*/
static void
{
Word i;
/* Make sure it's the first argument */
return;
/* Is -capndx present? If so, we don't complete tag types */
for (i = 0; i < num_opt; i++)
return;
/*
* Supply capability tag names. There are very few of these, so
* rather than worry about whether a given tag exists in the
* file or not, we simply serve up all the possibilities.
*/
}
/*ARGSUSED*/
static void
{
/* First argument */
return;
}
/* The second argument is always a tag value */
}
/*ARGSUSED*/
static void
{
/* This routine allows multiple flags to be specified */
/*
* If there is no object, then supply all the hardware
* capabilities we know of.
*/
return;
}
/*
* Supply the hardware capabilities for the type of
* machine the object is for, if we know any.
*/
}
/*ARGSUSED*/
static void
{
/* This routine allows multiple flags to be specified */
}
/*
* Implementation functions for the commands
*/
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
static elfedit_cmdret_t
{
}
/*ARGSUSED*/
{
/* For commands that only accept -and, -cmp, -o, and -or */
static elfedit_cmd_optarg_t opt_ostyle_bitop[] = {
ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
{ NULL }
};
/* For commands that only accept -capndx */
static elfedit_cmd_optarg_t opt_capndx[] = {
/* MSG_INTL(MSG_OPTDESC_CAPNDX) */
CAP_OPT_F_CAPNDX, 0 },
{ NULL }
};
/* For commands thataccept -capndx and output styles */
static elfedit_cmd_optarg_t opt_ostyle_capndx[] = {
/* MSG_INTL(MSG_OPTDESC_CAPNDX) */
CAP_OPT_F_CAPNDX, 0 },
ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
{ NULL }
};
/* cap:dump */
static const char *name_dump[] = {
};
static elfedit_cmd_optarg_t arg_dump[] = {
{ MSG_ORIG(MSG_STR_ELT),
/* MSG_INTL(MSG_ARGDESC_ELT) */
{ NULL }
};
/* cap:tag */
static elfedit_cmd_optarg_t arg_tag[] = {
{ MSG_ORIG(MSG_STR_ELT),
/* MSG_INTL(MSG_A1_TAG_ELT) */
/* MSG_INTL(MSG_A2_TAG_VALUE) */
{ NULL }
};
/* cap:value */
static elfedit_cmd_optarg_t arg_value[] = {
{ MSG_ORIG(MSG_STR_ELT),
/* MSG_INTL(MSG_ARGDESC_ELT) */
/* MSG_INTL(MSG_A2_VALUE_VALUE) */
{ NULL }
};
/* cap:delete */
static elfedit_cmd_optarg_t arg_delete[] = {
{ MSG_ORIG(MSG_STR_ELT),
/* MSG_INTL(MSG_ARGDESC_ELT) */
0 },
/* MSG_INTL(MSG_A2_DELETE_COUNT) */
{ NULL }
};
/* cap:move */
static elfedit_cmd_optarg_t arg_move[] = {
{ MSG_ORIG(MSG_STR_ELT),
/* MSG_INTL(MSG_ARGDESC_ELT) */
0 },
/* MSG_INTL(MSG_A2_MOVE_DST_INDEX) */
0 },
/* MSG_INTL(MSG_A3_MOVE_COUNT) */
{ NULL }
};
/* cap:hw1 */
static elfedit_cmd_optarg_t arg_hw1[] = {
/* MSG_INTL(MSG_A1_HW1_VALUE) */
{ NULL }
};
/* cap:sf1 */
static elfedit_cmd_optarg_t arg_sf1[] = {
/* MSG_INTL(MSG_A1_SF1_VALUE) */
{ NULL }
};
static elfedit_cmd_t cmds[] = {
/* cap:dump */
/* MSG_INTL(MSG_DESC_DUMP) */
/* MSG_INTL(MSG_HELP_DUMP) */
opt_capndx, arg_dump },
/* cap:tag */
/* MSG_INTL(MSG_DESC_TAG) */
/* MSG_INTL(MSG_HELP_TAG) */
/* cap:value */
/* MSG_INTL(MSG_DESC_VALUE) */
/* MSG_INTL(MSG_HELP_VALUE) */
/* cap:delete */
/* MSG_INTL(MSG_DESC_DELETE) */
/* MSG_INTL(MSG_HELP_DELETE) */
opt_capndx, arg_delete },
/* cap:move */
/* MSG_INTL(MSG_DESC_MOVE) */
/* MSG_INTL(MSG_HELP_MOVE) */
opt_capndx, arg_move },
/* cap:hw1 */
/* MSG_INTL(MSG_DESC_HW1) */
/* MSG_INTL(MSG_HELP_HW1) */
/* cap:sf1 */
/* MSG_INTL(MSG_DESC_SF1) */
/* MSG_INTL(MSG_HELP_SF1) */
{ NULL }
};
static elfedit_module_t module = {
/* MSG_INTL(MSG_MOD_DESC) */
return (&module);
}