Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:41

0001 /* CTF format description.
0002    Copyright (C) 2019-2022 Free Software Foundation, Inc.
0003 
0004    This file is part of libctf.
0005 
0006    libctf is free software; you can redistribute it and/or modify it under
0007    the terms of the GNU General Public License as published by the Free
0008    Software Foundation; either version 3, or (at your option) any later
0009    version.
0010 
0011    This program is distributed in the hope that it will be useful, but
0012    WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0014    See the GNU General Public License for more details.
0015 
0016    You should have received a copy of the GNU General Public License
0017    along with this program; see the file COPYING.  If not see
0018    <http://www.gnu.org/licenses/>.  */
0019 
0020 #ifndef _CTF_H
0021 #define _CTF_H
0022 
0023 #include <sys/types.h>
0024 #include <limits.h>
0025 #include <stdint.h>
0026 
0027 
0028 #ifdef  __cplusplus
0029 extern "C"
0030 {
0031 #endif
0032 
0033 /* CTF - Compact ANSI-C Type Format
0034 
0035    This file format can be used to compactly represent the information needed
0036    by a debugger to interpret the ANSI-C types used by a given program.
0037    Traditionally, this kind of information is generated by the compiler when
0038    invoked with the -g flag and is stored in "stabs" strings or in the more
0039    modern DWARF format.  CTF provides a representation of only the information
0040    that is relevant to debugging a complex, optimized C program such as the
0041    operating system kernel in a form that is significantly more compact than
0042    the equivalent stabs or DWARF representation.  The format is data-model
0043    independent, so consumers do not need different code depending on whether
0044    they are 32-bit or 64-bit programs; libctf automatically compensates for
0045    endianness variations.  CTF assumes that a standard ELF symbol table is
0046    available for use in the debugger, and uses the structure and data of the
0047    symbol table to avoid storing redundant information.  The CTF data may be
0048    compressed on disk or in memory, indicated by a bit in the header.  CTF may
0049    be interpreted in a raw disk file, or it may be stored in an ELF section,
0050    typically named .ctf.  Data structures are aligned so that a raw CTF file or
0051    CTF ELF section may be manipulated using mmap(2).
0052 
0053    The CTF file or section itself has the following structure:
0054 
0055    +--------+--------+---------+----------+--------+----------+...
0056    |  file  |  type  |  data   | function | object | function |...
0057    | header | labels | objects |   info   | index  |  index   |...
0058    +--------+--------+---------+----------+--------+----------+...
0059 
0060    ...+----------+-------+--------+
0061    ...| variable | data  | string |
0062    ...|   info   | types | table  |
0063       +----------+-------+--------+
0064 
0065    The file header stores a magic number and version information, encoding
0066    flags, and the byte offset of each of the sections relative to the end of the
0067    header itself.  If the CTF data has been uniquified against another set of
0068    CTF data, a reference to that data also appears in the the header.  This
0069    reference is the name of the label corresponding to the types uniquified
0070    against.
0071 
0072    Following the header is a list of labels, used to group the types included in
0073    the data types section.  Each label is accompanied by a type ID i.  A given
0074    label refers to the group of types whose IDs are in the range [0, i].
0075 
0076    Data object and function records (collectively, "symtypetabs") are stored in
0077    the same order as they appear in the corresponding symbol table, except that
0078    symbols marked SHN_UNDEF are not stored and symbols that have no type data
0079    are padded out with zeroes.  For each entry in these tables, the type ID (a
0080    small integer) is recorded.  (Functions get CTF_K_FUNCTION types, just like
0081    data objects that are function pointers.)
0082 
0083    For situations in which the order of the symbols in the symtab is not known,
0084    or most symbols have no type in this dict and most entries would be
0085    zero-pads, a pair of optional indexes follow the data object and function
0086    info sections: each of these is an array of strtab indexes, mapped 1:1 to the
0087    corresponding data object / function info section, giving each entry in those
0088    sections a name so that the linker can correlate them with final symtab
0089    entries and reorder them accordingly (dropping the indexes in the process).
0090 
0091    Variable records (as distinct from data objects) provide a modicum of support
0092    for non-ELF systems, mapping a variable name to a CTF type ID.  The variable
0093    names are sorted into ASCIIbetical order, permitting binary searching.  We do
0094    not define how the consumer maps these variable names to addresses or
0095    anything else, or indeed what these names represent: they might be names
0096    looked up at runtime via dlsym() or names extracted at runtime by a debugger
0097    or anything else the consumer likes.  Variable records with identically-
0098    named entries in the data object section are removed.
0099 
0100    The data types section is a list of variable size records that represent each
0101    type, in order by their ID.  The types themselves form a directed graph,
0102    where each node may contain one or more outgoing edges to other type nodes,
0103    denoted by their ID.  Most type nodes are standalone or point backwards to
0104    earlier nodes, but this is not required: nodes can point to later nodes,
0105    particularly structure and union members.
0106 
0107    Strings are recorded as a string table ID (0 or 1) and a byte offset into the
0108    string table.  String table 0 is the internal CTF string table.  String table
0109    1 is the external string table, which is the string table associated with the
0110    ELF dynamic symbol table for this object.  CTF does not record any strings
0111    that are already in the symbol table, and the CTF string table does not
0112    contain any duplicated strings.
0113 
0114    If the CTF data has been merged with another parent CTF object, some outgoing
0115    edges may refer to type nodes that exist in another CTF object.  The debugger
0116    and libctf library are responsible for connecting the appropriate objects
0117    together so that the full set of types can be explored and manipulated.
0118 
0119    This connection is done purely using the ctf_import() function.  The
0120    ctf_archive machinery (and thus ctf_open et al) automatically imports archive
0121    members named ".ctf" into child dicts if available in the same archive, to
0122    match the relationship set up by the linker, but callers can call ctf_import
0123    themselves as well if need be, if they know a different relationship is in
0124    force.  */
0125 
0126 #define CTF_MAX_TYPE    0xfffffffe  /* Max type identifier value.  */
0127 #define CTF_MAX_PTYPE   0x7fffffff  /* Max parent type identifier value.  */
0128 #define CTF_MAX_NAME 0x7fffffff     /* Max offset into a string table.  */
0129 #define CTF_MAX_VLEN    0xffffff /* Max struct, union, enum members or args.  */
0130 
0131 /* See ctf_type_t */
0132 #define CTF_MAX_SIZE    0xfffffffe  /* Max size of a v2 type in bytes. */
0133 #define CTF_LSIZE_SENT  0xffffffff  /* Sentinel for v2 ctt_size.  */
0134 
0135 # define CTF_MAX_TYPE_V1    0xffff  /* Max type identifier value.  */
0136 # define CTF_MAX_PTYPE_V1   0x7fff  /* Max parent type identifier value.  */
0137 # define CTF_MAX_VLEN_V1    0x3ff   /* Max struct, union, enums or args.  */
0138 # define CTF_MAX_SIZE_V1    0xfffe  /* Max size of a type in bytes. */
0139 # define CTF_LSIZE_SENT_V1  0xffff  /* Sentinel for v1 ctt_size.  */
0140 
0141   /* Start of actual data structure definitions.
0142 
0143      Every field in these structures must have corresponding code in the
0144      endianness-swapping machinery in libctf/ctf-open.c.  */
0145 
0146 typedef struct ctf_preamble
0147 {
0148   unsigned short ctp_magic; /* Magic number (CTF_MAGIC).  */
0149   unsigned char ctp_version;    /* Data format version number (CTF_VERSION).  */
0150   unsigned char ctp_flags;  /* Flags (see below).  */
0151 } ctf_preamble_t;
0152 
0153 typedef struct ctf_header_v2
0154 {
0155   ctf_preamble_t cth_preamble;
0156   uint32_t cth_parlabel;    /* Ref to name of parent lbl uniq'd against.  */
0157   uint32_t cth_parname;     /* Ref to basename of parent.  */
0158   uint32_t cth_lbloff;      /* Offset of label section.  */
0159   uint32_t cth_objtoff;     /* Offset of object section.  */
0160   uint32_t cth_funcoff;     /* Offset of function section.  */
0161   uint32_t cth_varoff;      /* Offset of variable section.  */
0162   uint32_t cth_typeoff;     /* Offset of type section.  */
0163   uint32_t cth_stroff;      /* Offset of string section.  */
0164   uint32_t cth_strlen;      /* Length of string section in bytes.  */
0165 } ctf_header_v2_t;
0166 
0167 typedef struct ctf_header
0168 {
0169   ctf_preamble_t cth_preamble;
0170   uint32_t cth_parlabel;    /* Ref to name of parent lbl uniq'd against.  */
0171   uint32_t cth_parname;     /* Ref to basename of parent.  */
0172   uint32_t cth_cuname;      /* Ref to CU name (may be 0).  */
0173   uint32_t cth_lbloff;      /* Offset of label section.  */
0174   uint32_t cth_objtoff;     /* Offset of object section.  */
0175   uint32_t cth_funcoff;     /* Offset of function section.  */
0176   uint32_t cth_objtidxoff;  /* Offset of object index section.  */
0177   uint32_t cth_funcidxoff;  /* Offset of function index section.  */
0178   uint32_t cth_varoff;      /* Offset of variable section.  */
0179   uint32_t cth_typeoff;     /* Offset of type section.  */
0180   uint32_t cth_stroff;      /* Offset of string section.  */
0181   uint32_t cth_strlen;      /* Length of string section in bytes.  */
0182 } ctf_header_t;
0183 
0184 #define cth_magic   cth_preamble.ctp_magic
0185 #define cth_version cth_preamble.ctp_version
0186 #define cth_flags   cth_preamble.ctp_flags
0187 
0188 #define CTF_MAGIC   0xdff2  /* Magic number identifying header.  */
0189 
0190 /* Data format version number.  */
0191 
0192 /* v1 upgraded to a later version is not quite the same as the native form,
0193    because the boundary between parent and child types is different but not
0194    recorded anywhere, and you can write it out again via ctf_compress_write(),
0195    so we must track whether the thing was originally v1 or not.  If we were
0196    writing the header from scratch, we would add a *pair* of version number
0197    fields to allow for this, but this will do for now.  (A flag will not do,
0198    because we need to encode both the version we came from and the version we
0199    went to, not just "we were upgraded".) */
0200 
0201 # define CTF_VERSION_1 1
0202 # define CTF_VERSION_1_UPGRADED_3 2
0203 # define CTF_VERSION_2 3
0204 
0205 #define CTF_VERSION_3 4
0206 #define CTF_VERSION CTF_VERSION_3 /* Current version.  */
0207 
0208 /* All of these flags bar CTF_F_COMPRESS and CTF_F_IDXSORTED are bug-workaround
0209    flags and are valid only in format v3: in v2 and below they cannot occur and
0210    in v4 and later, they will be recycled for other purposes.  */
0211 
0212 #define CTF_F_COMPRESS  0x1     /* Data buffer is compressed by libctf.  */
0213 #define CTF_F_NEWFUNCINFO 0x2       /* New v3 func info section format.  */
0214 #define CTF_F_IDXSORTED 0x4     /* Index sections already sorted.  */
0215 #define CTF_F_DYNSTR 0x8        /* Strings come from .dynstr.  */
0216 #define CTF_F_MAX (CTF_F_COMPRESS | CTF_F_NEWFUNCINFO | CTF_F_IDXSORTED \
0217            | CTF_F_DYNSTR)
0218 
0219 typedef struct ctf_lblent
0220 {
0221   uint32_t ctl_label;       /* Ref to name of label.  */
0222   uint32_t ctl_type;        /* Last type associated with this label.  */
0223 } ctf_lblent_t;
0224 
0225 typedef struct ctf_varent
0226 {
0227   uint32_t ctv_name;        /* Reference to name in string table.  */
0228   uint32_t ctv_type;        /* Index of type of this variable.  */
0229 } ctf_varent_t;
0230 
0231 /* In format v2, type sizes, measured in bytes, come in two flavours.  Nearly
0232    all of them fit into a (UINT_MAX - 1), and thus can be stored in the ctt_size
0233    member of a ctf_stype_t.  The maximum value for these sizes is CTF_MAX_SIZE.
0234    Types larger than this must be stored in the ctf_lsize member of a
0235    ctf_type_t.  Use of this member is indicated by the presence of
0236    CTF_LSIZE_SENT in ctt_size.  */
0237 
0238 /* In v1, the same applies, only the limit is (USHRT_MAX - 1) and
0239    CTF_MAX_SIZE_V1, and CTF_LSIZE_SENT_V1 is the sentinel.  */
0240 
0241 typedef struct ctf_stype_v1
0242 {
0243   uint32_t ctt_name;        /* Reference to name in string table.  */
0244   unsigned short ctt_info;  /* Encoded kind, variant length (see below).  */
0245 #ifndef __GNUC__
0246   union
0247   {
0248     unsigned short _size;   /* Size of entire type in bytes.  */
0249     unsigned short _type;   /* Reference to another type.  */
0250   } _u;
0251 #else
0252   __extension__
0253   union
0254   {
0255     unsigned short ctt_size;    /* Size of entire type in bytes.  */
0256     unsigned short ctt_type;    /* Reference to another type.  */
0257   };
0258 #endif
0259 } ctf_stype_v1_t;
0260 
0261 typedef struct ctf_type_v1
0262 {
0263   uint32_t ctt_name;        /* Reference to name in string table.  */
0264   unsigned short ctt_info;  /* Encoded kind, variant length (see below).  */
0265 #ifndef __GNUC__
0266   union
0267   {
0268     unsigned short _size;   /* Always CTF_LSIZE_SENT_V1.  */
0269     unsigned short _type;   /* Do not use.  */
0270   } _u;
0271 #else
0272   __extension__
0273   union
0274   {
0275     unsigned short ctt_size;    /* Always CTF_LSIZE_SENT_V1.  */
0276     unsigned short ctt_type;    /* Do not use.  */
0277   };
0278 #endif
0279   uint32_t ctt_lsizehi;     /* High 32 bits of type size in bytes.  */
0280   uint32_t ctt_lsizelo;     /* Low 32 bits of type size in bytes.  */
0281 } ctf_type_v1_t;
0282 
0283 
0284 typedef struct ctf_stype
0285 {
0286   uint32_t ctt_name;        /* Reference to name in string table.  */
0287   uint32_t ctt_info;        /* Encoded kind, variant length (see below).  */
0288 #ifndef __GNUC__
0289   union
0290   {
0291     uint32_t _size;     /* Size of entire type in bytes.  */
0292     uint32_t _type;     /* Reference to another type.  */
0293   } _u;
0294 #else
0295   __extension__
0296   union
0297   {
0298     uint32_t ctt_size;      /* Size of entire type in bytes.  */
0299     uint32_t ctt_type;      /* Reference to another type.  */
0300   };
0301 #endif
0302 } ctf_stype_t;
0303 
0304 typedef struct ctf_type
0305 {
0306   uint32_t ctt_name;        /* Reference to name in string table.  */
0307   uint32_t ctt_info;        /* Encoded kind, variant length (see below).  */
0308 #ifndef __GNUC__
0309 union
0310   {
0311     uint32_t _size;     /* Always CTF_LSIZE_SENT.  */
0312     uint32_t _type;     /* Do not use.  */
0313   } _u;
0314 #else
0315   __extension__
0316   union
0317   {
0318     uint32_t ctt_size;      /* Always CTF_LSIZE_SENT.  */
0319     uint32_t ctt_type;      /* Do not use.  */
0320   };
0321 #endif
0322   uint32_t ctt_lsizehi;     /* High 32 bits of type size in bytes.  */
0323   uint32_t ctt_lsizelo;     /* Low 32 bits of type size in bytes.  */
0324 } ctf_type_t;
0325 
0326 #ifndef __GNUC__
0327 #define ctt_size _u._size   /* For fundamental types that have a size.  */
0328 #define ctt_type _u._type   /* For types that reference another type.  */
0329 #endif
0330 
0331 /* The following macros and inline functions compose and decompose values for
0332    ctt_info and ctt_name, as well as other structures that contain name
0333    references.  Use outside libdtrace-ctf itself is explicitly for access to CTF
0334    files directly: types returned from the library will always appear to be
0335    CTF_V2.
0336 
0337    v1: (transparently upgraded to v2 at open time: may be compiled out of the
0338    library)
0339                ------------------------
0340    ctt_info:   | kind | isroot | vlen |
0341                ------------------------
0342                15   11    10    9     0
0343 
0344    v2:
0345                ------------------------
0346    ctt_info:   | kind | isroot | vlen |
0347                ------------------------
0348                31    26    25  24     0
0349 
0350    CTF_V1 and V2 _INFO_VLEN have the same interface:
0351 
0352    kind = CTF_*_INFO_KIND(c.ctt_info);     <-- CTF_K_* value (see below)
0353    vlen = CTF_*_INFO_VLEN(fp, c.ctt_info); <-- length of variable data list
0354 
0355    stid = CTF_NAME_STID(c.ctt_name);     <-- string table id number (0 or 1)
0356    offset = CTF_NAME_OFFSET(c.ctt_name); <-- string table byte offset
0357 
0358    c.ctt_info = CTF_TYPE_INFO(kind, vlen);
0359    c.ctt_name = CTF_TYPE_NAME(stid, offset);  */
0360 
0361 #define CTF_V1_INFO_KIND(info)      (((info) & 0xf800) >> 11)
0362 #define CTF_V1_INFO_ISROOT(info)    (((info) & 0x0400) >> 10)
0363 #define CTF_V1_INFO_VLEN(info)      (((info) & CTF_MAX_VLEN_V1))
0364 
0365 #define CTF_V2_INFO_KIND(info)      (((info) & 0xfc000000) >> 26)
0366 #define CTF_V2_INFO_ISROOT(info)    (((info) & 0x2000000) >> 25)
0367 #define CTF_V2_INFO_VLEN(info)      (((info) & CTF_MAX_VLEN))
0368 
0369 #define CTF_NAME_STID(name)     ((name) >> 31)
0370 #define CTF_NAME_OFFSET(name)       ((name) & CTF_MAX_NAME)
0371 #define CTF_SET_STID(name, stid)    ((name) | ((unsigned int) stid) << 31)
0372 
0373 /* V2 only. */
0374 #define CTF_TYPE_INFO(kind, isroot, vlen) \
0375     (((kind) << 26) | (((isroot) ? 1 : 0) << 25) | ((vlen) & CTF_MAX_VLEN))
0376 
0377 #define CTF_TYPE_NAME(stid, offset) \
0378     (((stid) << 31) | ((offset) & CTF_MAX_NAME))
0379 
0380 /* The next set of macros are for public consumption only.  Not used internally,
0381    since the relevant type boundary is dependent upon the version of the file at
0382    *opening* time, not the version after transparent upgrade.  Use
0383    ctf_type_isparent() / ctf_type_ischild() for that.  */
0384 
0385 #define CTF_V2_TYPE_ISPARENT(fp, id)    ((id) <= CTF_MAX_PTYPE)
0386 #define CTF_V2_TYPE_ISCHILD(fp, id) ((id) > CTF_MAX_PTYPE)
0387 #define CTF_V2_TYPE_TO_INDEX(id)    ((id) & CTF_MAX_PTYPE)
0388 #define CTF_V2_INDEX_TO_TYPE(id, child) ((child) ? ((id) | (CTF_MAX_PTYPE+1)) : (id))
0389 
0390 #define CTF_V1_TYPE_ISPARENT(fp, id)    ((id) <= CTF_MAX_PTYPE_V1)
0391 #define CTF_V1_TYPE_ISCHILD(fp, id) ((id) > CTF_MAX_PTYPE_V1)
0392 #define CTF_V1_TYPE_TO_INDEX(id)    ((id) & CTF_MAX_PTYPE_V1)
0393 #define CTF_V1_INDEX_TO_TYPE(id, child) ((child) ? ((id) | (CTF_MAX_PTYPE_V1+1)) : (id))
0394 
0395 /* Valid for both V1 and V2. */
0396 #define CTF_TYPE_LSIZE(cttp) \
0397     (((uint64_t)(cttp)->ctt_lsizehi) << 32 | (cttp)->ctt_lsizelo)
0398 #define CTF_SIZE_TO_LSIZE_HI(size)  ((uint32_t)((uint64_t)(size) >> 32))
0399 #define CTF_SIZE_TO_LSIZE_LO(size)  ((uint32_t)(size))
0400 
0401 #define CTF_STRTAB_0    0   /* String table id 0 (in-CTF).  */
0402 #define CTF_STRTAB_1    1   /* String table id 1 (ELF strtab).  */
0403 
0404 /* Values for CTF_TYPE_KIND().  If the kind has an associated data list,
0405    CTF_INFO_VLEN() will extract the number of elements in the list, and
0406    the type of each element is shown in the comments below. */
0407 
0408 #define CTF_K_UNKNOWN   0   /* Unknown type (used for padding and
0409                    unrepresentable types).  */
0410 #define CTF_K_INTEGER   1   /* Variant data is CTF_INT_DATA (see below).  */
0411 #define CTF_K_FLOAT 2   /* Variant data is CTF_FP_DATA (see below).  */
0412 #define CTF_K_POINTER   3   /* ctt_type is referenced type.  */
0413 #define CTF_K_ARRAY 4   /* Variant data is single ctf_array_t.  */
0414 #define CTF_K_FUNCTION  5   /* ctt_type is return type, variant data is
0415                    list of argument types (unsigned short's for v1,
0416                    uint32_t's for v2).  */
0417 #define CTF_K_STRUCT    6   /* Variant data is list of ctf_member_t's.  */
0418 #define CTF_K_UNION 7   /* Variant data is list of ctf_member_t's.  */
0419 #define CTF_K_ENUM  8   /* Variant data is list of ctf_enum_t's.  */
0420 #define CTF_K_FORWARD   9   /* No additional data; ctt_name is tag.  */
0421 #define CTF_K_TYPEDEF   10  /* ctt_type is referenced type.  */
0422 #define CTF_K_VOLATILE  11  /* ctt_type is base type.  */
0423 #define CTF_K_CONST 12  /* ctt_type is base type.  */
0424 #define CTF_K_RESTRICT  13  /* ctt_type is base type.  */
0425 #define CTF_K_SLICE 14  /* Variant data is a ctf_slice_t.  */
0426 
0427 #define CTF_K_MAX   63  /* Maximum possible (V2) CTF_K_* value.  */
0428 
0429 /* Values for ctt_type when kind is CTF_K_INTEGER.  The flags, offset in bits,
0430    and size in bits are encoded as a single word using the following macros.
0431    (However, you can also encode the offset and bitness in a slice.)  */
0432 
0433 #define CTF_INT_ENCODING(data) (((data) & 0xff000000) >> 24)
0434 #define CTF_INT_OFFSET(data)   (((data) & 0x00ff0000) >> 16)
0435 #define CTF_INT_BITS(data)     (((data) & 0x0000ffff))
0436 
0437 #define CTF_INT_DATA(encoding, offset, bits) \
0438        (((encoding) << 24) | ((offset) << 16) | (bits))
0439 
0440 #define CTF_INT_SIGNED  0x01    /* Integer is signed (otherwise unsigned).  */
0441 #define CTF_INT_CHAR    0x02    /* Character display format.  */
0442 #define CTF_INT_BOOL    0x04    /* Boolean display format.  */
0443 #define CTF_INT_VARARGS 0x08    /* Varargs display format.  */
0444 
0445 /* Use CTF_CHAR to produce a char that agrees with the system's native
0446    char signedness.  */
0447 #if CHAR_MIN == 0
0448 # define CTF_CHAR (CTF_INT_CHAR)
0449 #else
0450 # define CTF_CHAR (CTF_INT_CHAR | CTF_INT_SIGNED)
0451 #endif
0452 
0453 /* Values for ctt_type when kind is CTF_K_FLOAT.  The encoding, offset in bits,
0454    and size in bits are encoded as a single word using the following macros.
0455    (However, you can also encode the offset and bitness in a slice.)  */
0456 
0457 #define CTF_FP_ENCODING(data)  (((data) & 0xff000000) >> 24)
0458 #define CTF_FP_OFFSET(data)    (((data) & 0x00ff0000) >> 16)
0459 #define CTF_FP_BITS(data)      (((data) & 0x0000ffff))
0460 
0461 #define CTF_FP_DATA(encoding, offset, bits) \
0462        (((encoding) << 24) | ((offset) << 16) | (bits))
0463 
0464 /* Variant data when kind is CTF_K_FLOAT is an encoding in the top eight bits.  */
0465 #define CTF_FP_ENCODING(data)   (((data) & 0xff000000) >> 24)
0466 
0467 #define CTF_FP_SINGLE   1   /* IEEE 32-bit float encoding.  */
0468 #define CTF_FP_DOUBLE   2   /* IEEE 64-bit float encoding.  */
0469 #define CTF_FP_CPLX 3   /* Complex encoding.  */
0470 #define CTF_FP_DCPLX    4   /* Double complex encoding.  */
0471 #define CTF_FP_LDCPLX   5   /* Long double complex encoding.  */
0472 #define CTF_FP_LDOUBLE  6   /* Long double encoding.  */
0473 #define CTF_FP_INTRVL   7   /* Interval (2x32-bit) encoding.  */
0474 #define CTF_FP_DINTRVL  8   /* Double interval (2x64-bit) encoding.  */
0475 #define CTF_FP_LDINTRVL 9   /* Long double interval (2x128-bit) encoding.  */
0476 #define CTF_FP_IMAGRY   10  /* Imaginary (32-bit) encoding.  */
0477 #define CTF_FP_DIMAGRY  11  /* Long imaginary (64-bit) encoding.  */
0478 #define CTF_FP_LDIMAGRY 12  /* Long double imaginary (128-bit) encoding.  */
0479 
0480 #define CTF_FP_MAX  12  /* Maximum possible CTF_FP_* value */
0481 
0482 /* A slice increases the offset and reduces the bitness of the referenced
0483    ctt_type, which must be a type which has an encoding (fp, int, or enum).  We
0484    also store the referenced type in here, because it is easier to keep the
0485    ctt_size correct for the slice than to shuffle the size into here and keep
0486    the ctt_type where it is for other types.
0487 
0488    In a future version, where we loosen requirements on alignment in the CTF
0489    file, the cts_offset and cts_bits will be chars: but for now they must be
0490    shorts or everything after a slice will become unaligned.  */
0491 
0492 typedef struct ctf_slice
0493 {
0494   uint32_t cts_type;
0495   unsigned short cts_offset;
0496   unsigned short cts_bits;
0497 } ctf_slice_t;
0498 
0499 typedef struct ctf_array_v1
0500 {
0501   unsigned short cta_contents;  /* Reference to type of array contents.  */
0502   unsigned short cta_index; /* Reference to type of array index.  */
0503   uint32_t cta_nelems;      /* Number of elements.  */
0504 } ctf_array_v1_t;
0505 
0506 typedef struct ctf_array
0507 {
0508   uint32_t cta_contents;    /* Reference to type of array contents.  */
0509   uint32_t cta_index;       /* Reference to type of array index.  */
0510   uint32_t cta_nelems;      /* Number of elements.  */
0511 } ctf_array_t;
0512 
0513 /* Most structure members have bit offsets that can be expressed using a short.
0514    Some don't.  ctf_member_t is used for structs which cannot contain any of
0515    these large offsets, whereas ctf_lmember_t is used in the latter case.  If
0516    any member of a given struct has an offset that cannot be expressed using a
0517    uint32_t, all members will be stored as type ctf_lmember_t.  This is expected
0518    to be very rare (but nonetheless possible).  */
0519 
0520 #define CTF_LSTRUCT_THRESH  536870912
0521 
0522 /* In v1, the same is true, except that lmembers are used for structs >= 8192
0523    bytes in size.  (The ordering of members in the ctf_member_* structures is
0524    different to improve padding.)  */
0525 
0526 #define CTF_LSTRUCT_THRESH_V1   8192
0527 
0528 typedef struct ctf_member_v1
0529 {
0530   uint32_t ctm_name;        /* Reference to name in string table.  */
0531   unsigned short ctm_type;  /* Reference to type of member.  */
0532   unsigned short ctm_offset;    /* Offset of this member in bits.  */
0533 } ctf_member_v1_t;
0534 
0535 typedef struct ctf_lmember_v1
0536 {
0537   uint32_t ctlm_name;       /* Reference to name in string table.  */
0538   unsigned short ctlm_type; /* Reference to type of member.  */
0539   unsigned short ctlm_pad;  /* Padding.  */
0540   uint32_t ctlm_offsethi;   /* High 32 bits of member offset in bits.  */
0541   uint32_t ctlm_offsetlo;   /* Low 32 bits of member offset in bits.  */
0542 } ctf_lmember_v1_t;
0543 
0544 typedef struct ctf_member_v2
0545 {
0546   uint32_t ctm_name;        /* Reference to name in string table.  */
0547   uint32_t ctm_offset;      /* Offset of this member in bits.  */
0548   uint32_t ctm_type;        /* Reference to type of member.  */
0549 } ctf_member_t;
0550 
0551 typedef struct ctf_lmember_v2
0552 {
0553   uint32_t ctlm_name;       /* Reference to name in string table.  */
0554   uint32_t ctlm_offsethi;   /* High 32 bits of member offset in bits.  */
0555   uint32_t ctlm_type;       /* Reference to type of member.  */
0556   uint32_t ctlm_offsetlo;   /* Low 32 bits of member offset in bits.  */
0557 } ctf_lmember_t;
0558 
0559 #define CTF_LMEM_OFFSET(ctlmp) \
0560     (((uint64_t)(ctlmp)->ctlm_offsethi) << 32 | (ctlmp)->ctlm_offsetlo)
0561 #define CTF_OFFSET_TO_LMEMHI(offset)    ((uint32_t)((uint64_t)(offset) >> 32))
0562 #define CTF_OFFSET_TO_LMEMLO(offset)    ((uint32_t)(offset))
0563 
0564 typedef struct ctf_enum
0565 {
0566   uint32_t cte_name;        /* Reference to name in string table.  */
0567   int32_t cte_value;        /* Value associated with this name.  */
0568 } ctf_enum_t;
0569 
0570 /* The ctf_archive is a collection of ctf_dict_t's stored together. The format
0571    is suitable for mmap()ing: this control structure merely describes the
0572    mmap()ed archive (and overlaps the first few bytes of it), hence the
0573    greater care taken with integral types.  All CTF files in an archive
0574    must have the same data model.  (This is not validated.)
0575 
0576    All integers in this structure are stored in little-endian byte order.
0577 
0578    The code relies on the fact that everything in this header is a uint64_t
0579    and thus the header needs no padding (in particular, that no padding is
0580    needed between ctfa_ctfs and the unnamed ctfa_archive_modent array
0581    that follows it).
0582 
0583    This is *not* the same as the data structure returned by the ctf_arc_*()
0584    functions:  this is the low-level on-disk representation.  */
0585 
0586 #define CTFA_MAGIC 0x8b47f2a4d7623eeb   /* Random.  */
0587 struct ctf_archive
0588 {
0589   /* Magic number.  (In loaded files, overwritten with the file size
0590      so ctf_arc_close() knows how much to munmap()).  */
0591   uint64_t ctfa_magic;
0592 
0593   /* CTF data model.  */
0594   uint64_t ctfa_model;
0595 
0596   /* Number of CTF dicts in the archive.  */
0597   uint64_t ctfa_ndicts;
0598 
0599   /* Offset of the name table.  */
0600   uint64_t ctfa_names;
0601 
0602   /* Offset of the CTF table.  Each element starts with a size (a uint64_t
0603      in network byte order) then a ctf_dict_t of that size.  */
0604   uint64_t ctfa_ctfs;
0605 };
0606 
0607 /* An array of ctfa_nnamed of this structure lies at
0608    ctf_archive[ctf_archive->ctfa_modents] and gives the ctfa_ctfs or
0609    ctfa_names-relative offsets of each name or ctf_dict_t.  */
0610 
0611 typedef struct ctf_archive_modent
0612 {
0613   uint64_t name_offset;
0614   uint64_t ctf_offset;
0615 } ctf_archive_modent_t;
0616 
0617 #ifdef  __cplusplus
0618 }
0619 #endif
0620 
0621 #endif              /* _CTF_H */