c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * CDDL HEADER START
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The contents of this file are subject to the terms of the
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Common Development and Distribution License (the "License").
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * You may not use this file except in compliance with the License.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * See the License for the specific language governing permissions
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * and limitations under the License.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * When distributing Covered Code, include this CDDL HEADER in each
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * If applicable, add the following below this CDDL HEADER, with the
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * fields enclosed by brackets "[]" replaced with your own identifying
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * information: Portions Copyright [yyyy] [name of copyright owner]
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * CDDL HEADER END
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Use is subject to license terms.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab#include <_machelf.h>
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Local include file for elfdump, used to define structure layout
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * definitions for various system structs.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern "C" {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Solaris defines system structs that elfdump needs to display
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * data from. We have a variety of hurdles to overcome in doing this:
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * - The size of system types can differ between ELFCLASS32 and
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * ELFCLASS64.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * - Stucture layout can differ between architectures, so a given
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * field can have a different struct offset than is native
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * for the system running elfdump. Depending on the struct
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * in question, the layout for one platform may be impossible
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * to achieve on another.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * - The byte order of the core object can differ from that
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * of the system running elfdump.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The result is that in the fully general case, each architecture
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * can have a slightly different definition of these structures.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The usual approach of assigning a pointer of the desired structure
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * type and then accessing fields through that pointer cannot be used
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * here. That approach can only be used to access structures with the
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * native layout of the elfdump host. We want any instance of elfdump
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * to be able to examine a Solaris object for any supported architecture,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * so we need a more flexible approach.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The solution to this problem lies in the fact that the binary
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * layout of these public types cannot be changed, except in backward
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * compatible ways. They are written to core files or published in
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * other ways such that we can't make changes that would make it
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * impossible to analyze old files. This means that we can build
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * table of offsets and sizes for each field of each struct, on
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * a per-archecture basis. These tables can be used to access the
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * struct fields directly from the note desc data, and elfdump
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * on any host can read the data from any other host.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * When reading these tables, it can be very helpful to examine
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * the struct definition at the same time.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * sl_field_t is used to describe a struct field
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab ushort_t slf_nelts; /* 0 for scalar, # of els for array */
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * This type is used to extract and manipulate data described by
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * sl_field_t. We rely on the C guarantee that all the fields in
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * a union have offset 0.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef union {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Buffer large enough to format any integral value in a field
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Types of formatting done by fmt_num()
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef enum {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab SL_FMT_NUM_HEX = 1, /* Hex integer, with natural width */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab SL_FMT_NUM_ZHEX = 2, /* Hex integer, fixed width with zero fill */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of auxv_t, from <sys/auxv.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of prgregset_t, an architecture specific
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * array of general register c values
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of lwpstatus_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of pstatus_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of prstatus_t, from <sys/old_procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of psinfo_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of prpsinfo_t, from <sys/old_procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of lwpsinfo_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of prcred_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of prpriv_t, from <sys/procfs.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of priv_impl_info_t, from <sys/priv.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of fltset_t, from <sys/fault.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of siginfo_t, from <sys/siginfo.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * siginfo_t is unusual, in that it contains a large union
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * full of private fields. There are macros defined to give
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * access to these fields via the names documented in the
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * siginfo manpage. We stick to the documented names
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * rather than try to unravel the undocumented blob. Hence,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * the layout description below is a "logical" view of siginfo_t.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The fields below are not necessarily in the same order as
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * they appear in siginfo_t, nor are they everything that is in
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * that struct. They may also overlap each other, if they are
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * contained within of the union.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * The f_ prefixes are used to prevent our field names from
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * clashing with the macros defined in siginfo.h.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of sigset_t, from <sys/signal.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of struct sigaction, from <sys/signal.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of stack_t, from <sys/signal.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of sysset_t, from <sys/syscall.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of timestruc_t, from <sys/time_impl.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Layout description of struct utsname, from <sys/utsname.h>.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Layout description of prdinfo_t, from <sys/procfs.h>.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amoretypedef struct {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowetypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * This type collects all of the layout definitions for
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * a given architecture.
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef struct {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab const sl_lwpstatus_layout_t *lwpstatus; /* lwpstatus_t */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab const sl_priv_impl_info_layout_t *priv_impl_info; /* priv_impl_info_t */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab const sl_prgregset_layout_t *prgregset; /* prgregset_t */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab const sl_sigaction_layout_t *sigaction; /* struct sigaction */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab const sl_timestruc_layout_t *timestruc; /* timestruc_t */
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore const sl_prfdinfo_layout_t *prfdinfo; /* prdinfo_t */
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe const sl_prsecflags_layout_t *prsecflags; /* prsecflags_t */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern void sl_extract_num_field(const char *data, int do_swap,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern Word sl_extract_as_word(const char *data, int do_swap,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern Lword sl_extract_as_lword(const char *data, int do_swap,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern Sword sl_extract_as_sword(const char *data, int do_swap,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern const char *sl_fmt_num(const char *data, int do_swap,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern const sl_arch_layout_t *struct_layout_sparcv9(void);
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab#endif /* _STRUCT_LAYOUT_H */