view usr/src/common/ctf/ctf_impl.h @ 25635:ce2b70e7aab0

[illumos-gate merge] commit 0a554e9f2c0d440dc40a97fae2d18f1d428ca786 13404 man page spelling errors commit 9f76c6ed5b6ee0cc0bf631daca15ac3dc5fc70c4 13400 zfs-tests: implicit conversion from 'enum dmu_objset_type' to 'enum lzc_dataset_type' commit ef96fc31fc4f4306719704352d5c3e33573c039f 13399 zfs: error: implicit conversion from 'boolean_t' to 'ds_hold_flags_t' commit 56870e8c76c2675bcef1fcee5d519585ce9c768e 13393 cheetah: case value '47616' not in enumerated type commit 8247326397b1a16f37e70cf13f5b7a4f50d06712 13403 zfs: symbol 'g_zfs' is multiply-defined commit 436b964b19ef06803ad9165542d80d9d731d6486 13402 zpool: symbol 'g_zfs' is multiply-defined commit 99308ed0417a2b8ab73c5856a8a5345ce2a7aea7 13396 PoolsExecption typo in resource pools javadoc commit 1575b751c16622553e958c1e5c45e59c86b15c6e 13392 px: case value '3' not in enumerated type commit 9b0429a10eec9313ec782d8421272aff70adbfdc 13339 Add support for Hygon Dhyana Family 18h processor commit d20422bd742384b77102bb3bd09e0dc4b7372e50 13351 loader: vbe_find_mode_xydm() is using wrong safety and iteration is buggy commit 174b8e455f9a6974e69fa4e28792580acde0892d 13311 uptime(1) dazed and confused for a minute after boot commit f816551bb187d104fbf2757703d7a5d2189a3a18 13401 eeprom: 'lv' may be used uninitialized in this function commit 5e96da73c99d9d17ff5a58b793fff2ab6dcadf25 13391 fm: build errors with gcc 7 on SPARC commit 58b55f701e285559e4799354996fd284238ed0d4 13398 libstand: xdrproc_t should return bool commit c6a28d7650029501a356f7b75b2a10a5c4430cef 13394 fhc: case value '4294967295' not in enumerated type commit 58d4b16fe601073f2408de78e3db7e9bfa9abfd2 13355 remove topo module warning gags commit 1473b8d60e902819558a8b0e8a257eb0d754c3c3 13388 ZFS list bookmark not working on zvols commit 4bba12ca5cd6f92aaf0d4c0d19d05528110bc095 13368 libbe_py should support temporary BE activation commit a92282e44f968185a6bba094d1e5fece2da819cf 13376 fm: variable may be used uninitialized commit 8b1df8bf71b7b62e7e4d46fe6b457d4d6447b2b8 13367 beadm activate -t should not promote new BE datasets commit 9704bf7fb82e71b685e194a967937ff03843e73a 13317 Decrease contention on dn_struct_rwlock commit 88a08813800ed7ba7c927986421cee437f7f2233 13363 ctfconvert could support more granular ignore for missing debug data commit 3dd4cd56e7843e01a8ab147a0d102cd4f6d732c1 13342 ctfconvert could encode _Float128 for 32-bit objects commit 73197b540cc5f0434c409b68ca9e1a514a6ce91b 13336 ctfconvert should be able to unconditionally attempt conversion commit dd4422524768709a579a2a93a10c78a88a6b0ecb 13280 CTF: provide option to truncate and continue Conflicts & other fixes (with help from Jason King <jbk@joyent.com>): usr/src/lib/fm/topo/modules/common/ipmi/ipmi_enum.c usr/src/lib/libctf/common/ctf_convert.c usr/src/lib/libctf/common/ctf_lib.c usr/src/lib/libctf/common/libctf.h usr/src/lib/libproc/common/Psymtab.c usr/src/man/man1/ld.so.1.1 usr/src/man/man4/process.4
author Dan McDonald <danmcd@joyent.com>
date Mon, 04 Jan 2021 14:49:49 -0500
parents 790afcb3bacd 790618c19823
children
line wrap: on
line source

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (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
 * or http://www.opensolaris.org/os/licensing.
 * 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 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/*
 * Copyright 2020 Joyent, Inc.
 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
 */

#ifndef	_CTF_IMPL_H
#define	_CTF_IMPL_H

#include <sys/types.h>
#include <sys/errno.h>
#include <sys/sysmacros.h>
#include <sys/ctf_api.h>

#ifdef _KERNEL

#include <sys/systm.h>
#include <sys/cmn_err.h>
#include <sys/varargs.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>

#define	isspace(c) \
	((c) == ' ' || (c) == '\t' || (c) == '\n' || \
	(c) == '\r' || (c) == '\f' || (c) == '\v')

#define	MAP_FAILED	((void *)-1)

#else	/* _KERNEL */

#include <strings.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <stddef.h>

#endif	/* _KERNEL */

#ifdef	__cplusplus
extern "C" {
#endif

typedef struct ctf_helem {
	uint_t h_name;		/* reference to name in string table */
	ushort_t h_type;	/* corresponding type ID number */
	ushort_t h_next;	/* index of next element in hash chain */
} ctf_helem_t;

typedef struct ctf_hash {
	ushort_t *h_buckets;	/* hash bucket array (chain indices) */
	ctf_helem_t *h_chains;	/* hash chains buffer */
	ushort_t h_nbuckets;	/* number of elements in bucket array */
	ushort_t h_nelems;	/* number of elements in hash table */
	uint_t h_free;		/* index of next free hash element */
} ctf_hash_t;

struct ctf_idhash_iter {
	int cii_id;	/* Current iteration id */
};

typedef struct ctf_strs {
	const char *cts_strs;	/* base address of string table */
	size_t cts_len;		/* size of string table in bytes */
} ctf_strs_t;

typedef struct ctf_dmodel {
	const char *ctd_name;	/* data model name */
	int ctd_code;		/* data model code */
	size_t ctd_pointer;	/* size of void * in bytes */
	size_t ctd_char;	/* size of char in bytes */
	size_t ctd_short;	/* size of short in bytes */
	size_t ctd_int;		/* size of int in bytes */
	size_t ctd_long;	/* size of long in bytes */
} ctf_dmodel_t;

typedef struct ctf_lookup {
	const char *ctl_prefix;	/* string prefix for this lookup */
	size_t ctl_len;		/* length of prefix string in bytes */
	ctf_hash_t *ctl_hash;	/* pointer to hash table for lookup */
} ctf_lookup_t;

typedef struct ctf_fileops {
	ushort_t (*ctfo_get_kind)(ushort_t);
	ushort_t (*ctfo_get_root)(ushort_t);
	ushort_t (*ctfo_get_vlen)(ushort_t);
} ctf_fileops_t;

typedef struct ctf_list {
	struct ctf_list *l_prev; /* previous pointer or tail pointer */
	struct ctf_list *l_next; /* next pointer or head pointer */
} ctf_list_t;

typedef enum {
	CTF_PREC_BASE,
	CTF_PREC_POINTER,
	CTF_PREC_ARRAY,
	CTF_PREC_FUNCTION,
	CTF_PREC_MAX
} ctf_decl_prec_t;

typedef struct ctf_decl_node {
	ctf_list_t cd_list;			/* linked list pointers */
	ctf_id_t cd_type;			/* type identifier */
	uint_t cd_kind;				/* type kind */
	uint_t cd_n;				/* type dimension if array */
} ctf_decl_node_t;

typedef struct ctf_decl {
	ctf_list_t cd_nodes[CTF_PREC_MAX];	/* declaration node stacks */
	int cd_order[CTF_PREC_MAX];		/* storage order of decls */
	ctf_decl_prec_t cd_qualp;		/* qualifier precision */
	ctf_decl_prec_t cd_ordp;		/* ordered precision */
	char *cd_buf;				/* buffer for output */
	char *cd_ptr;				/* buffer location */
	char *cd_end;				/* buffer limit */
	size_t cd_len;				/* buffer space required */
	int cd_err;				/* saved error value */
} ctf_decl_t;

typedef struct ctf_dmdef {
	ctf_list_t dmd_list;	/* list forward/back pointers */
	char *dmd_name;		/* name of this member */
	ctf_id_t dmd_type;	/* type of this member (for sou) */
	ulong_t dmd_offset;	/* offset of this member in bits (for sou) */
	int dmd_value;		/* value of this member (for enum) */
} ctf_dmdef_t;

typedef struct ctf_dtdef {
	ctf_list_t dtd_list;	/* list forward/back pointers */
	struct ctf_dtdef *dtd_hash; /* hash chain pointer for ctf_dthash */
	char *dtd_name;		/* name associated with definition (if any) */
	ctf_id_t dtd_type;	/* type identifier for this definition */
	ctf_type_t dtd_data;	/* type node (see <sys/ctf.h>) */
	int dtd_ref;		/* recfount for dyanmic types */
	union {
		ctf_list_t dtu_members;	/* struct, union, or enum */
		ctf_arinfo_t dtu_arr;	/* array */
		ctf_encoding_t dtu_enc;	/* integer or float */
		ctf_id_t *dtu_argv;	/* function */
	} dtd_u;
} ctf_dtdef_t;

typedef struct ctf_dsdef {
	ctf_list_t dsd_list;	/* list forward/back pointers */
	ulong_t dsd_symidx;	/* symbol id */
	ctf_id_t dsd_tid;	/* type for obj, 0 if function */
	uint_t dsd_nargs;
	ctf_id_t *dsd_argc;	/* function argv */
} ctf_dsdef_t;

typedef struct ctf_dldef {
	ctf_list_t dld_list;	/* list forward/back pointers */
	char *dld_name;		/* name of the label */
	ctf_id_t dld_type;	/* type ID associated with the label */
} ctf_dldef_t;

typedef struct ctf_bundle {
	ctf_file_t *ctb_file;	/* CTF container handle */
	ctf_id_t ctb_type;	/* CTF type identifier */
	ctf_dtdef_t *ctb_dtd;	/* CTF dynamic type definition (if any) */
} ctf_bundle_t;

/*
 * The ctf_file is the structure used to represent a CTF container to library
 * clients, who see it only as an opaque pointer.  Modifications can therefore
 * be made freely to this structure without regard to client versioning.  The
 * ctf_file_t typedef appears in <sys/ctf_api.h> and declares a forward tag.
 *
 * NOTE: ctf_update() requires that everything inside of ctf_file either be an
 * immediate value, a pointer to dynamically allocated data *outside* of the
 * ctf_file itself, or a pointer to statically allocated data.  If you add a
 * pointer to ctf_file that points to something within the ctf_file itself,
 * you must make corresponding changes to ctf_update().
 */
struct ctf_file {
	const ctf_fileops_t *ctf_fileops; /* version-specific file operations */
	ctf_sect_t ctf_data;	/* CTF data from object file */
	ctf_sect_t ctf_symtab;	/* symbol table from object file */
	ctf_sect_t ctf_strtab;	/* string table from object file */
	ctf_hash_t ctf_structs;	/* hash table of struct types */
	ctf_hash_t ctf_unions;	/* hash table of union types */
	ctf_hash_t ctf_enums;	/* hash table of enum types */
	ctf_hash_t ctf_names;	/* hash table of remaining type names */
	ctf_lookup_t ctf_lookups[5];	/* pointers to hashes for name lookup */
	ctf_strs_t ctf_str[2];	/* array of string table base and bounds */
	const uchar_t *ctf_base; /* base of CTF header + uncompressed buffer */
	const uchar_t *ctf_buf;	/* uncompressed CTF data buffer */
	size_t ctf_size;	/* size of CTF header + uncompressed data */
	uint_t *ctf_sxlate;	/* translation table for symtab entries */
	ulong_t ctf_nsyms;	/* number of entries in symtab xlate table */
	uint_t *ctf_txlate;	/* translation table for type IDs */
	ushort_t *ctf_ptrtab;	/* translation table for pointer-to lookups */
	ulong_t ctf_typemax;	/* maximum valid type ID number */
	const ctf_dmodel_t *ctf_dmodel;	/* data model pointer (see above) */
	struct ctf_file *ctf_parent;	/* parent CTF container (if any) */
	const char *ctf_parlabel;	/* label in parent container (if any) */
	const char *ctf_parname;	/* basename of parent (if any) */
	uint_t ctf_refcnt;	/* reference count (for parent links) */
	uint_t ctf_flags;	/* libctf flags (see below) */
	int ctf_errno;		/* error code for most recent error */
	int ctf_version;	/* CTF data version */
	ctf_dtdef_t **ctf_dthash; /* hash of dynamic type definitions */
	ulong_t ctf_dthashlen;	/* size of dynamic type hash bucket array */
	ctf_list_t ctf_dtdefs;	/* list of dynamic type definitions */
	size_t ctf_dtstrlen;	/* total length of dynamic type strings */
	ulong_t ctf_dtnextid;	/* next dynamic type id to assign */
	ulong_t ctf_dtoldid;	/* oldest id that has been committed */
	void *ctf_specific;	/* data for ctf_get/setspecific */
	ctf_list_t ctf_dsdefs;	/* list of dynamic obj/func definitions */
	ctf_list_t ctf_dldefs;	/* list of dynamic labels */
	uint_t ctf_hflags;	/* original flags on the header */
};

#define	LCTF_INDEX_TO_TYPEPTR(fp, i) \
	((ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)]))

