Home | History | Annotate | Download | only in tnf
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  *	Copyright (c) 1994,1998 by Sun Microsystems, Inc.
     24  *	All rights reserved.
     25  */
     26 
     27 #ifndef	_TNF_TYPES_H
     28 #define	_TNF_TYPES_H
     29 
     30 #pragma ident	"@(#)tnf_types.h	1.18	05/06/08 SMI"
     31 
     32 #include <sys/types.h>
     33 #ifdef _KERNEL
     34 #include <sys/tnf_com.h>
     35 #include <sys/tnf_writer.h>
     36 #include <sys/tnf_probe.h>
     37 #include "tnf_buf.h"
     38 #else  /* _KERNEL */
     39 #include <tnf/com.h>
     40 #include <tnf/writer.h>
     41 #include <tnf/probe.h>
     42 #endif /* _KERNEL */
     43 
     44 #ifdef	__cplusplus
     45 extern "C" {
     46 #endif
     47 
     48 extern struct tnf_probe_version __tnf_probe_version_1_info;
     49 
     50 /*
     51  * Defines
     52  */
     53 
     54 #define	TAG_DATA(type)		type##_tag_data
     55 #define	_TAG_DATA(type)		_##type##_tag_data
     56 
     57 #define	TAG_SNAP(type)		TAG_DATA(type) = &_TAG_DATA(type)
     58 #define	TAG_EXPORT(type)	tnf_tag_data_t *TAG_SNAP(type)
     59 
     60 /*
     61  * String limits
     62  */
     63 
     64 /* XXX tie into TNF_BLOCK_SIZE */
     65 #define	TNF_STRING_LIMIT	255	/* excludes terminating NUL */
     66 #define	TNF_STRING_ROUNDUP(sz)	(((sz) + 3) & ~3)
     67 
     68 /*
     69  * XXX Semi-private
     70  */
     71 
     72 #ifdef _KERNEL
     73 
     74 #define	TAG_SET(type)		TAG_SNAP(type)
     75 #define	BUF_ALLOC(ops)		tnfw_b_alloc
     76 
     77 #else	/* _KERNEL */
     78 
     79 #define	TAG_SET(type)		TAG_EXPORT(type)
     80 #define	BUF_ALLOC(ops)		ops->alloc
     81 
     82 #endif	/* _KERNEL */
     83 
     84 #define	ASSIGN(buf, slot, val)						\
     85 	buf->slot = tnf_##slot(ops, val, (tnf_record_p) &buf->slot)
     86 
     87 #define	ASSIGN2(buf, slot, val, func)					\
     88 	buf->slot = tnf_##func(ops, val, (tnf_record_p)&buf->slot)
     89 
     90 #define	ALLOC(ops, size, mem, index_p, saved_mode)			\
     91 	mem = BUF_ALLOC(ops)(&(ops->wcb), size, ops->mode);		\
     92 	if (mem == TNF_NULL) {						\
     93 		ops->mode = saved_mode;					\
     94 		return (TNF_NULL);					\
     95 	}								\
     96 	index_p = (tnf_record_p)mem
     97 
     98 #define	ALLOC2(ops, size, mem, saved_mode)				\
     99 	mem = BUF_ALLOC(ops)(&(ops->wcb), size, ops->mode);		\
    100 	if (mem == TNF_NULL) {						\
    101 		ops->mode = saved_mode;					\
    102 		return (TNF_NULL);					\
    103 	}
    104 
    105 /*
    106  * NOTE: These macros DO NOT export the tags.  In the kernel, tag data
    107  * pointers are initialized to NULL in tnf_res.c, and are snapped by
    108  * tnf_tag_XXX_init() when the driver is loaded.  In user land
    109  * they are exported by another macro.
    110  */
    111 
    112 /*
    113  * Initializing abstract tags
    114  */
    115 
    116 #define	TNF_ABSTRACT_TAG(type)					\
    117 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    118 	TNF_TAG_VERSION,					\
    119 	&tnf_abstract_tag_1, 					\
    120 	0, 							\
    121 	TNF_STRINGIFY(type) }
    122 
    123 /*
    124  * Initializing scalar tags
    125  */
    126 
    127 #define	TNF_SCALAR_TAG(type, size, align, kind)			\
    128 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    129 	TNF_TAG_VERSION, 					\
    130 	&tnf_scalar_tag_1, 					\
    131 	0, 							\
    132 	TNF_STRINGIFY(type),					\
    133 	&tnf_scalar_properties,					\
    134 	size,							\
    135 	align,							\
    136 	size,							\
    137 	kind }
    138 
    139 #define	TNF_STD_SCALAR_TAG(type, kind)				\
    140 	TNF_SCALAR_TAG(type, sizeof (type##_t),			\
    141 		TNF_ALIGN(type##_t), kind)
    142 
    143 /*
    144  * Initializing array tags
    145  * Assumes all arrays are `records'
    146  */
    147 
    148 #define	TNF_ARRAY_TAG(type, eltag, props, slots, kind)		\
    149 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    150 	TNF_TAG_VERSION, 					\
    151 	&tnf_array_tag_1, 					\
    152 	0, 							\
    153 	TNF_STRINGIFY(type),					\
    154 	&props,							\
    155 	ARRAY_HDR_SIZE,						\
    156 	TNF_ALIGN(tnf_ref32_t),					\
    157 	sizeof (tnf_ref32_t), 					\
    158 	kind,	 						\
    159 	eltag,							\
    160 	slots }
    161 
    162 #define	TNF_STD_ARRAY_TAG(type, eltype, kind)			\
    163 	TNF_ARRAY_TAG(type, &TAG_DATA(eltype),			\
    164 		tnf_array_properties, tnf_array_slots, kind)
    165 
    166 /*
    167  * Initializing derived tags
    168  */
    169 
    170 #define	TNF_DERIVED_TAG(type, basetag, props, size, align, kind)	\
    171 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    172 	TNF_TAG_VERSION,					\
    173 	&tnf_derived_tag_1,	 				\
    174 	0,	 						\
    175 	TNF_STRINGIFY(type),					\
    176 	&props,		 					\
    177 	0,	 						\
    178 	align,			 				\
    179 	size,							\
    180 	kind,		 					\
    181 	basetag }
    182 
    183 #define	TNF_STD_DERIVED_TAG(type, base, props, kind)		\
    184 	TNF_DERIVED_TAG(type, &TAG_DATA(base), props, 		\
    185 		sizeof (type##_t), TNF_ALIGN(type##_t), kind)
    186 
    187 /*
    188  * Initializing structure tags
    189  * Assumes all structs are `records'
    190  */
    191 
    192 #define	TNF_STRUCT_TAG(type, props, slots, names, size)		\
    193 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    194 	TNF_TAG_VERSION,					\
    195 	&tnf_struct_tag_1,					\
    196 	0,							\
    197 	TNF_STRINGIFY(type),					\
    198 	&props,							\
    199 	size,							\
    200 	TNF_ALIGN(tnf_ref32_t),					\
    201 	sizeof (tnf_ref32_t),					\
    202 	TNF_STRUCT,						\
    203 	0,							\
    204 	slots,							\
    205 	names }
    206 
    207 #define	TNF_STD_STRUCT_TAG(type, slots, names, size)		\
    208 	TNF_STRUCT_TAG(type, tnf_struct_properties, slots, names, size)
    209 
    210 /*
    211  * Initializing metatags
    212  * Size is initialized assuming NULL-terminated array of words and
    213  * each element has a reference size of one word.
    214  */
    215 
    216 #define	TNF_METATAG(type, props, slots, desc)			\
    217 static tnf_tag_data_t	_TAG_DATA(type) = {			\
    218 	TNF_TAG_VERSION,					\
    219 	&desc,							\
    220 	0,							\
    221 	TNF_STRINGIFY(type),					\
    222 	&props,							\
    223 	(sizeof (slots) - sizeof (slots[0])) *  	        \
    224 	(sizeof (tnf_uint32_t))/(sizeof (char *)),	        \
    225 	TNF_ALIGN(tnf_ref32_t),					\
    226 	sizeof (tnf_ref32_t),					\
    227 	TNF_STRUCT,						\
    228 	0,							\
    229 	slots,							\
    230 	0 }
    231 
    232 /*
    233  * TNF internal types
    234  */
    235 
    236 extern tnf_tag_data_t		*tnf_tag_arg_tag_data;
    237 typedef tnf_ref32_t		tnf_tag_arg_t; /* tag qualifier */
    238 
    239 extern tnf_tag_data_t		*tnf_inline_tag_data; /* abstract */
    240 
    241 extern tnf_tag_data_t		*tnf_tagged_tag_data; /* abstract */
    242 
    243 extern tnf_tag_data_t		*tnf_scalar_tag_data; /* abstract scalar */
    244 
    245 extern tnf_tag_data_t		*tnf_array_tag_data; /* abstract array */
    246 
    247 extern tnf_tag_data_t		*tnf_derived_tag_data; /* abstract derived */
    248 
    249 extern tnf_tag_data_t		*tnf_derived_base_tag_data;
    250 typedef tnf_reference_t		tnf_derived_base_t;
    251 #define	tnf_derived_base(ops, item, ref)\
    252 	tnf_tag_element_1(ops, item, ref, tnf_derived_base_tag_data)
    253 
    254 extern tnf_tag_data_t		*tnf_element_type_tag_data;
    255 typedef tnf_reference_t		tnf_element_type_t;
    256 #define	tnf_element_type(ops, item, ref)\
    257 	tnf_tag_element_1(ops, item, ref, tnf_element_type_tag_data)
    258 
    259 extern tnf_tag_data_t		*tnf_type_array_tag_data;
    260 typedef tnf_reference_t		tnf_type_array_t;
    261 #define	tnf_type_array(ops, item, ref)	\
    262 	tnf_tag_array_1(ops, item, ref, tnf_type_array_tag_data)
    263 
    264 extern tnf_tag_data_t		*tnf_slot_types_tag_data;
    265 typedef tnf_type_array_t	tnf_slot_types_t;
    266 #define	tnf_slot_types(ops, item, ref)	\
    267 	tnf_tag_array_1(ops, item, ref, tnf_slot_types_tag_data)
    268 
    269 extern tnf_tag_data_t		*tnf_properties_tag_data;
    270 typedef tnf_type_array_t	tnf_properties_t;
    271 #define	tnf_properties(ops, item, ref) 	\
    272 	tnf_tag_properties_1(ops, item, ref, tnf_properties_tag_data)
    273 
    274 extern tnf_tag_data_t		*tnf_name_array_tag_data;
    275 typedef tnf_reference_t		tnf_name_array_t;
    276 #define	tnf_name_array(ops, item, ref)	\
    277 	tnf_string_array_1(ops, item, ref, tnf_name_array_tag_data)
    278 
    279 extern tnf_tag_data_t		*tnf_slot_names_tag_data;
    280 typedef tnf_name_array_t	tnf_slot_names_t;
    281 #define	tnf_slot_names(ops, item, ref)	\
    282 	tnf_string_array_1(ops, item, ref, tnf_slot_names_tag_data)
    283 
    284 extern tnf_tag_data_t		*tnf_align_tag_data;
    285 typedef tnf_uint32_t		tnf_align_t;
    286 #define	tnf_align(ops, item, ref)	\
    287 	tnf_uint32(ops, item, ref)
    288 
    289 extern tnf_tag_data_t		*tnf_self_size_tag_data;
    290 typedef tnf_uint32_t		tnf_self_size_t;
    291 #define	tnf_self_size(ops, item, ref) 	\
    292 	tnf_uint32(ops, item, ref)
    293 
    294 extern tnf_tag_data_t		*tnf_type_size_tag_data;
    295 typedef tnf_uint32_t		tnf_type_size_t;
    296 #define	tnf_type_size(ops, item, ref) 	\
    297 	tnf_uint32(ops, item, ref)
    298 
    299 extern tnf_tag_data_t		*tnf_header_size_tag_data;
    300 typedef tnf_uint32_t		tnf_header_size_t;
    301 #define	tnf_header_size(ops, item, ref) \
    302 	tnf_uint32(ops, item, ref)
    303 
    304 extern tnf_tag_data_t		*tnf_struct_tag_data; /* abstract struct */
    305 
    306 extern tnf_tag_data_t		*tnf_type_tag_data; /* abstract type */
    307 
    308 extern tnf_tag_data_t		*tnf_scalar_type_tag_data;
    309 
    310 extern tnf_tag_data_t		*tnf_derived_type_tag_data;
    311 
    312 extern tnf_tag_data_t		*tnf_array_type_tag_data;
    313 
    314 extern tnf_tag_data_t		*tnf_struct_type_tag_data;
    315 
    316 /*
    317  * Concrete struct types
    318  */
    319 
    320 extern tnf_tag_data_t		*tnf_file_header_tag_data;
    321 
    322 extern tnf_tag_data_t		*tnf_block_header_tag_data;
    323 
    324 /*
    325  * Exported slots
    326  */
    327 
    328 extern tnf_tag_data_t		**tnf_array_slots[];
    329 
    330 /*
    331  * Exported properties
    332  */
    333 
    334 extern tnf_tag_data_t		***tnf_no_properties;
    335 extern tnf_tag_data_t		***tnf_scalar_properties;
    336 extern tnf_tag_data_t		***tnf_array_properties;
    337 extern tnf_tag_data_t		***tnf_derived_properties;
    338 extern tnf_tag_data_t		***tnf_struct_properties;
    339 extern tnf_tag_data_t		***tnf_type_properties;
    340 
    341 /*
    342  * Binary layout of standard array header
    343  */
    344 
    345 typedef struct {
    346 	tnf_tag_t		tag;
    347 	tnf_self_size_t		self_size;
    348 } tnf_array_header_t;
    349 
    350 #define	ARRAY_HDR_SIZE	sizeof (tnf_array_header_t)
    351 
    352 /*
    353  * Binary layouts of TNF tags
    354  */
    355 
    356 typedef struct {
    357 	tnf_tag_t		tag;
    358 	tnf_name_t		name;
    359 	tnf_properties_t	properties;
    360 } tnf_type_prototype_t;
    361 
    362 typedef struct {
    363 	tnf_tag_t		tag;
    364 	tnf_name_t		name;
    365 	tnf_properties_t	properties;
    366 	tnf_type_size_t		type_size;
    367 	tnf_align_t		align;
    368 } tnf_scalar_type_prototype_t;
    369 
    370 typedef struct {
    371 	tnf_tag_t		tag;
    372 	tnf_name_t		name;
    373 	tnf_properties_t	properties;
    374 	tnf_derived_base_t	derived_base;
    375 } tnf_derived_type_prototype_t;
    376 
    377 typedef struct {
    378 	tnf_tag_t		tag;
    379 	tnf_name_t		name;
    380 	tnf_properties_t	properties;
    381 	tnf_slot_types_t	slot_types;
    382 	tnf_header_size_t	header_size;
    383 	tnf_element_type_t	element_type;
    384 } tnf_array_type_prototype_t;
    385 
    386 typedef struct {
    387 	tnf_tag_t		tag;
    388 	tnf_name_t		name;
    389 	tnf_properties_t	properties;
    390 	tnf_slot_types_t	slot_types;
    391 	tnf_type_size_t		type_size;
    392 	tnf_slot_names_t	slot_names;
    393 } tnf_struct_type_prototype_t;
    394 
    395 /*
    396  * Data encoders
    397  */
    398 
    399 extern tnf_reference_t	tnf_tag_element_1(tnf_ops_t *,
    400 					tnf_tag_data_t **,
    401 					tnf_record_p,
    402 					tnf_tag_data_t *);
    403 
    404 extern tnf_reference_t	tnf_tag_array_1(tnf_ops_t *,
    405 					tnf_tag_data_t ***,
    406 					tnf_record_p,
    407 					tnf_tag_data_t *);
    408 
    409 extern tnf_reference_t	tnf_tag_properties_1(tnf_ops_t *,
    410 					tnf_tag_data_t ****,
    411 					tnf_record_p,
    412 					tnf_tag_data_t *);
    413 
    414 extern tnf_reference_t	tnf_string_array_1(tnf_ops_t *,
    415 					char **,
    416 					tnf_record_p,
    417 					tnf_tag_data_t *);
    418 
    419 /*
    420  * Tag descriptors
    421  */
    422 
    423 extern tnf_record_p tnf_abstract_tag_1(tnf_ops_t *, tnf_tag_data_t *);
    424 extern tnf_record_p tnf_scalar_tag_1(tnf_ops_t *, tnf_tag_data_t *);
    425 extern tnf_record_p tnf_derived_tag_1(tnf_ops_t *, tnf_tag_data_t *);
    426 extern tnf_record_p tnf_array_tag_1(tnf_ops_t *, tnf_tag_data_t *);
    427 
    428 #ifdef _KERNEL
    429 /*
    430  * Tag pointer initializers, called when driver loaded to snap all
    431  * tag data pointers.
    432  */
    433 
    434 extern void tnf_tag_core_init(void);	/* initialize core tags */
    435 extern void tnf_tag_trace_init(void);	/* initialize trace tags */
    436 #endif /* _KERNEL */
    437 
    438 #ifdef	__cplusplus
    439 }
    440 #endif
    441 
    442 #endif /* _TNF_TYPES_H */
    443