17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#ifndef	_DT_IDENT_H
287c478bdstevel@tonic-gate#define	_DT_IDENT_H
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#include <libctf.h>
337c478bdstevel@tonic-gate#include <dtrace.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#ifdef	__cplusplus
367c478bdstevel@tonic-gateextern "C" {
377c478bdstevel@tonic-gate#endif
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gate#include <dt_list.h>
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gatestruct dt_node;
427c478bdstevel@tonic-gatestruct dt_ident;
437c478bdstevel@tonic-gatestruct dt_idhash;
447c478bdstevel@tonic-gatestruct dt_irlist;
457c478bdstevel@tonic-gatestruct dt_regset;
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gatetypedef struct dt_idsig {
487c478bdstevel@tonic-gate	int dis_varargs;	/* argument index of start of varargs (or -1) */
497c478bdstevel@tonic-gate	int dis_optargs;	/* argument index of start of optargs (or -1) */
507c478bdstevel@tonic-gate	int dis_argc;		/* number of types in this signature */
517c478bdstevel@tonic-gate	struct dt_node *dis_args; /* array of nodes representing formal types */
5230ef842bmc	uint64_t dis_auxinfo;	/* auxiliary signature information, if any */
537c478bdstevel@tonic-gate} dt_idsig_t;
547c478bdstevel@tonic-gate
557c478bdstevel@tonic-gatetypedef struct dt_idnode {
567c478bdstevel@tonic-gate	struct dt_node *din_list; /* allocation list for parse tree nodes */
577c478bdstevel@tonic-gate	struct dt_node *din_root; /* root of this identifier's parse tree */
587c478bdstevel@tonic-gate	struct dt_idhash *din_hash; /* identifiers private to this subtree */
597c478bdstevel@tonic-gate	struct dt_ident **din_argv; /* identifiers in din_hash for arguments */
607c478bdstevel@tonic-gate	int din_argc;		  /* length of din_argv[] array */
617c478bdstevel@tonic-gate} dt_idnode_t;
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gatetypedef struct dt_idops {
647c478bdstevel@tonic-gate	void (*di_cook)(struct dt_node *, struct dt_ident *,
657c478bdstevel@tonic-gate	    int, struct dt_node *);
667c478bdstevel@tonic-gate	void (*di_dtor)(struct dt_ident *);
677c478bdstevel@tonic-gate	size_t (*di_size)(struct dt_ident *);
687c478bdstevel@tonic-gate} dt_idops_t;
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gatetypedef struct dt_ident {
717c478bdstevel@tonic-gate	char *di_name;		/* identifier name */
727c478bdstevel@tonic-gate	ushort_t di_kind;	/* identifier kind (see below) */
737c478bdstevel@tonic-gate	ushort_t di_flags;	/* identifier flags (see below) */
747c478bdstevel@tonic-gate	uint_t di_id;		/* variable or subr id (see <sys/dtrace.h>) */
757c478bdstevel@tonic-gate	dtrace_attribute_t di_attr; /* identifier stability attributes */
767c478bdstevel@tonic-gate	uint_t di_vers;		/* identifier version number (dt_version_t) */
777c478bdstevel@tonic-gate	const dt_idops_t *di_ops; /* identifier's class-specific ops vector */
787c478bdstevel@tonic-gate	void *di_iarg;		/* initial argument pointer for ops vector */
797c478bdstevel@tonic-gate	void *di_data;		/* private data pointer for ops vector */
807c478bdstevel@tonic-gate	ctf_file_t *di_ctfp;	/* CTF container for the variable data type */
817c478bdstevel@tonic-gate	ctf_id_t di_type;	/* CTF identifier for the variable data type */
827c478bdstevel@tonic-gate	struct dt_ident *di_next; /* pointer to next ident in hash chain */
837c478bdstevel@tonic-gate	ulong_t di_gen;		/* generation number (pass that created me) */
847c478bdstevel@tonic-gate	int di_lineno;		/* line number that defined this identifier */
857c478bdstevel@tonic-gate} dt_ident_t;
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate#define	DT_IDENT_ARRAY	0	/* identifier is an array variable */
887c478bdstevel@tonic-gate#define	DT_IDENT_SCALAR	1	/* identifier is a scalar variable */
897c478bdstevel@tonic-gate#define	DT_IDENT_PTR	2	/* identifier is a magic pointer */
907c478bdstevel@tonic-gate#define	DT_IDENT_FUNC	3	/* identifier is a built-in function */
917c478bdstevel@tonic-gate#define	DT_IDENT_AGG	4	/* identifier is an aggregation */
927c478bdstevel@tonic-gate#define	DT_IDENT_AGGFUNC 5	/* identifier is an aggregating function */
937c478bdstevel@tonic-gate#define	DT_IDENT_ACTFUNC 6	/* identifier is an action function */
947c478bdstevel@tonic-gate#define	DT_IDENT_XLSOU	7	/* identifier is a translated struct or union */
957c478bdstevel@tonic-gate#define	DT_IDENT_XLPTR	8	/* identifier is a translated pointer */
967c478bdstevel@tonic-gate#define	DT_IDENT_SYMBOL	9	/* identifier is an external symbol */
977c478bdstevel@tonic-gate#define	DT_IDENT_ENUM	10	/* identifier is an enumerator */
987c478bdstevel@tonic-gate#define	DT_IDENT_PRAGAT	11	/* identifier is #pragma attributes */
997c478bdstevel@tonic-gate#define	DT_IDENT_PRAGBN	12	/* identifier is #pragma binding */
1007c478bdstevel@tonic-gate#define	DT_IDENT_PROBE	13	/* identifier is a probe definition */
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gate#define	DT_IDFLG_TLS	0x0001	/* variable is thread-local storage */
1037c478bdstevel@tonic-gate#define	DT_IDFLG_LOCAL	0x0002	/* variable is local storage */
1047c478bdstevel@tonic-gate#define	DT_IDFLG_WRITE	0x0004	/* variable is writable (can be modified) */
1057c478bdstevel@tonic-gate#define	DT_IDFLG_INLINE	0x0008	/* variable is an inline definition */
1067c478bdstevel@tonic-gate#define	DT_IDFLG_REF	0x0010	/* variable is referenced by this program */
1077c478bdstevel@tonic-gate#define	DT_IDFLG_MOD	0x0020	/* variable is modified by this program */
1087c478bdstevel@tonic-gate#define	DT_IDFLG_DIFR	0x0040	/* variable is referenced by current DIFO */
1097c478bdstevel@tonic-gate#define	DT_IDFLG_DIFW	0x0080	/* variable is modified by current DIFO */
1107c478bdstevel@tonic-gate#define	DT_IDFLG_CGREG	0x0100	/* variable is inlined by code generator */
1117c478bdstevel@tonic-gate#define	DT_IDFLG_USER	0x0200	/* variable is associated with userland */
1127c478bdstevel@tonic-gate#define	DT_IDFLG_PRIM	0x0400	/* variable is associated with primary object */
1137c478bdstevel@tonic-gate#define	DT_IDFLG_DECL	0x0800	/* variable is associated with explicit decl */
1147c478bdstevel@tonic-gate#define	DT_IDFLG_ORPHAN	0x1000	/* variable is in a dt_node and not dt_idhash */
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gatetypedef struct dt_idhash {
1177c478bdstevel@tonic-gate	dt_list_t dh_list;	/* list prev/next pointers for dt_idstack */
1187c478bdstevel@tonic-gate	const char *dh_name;	/* name of this hash table */
1197c478bdstevel@tonic-gate	void (*dh_defer)(struct dt_idhash *, dt_ident_t *); /* defer callback */
1207c478bdstevel@tonic-gate	const dt_ident_t *dh_tmpl; /* template for initial ident population */
1217c478bdstevel@tonic-gate	uint_t dh_nextid;	/* next id to be returned by idhash_nextid() */
1227c478bdstevel@tonic-gate	uint_t dh_minid;	/* min id to be returned by idhash_nextid() */
1237c478bdstevel@tonic-gate	uint_t dh_maxid;	/* max id to be returned by idhash_nextid() */
1247c478bdstevel@tonic-gate	ulong_t dh_nelems;	/* number of identifiers in hash table */
1257c478bdstevel@tonic-gate	ulong_t dh_hashsz;	/* number of entries in dh_buckets array */
1267c478bdstevel@tonic-gate	dt_ident_t *dh_hash[1];	/* array of hash table bucket pointers */
1277c478bdstevel@tonic-gate} dt_idhash_t;
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gatetypedef struct dt_idstack {
1307c478bdstevel@tonic-gate	dt_list_t dids_list;	/* list meta-data for dt_idhash_t stack */
1317c478bdstevel@tonic-gate} dt_idstack_t;
1327c478bdstevel@tonic-gate
1337c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_assc;	/* associative array or aggregation */
1347c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_func;	/* function call built-in */
1357c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_args;	/* args[] built-in */
1367c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_regs;	/* regs[]/uregs[] built-in */
1377c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_type;	/* predefined type name string */
1387c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_thaw;	/* prefrozen type identifier */
1397c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_inline; /* inline variable */
1407c478bdstevel@tonic-gateextern const dt_idops_t dt_idops_probe;	/* probe definition */
1417c478bdstevel@tonic-gate
1427c478bdstevel@tonic-gateextern dt_idhash_t *dt_idhash_create(const char *, const dt_ident_t *,
1437c478bdstevel@tonic-gate    uint_t, uint_t);
1447c478bdstevel@tonic-gateextern void dt_idhash_destroy(dt_idhash_t *);
1457c478bdstevel@tonic-gateextern void dt_idhash_update(dt_idhash_t *);
1467c478bdstevel@tonic-gateextern dt_ident_t *dt_idhash_lookup(dt_idhash_t *, const char *);
1477c478bdstevel@tonic-gateextern int dt_idhash_nextid(dt_idhash_t *, uint_t *);
1487c478bdstevel@tonic-gateextern ulong_t dt_idhash_size(const dt_idhash_t *);
1497c478bdstevel@tonic-gateextern const char *dt_idhash_name(const dt_idhash_t *);
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gateextern dt_ident_t *dt_idhash_insert(dt_idhash_t *, const char *, ushort_t,
1527c478bdstevel@tonic-gate    ushort_t, uint_t, dtrace_attribute_t, uint_t,
1537c478bdstevel@tonic-gate    const dt_idops_t *, void *, ulong_t);
1547c478bdstevel@tonic-gate
1557c478bdstevel@tonic-gateextern void dt_idhash_xinsert(dt_idhash_t *, dt_ident_t *);
1567c478bdstevel@tonic-gateextern void dt_idhash_delete(dt_idhash_t *, dt_ident_t *);
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gatetypedef int dt_idhash_f(dt_idhash_t *, dt_ident_t *, void *);
1597c478bdstevel@tonic-gateextern int dt_idhash_iter(dt_idhash_t *, dt_idhash_f *, void *);
1607c478bdstevel@tonic-gate
1617c478bdstevel@tonic-gateextern dt_ident_t *dt_idstack_lookup(dt_idstack_t *, const char *);
1627c478bdstevel@tonic-gateextern void dt_idstack_push(dt_idstack_t *, dt_idhash_t *);
1637c478bdstevel@tonic-gateextern void dt_idstack_pop(dt_idstack_t *, dt_idhash_t *);
1647c478bdstevel@tonic-gate
1657c478bdstevel@tonic-gateextern dt_ident_t *dt_ident_create(const char *, ushort_t, ushort_t, uint_t,
1667c478bdstevel@tonic-gate    dtrace_attribute_t, uint_t, const dt_idops_t *, void *, ulong_t);
1677c478bdstevel@tonic-gateextern void dt_ident_destroy(dt_ident_t *);
1687c478bdstevel@tonic-gateextern void dt_ident_morph(dt_ident_t *, ushort_t, const dt_idops_t *, void *);
1697c478bdstevel@tonic-gateextern dtrace_attribute_t dt_ident_cook(struct dt_node *,
1707c478bdstevel@tonic-gate    dt_ident_t *, struct dt_node **);
1717c478bdstevel@tonic-gate
1727c478bdstevel@tonic-gateextern void dt_ident_type_assign(dt_ident_t *, ctf_file_t *, ctf_id_t);
1737c478bdstevel@tonic-gateextern dt_ident_t *dt_ident_resolve(dt_ident_t *);
1747c478bdstevel@tonic-gateextern size_t dt_ident_size(dt_ident_t *);
1757c478bdstevel@tonic-gateextern int dt_ident_unref(const dt_ident_t *);
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gateextern const char *dt_idkind_name(uint_t);
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate#ifdef	__cplusplus
1807c478bdstevel@tonic-gate}
1817c478bdstevel@tonic-gate#endif
1827c478bdstevel@tonic-gate
1837c478bdstevel@tonic-gate#endif	/* _DT_IDENT_H */
184