#define	LCTF_INFO_KIND(fp, info)	((fp)->ctf_fileops->ctfo_get_kind(info))
#define	LCTF_INFO_ROOT(fp, info)	((fp)->ctf_fileops->ctfo_get_root(info))
#define	LCTF_INFO_VLEN(fp, info)	((fp)->ctf_fileops->ctfo_get_vlen(info))

#define	LCTF_MMAP	0x0001	/* libctf should munmap buffers on close */
#define	LCTF_CHILD	0x0002	/* CTF container is a child */
#define	LCTF_RDWR	0x0004	/* CTF container is writable */
#define	LCTF_DIRTY	0x0008	/* CTF container has been modified */
/*
 * The storage for this CTF container was allocated via ctf_data_alloc()
 * and libctf should free it with ctf_data_free() on close.
 */
#define	LCTF_FREE	0x0010

#define	CTF_ELF_SCN_NAME	".SUNW_ctf"

extern ssize_t ctf_get_ctt_size(const ctf_file_t *, const ctf_type_t *,
    ssize_t *, ssize_t *);

extern void ctf_set_ctt_size(ctf_type_t *, ssize_t);

extern const ctf_type_t *ctf_lookup_by_id(ctf_file_t **, ctf_id_t);

extern ctf_file_t *ctf_fdcreate_int(int, int *, ctf_sect_t *);

extern int ctf_hash_create(ctf_hash_t *, ulong_t);
extern int ctf_hash_insert(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
extern int ctf_hash_define(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
extern ctf_helem_t *ctf_hash_lookup(ctf_hash_t *, ctf_file_t *,
    const char *, size_t);
extern uint_t ctf_hash_size(const ctf_hash_t *);
extern void ctf_hash_destroy(ctf_hash_t *);
extern void ctf_hash_dump(const char *, ctf_hash_t *, ctf_file_t *);

#define	ctf_list_prev(elem)	((void *)(((ctf_list_t *)(elem))->l_prev))
#define	ctf_list_next(elem)	((void *)(((ctf_list_t *)(elem))->l_next))

extern void ctf_list_append(ctf_list_t *, void *);
extern void ctf_list_prepend(ctf_list_t *, void *);
extern void ctf_list_insert_before(ctf_list_t *, void *, void *);
extern void ctf_list_delete(ctf_list_t *, void *);

extern void ctf_dtd_insert(ctf_file_t *, ctf_dtdef_t *);
extern void ctf_dtd_delete(ctf_file_t *, ctf_dtdef_t *);
extern ctf_dtdef_t *ctf_dtd_lookup(ctf_file_t *, ctf_id_t);

extern void ctf_dsd_delete(ctf_file_t *, ctf_dsdef_t *);
extern void ctf_dld_delete(ctf_file_t *, ctf_dldef_t *);

extern void ctf_decl_init(ctf_decl_t *, char *, size_t);
extern void ctf_decl_fini(ctf_decl_t *);
extern void ctf_decl_push(ctf_decl_t *, ctf_file_t *, ctf_id_t);
extern void ctf_decl_sprintf(ctf_decl_t *, const char *, ...);

extern const char *ctf_strraw(ctf_file_t *, uint_t);
extern const char *ctf_strptr(ctf_file_t *, uint_t);

extern ctf_file_t *ctf_set_open_errno(int *, int);
extern long ctf_set_errno(ctf_file_t *, int);

extern const void *ctf_sect_mmap(ctf_sect_t *, int);
extern void ctf_sect_munmap(const ctf_sect_t *);

extern void *ctf_data_alloc(size_t);
extern void ctf_data_free(void *, size_t);
extern void ctf_data_protect(void *, size_t);

extern void *ctf_alloc(size_t);
extern void ctf_free(void *, size_t);

extern char *ctf_strdup(const char *);
extern void ctf_strfree(char *);
extern const char *ctf_strerror(int);
extern void ctf_dprintf(const char *, ...);

extern void *ctf_zopen(int *);

extern ctf_id_t ctf_add_encoded(ctf_file_t *, uint_t, const char *,
    const ctf_encoding_t *, uint_t);
extern ctf_id_t ctf_add_reftype(ctf_file_t *, uint_t, const char *, ctf_id_t,
    uint_t);
extern boolean_t ctf_sym_valid(uintptr_t, int, uint16_t, uint64_t,
    uint32_t);

extern const ctf_type_t *ctf_dyn_lookup_by_id(ctf_file_t *, ctf_id_t);
extern int ctf_dyn_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *);

extern const char _CTF_SECTION[];	/* name of CTF ELF section */
extern const char _CTF_NULLSTR[];	/* empty string */

extern int _libctf_version;		/* library client version */
extern int _libctf_debug;		/* debugging messages enabled */

#ifdef	__cplusplus
}
#endif

#endif	/* _CTF_IMPL_H */