xref: /onnv-gate/usr/src/uts/common/tnf/tnf_probe.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate  */
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #ifdef _KERNEL
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/param.h>
31*0Sstevel@tonic-gate #include <sys/systm.h>
32*0Sstevel@tonic-gate #include <sys/ddi.h>		/* strchr */
33*0Sstevel@tonic-gate #include <sys/sunddi.h>		/* strchr */
34*0Sstevel@tonic-gate #include <sys/tnf_com.h>
35*0Sstevel@tonic-gate #include <sys/tnf_writer.h>
36*0Sstevel@tonic-gate #include <sys/tnf_probe.h> /* fixed tnf_probe_control_t->index problem */
37*0Sstevel@tonic-gate #include "tnf_types.h"
38*0Sstevel@tonic-gate #include "tnf_trace.h"
39*0Sstevel@tonic-gate #else  /* _KERNEL */
40*0Sstevel@tonic-gate #include <stdlib.h>
41*0Sstevel@tonic-gate #include <string.h>
42*0Sstevel@tonic-gate #include <tnf/com.h>
43*0Sstevel@tonic-gate #include <tnf/writer.h>
44*0Sstevel@tonic-gate #include <tnf/probe.h>
45*0Sstevel@tonic-gate #include "tnf_types.h"
46*0Sstevel@tonic-gate #include <tnf_trace.h>
47*0Sstevel@tonic-gate #endif	/* _KERNEL */
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate  * Defines
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #define	NAME_LIMIT	128
55*0Sstevel@tonic-gate #define	ARRAY_LIMIT	5
56*0Sstevel@tonic-gate #define	NAME_START	5
57*0Sstevel@tonic-gate #define	SLOT_OFFSET	7
58*0Sstevel@tonic-gate #define	CONST_SLOTS	2
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate /*
61*0Sstevel@tonic-gate  * probe version 1
62*0Sstevel@tonic-gate  */
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate struct tnf_probe_version  __tnf_probe_version_1_info =  {
65*0Sstevel@tonic-gate 	sizeof (struct tnf_probe_version),
66*0Sstevel@tonic-gate 	sizeof (tnf_probe_control_t)
67*0Sstevel@tonic-gate };
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate /*
70*0Sstevel@tonic-gate  * write instances of tnf_probe_type (i.e probe records)
71*0Sstevel@tonic-gate  */
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate uintptr_t
tnf_probe_tag(tnf_ops_t * ops,tnf_probe_control_t * probe_p)74*0Sstevel@tonic-gate tnf_probe_tag(tnf_ops_t *ops, tnf_probe_control_t *probe_p)
75*0Sstevel@tonic-gate {
76*0Sstevel@tonic-gate 	tnf_tag_data_t		*metatag_data;
77*0Sstevel@tonic-gate 	tnf_record_p		metatag_index;
78*0Sstevel@tonic-gate 	tnf_probe_prototype_t 	*buffer;
79*0Sstevel@tonic-gate 	enum tnf_alloc_mode	saved_mode;
80*0Sstevel@tonic-gate 	tnf_uint32_t		*fwp;
81*0Sstevel@tonic-gate 	char			probe_name[NAME_LIMIT];
82*0Sstevel@tonic-gate 	char			slot_array[ARRAY_LIMIT][NAME_LIMIT];
83*0Sstevel@tonic-gate 	char			*slot_args[ARRAY_LIMIT + CONST_SLOTS + 1];
84*0Sstevel@tonic-gate 	const char		*nm_start, *nm_end, *slot_start, *slot_end;
85*0Sstevel@tonic-gate 	int			nm_len, separator, count;
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	saved_mode = ops->mode;
88*0Sstevel@tonic-gate 	ops->mode = TNF_ALLOC_FIXED;
89*0Sstevel@tonic-gate #if defined(_LP64)
90*0Sstevel@tonic-gate 	/* LINTED assignment of 32-bit integer to 8-bit integer */
91*0Sstevel@tonic-gate 	ALLOC2(ops, sizeof (*buffer), buffer, saved_mode);
92*0Sstevel@tonic-gate #else
93*0Sstevel@tonic-gate 	ALLOC2(ops, sizeof (*buffer), buffer, saved_mode);
94*0Sstevel@tonic-gate #endif
95*0Sstevel@tonic-gate 	probe_p->index = (uintptr_t)buffer;
96*0Sstevel@tonic-gate 	fwp = tnfw_b_fw_alloc(&(ops->wcb));
97*0Sstevel@tonic-gate 	if (fwp) {
98*0Sstevel@tonic-gate 		/* REMIND: can make the next call more efficient */
99*0Sstevel@tonic-gate 		*fwp = tnf_ref32(ops, (tnf_record_p) buffer,
100*0Sstevel@tonic-gate 						(tnf_record_p)fwp);
101*0Sstevel@tonic-gate 		/* fwp - filestart < 64K */
102*0Sstevel@tonic-gate #ifdef _KERNEL
103*0Sstevel@tonic-gate 		probe_p->index = (char *)fwp - tnf_buf;
104*0Sstevel@tonic-gate #else
105*0Sstevel@tonic-gate 		probe_p->index = (char *)fwp - _tnfw_b_control->tnf_buffer;
106*0Sstevel@tonic-gate #endif
107*0Sstevel@tonic-gate 		probe_p->index |= TNF_TAG16_T_ABS;
108*0Sstevel@tonic-gate 		probe_p->index = probe_p->index << PROBE_INDEX_SHIFT;
109*0Sstevel@tonic-gate 		probe_p->index |= PROBE_INDEX_FILE_PTR;
110*0Sstevel@tonic-gate 	}
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	metatag_data = TAG_DATA(tnf_probe_type);
113*0Sstevel@tonic-gate 	metatag_index = metatag_data->tag_index ?
114*0Sstevel@tonic-gate 		metatag_data->tag_index :
115*0Sstevel@tonic-gate 		metatag_data->tag_desc(ops, metatag_data);
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 	/* find the name of the probe */
118*0Sstevel@tonic-gate 	nm_start = &(probe_p->attrs[NAME_START]);
119*0Sstevel@tonic-gate 	separator = ATTR_SEPARATOR;
120*0Sstevel@tonic-gate 	nm_end = strchr(probe_p->attrs, separator);
121*0Sstevel@tonic-gate #if defined(_LP64)
122*0Sstevel@tonic-gate 	/* LINTED assignment of 64-bit integer to 32-bit integer */
123*0Sstevel@tonic-gate 	nm_len = nm_end - nm_start;
124*0Sstevel@tonic-gate #else
125*0Sstevel@tonic-gate 	nm_len = nm_end - nm_start;
126*0Sstevel@tonic-gate #endif
127*0Sstevel@tonic-gate 	slot_start = nm_end + SLOT_OFFSET;
128*0Sstevel@tonic-gate 	nm_len = (nm_len > (NAME_LIMIT - 1)) ? (NAME_LIMIT - 1) : nm_len;
129*0Sstevel@tonic-gate 	(void) strncpy(probe_name, nm_start, nm_len);
130*0Sstevel@tonic-gate 	probe_name[nm_len] = '\0';
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	/* initialize constant part of slot names */
133*0Sstevel@tonic-gate 	slot_args[0] = TNF_N_TAG;
134*0Sstevel@tonic-gate 	slot_args[1] = TNF_N_TIME_DELTA;
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate 	/*
137*0Sstevel@tonic-gate 	 * initialize rest of slot names, if any. This parsing routine is
138*0Sstevel@tonic-gate 	 * dependant on a space after "slots" (even for TNF_PROBE_0 and a
139*0Sstevel@tonic-gate 	 * space after the last slot name.  It truncates any values that
140*0Sstevel@tonic-gate 	 * are larger than 127 chars to 127 chars.  It handles missing slot
141*0Sstevel@tonic-gate 	 * names.
142*0Sstevel@tonic-gate 	 */
143*0Sstevel@tonic-gate 	separator = ATTR_SEPARATOR;
144*0Sstevel@tonic-gate 	slot_end = strchr(slot_start, separator);
145*0Sstevel@tonic-gate 	nm_start = slot_start;
146*0Sstevel@tonic-gate 	separator = VAL_SEPARATOR;
147*0Sstevel@tonic-gate 	for (count = 0; nm_start < slot_end; count++) {
148*0Sstevel@tonic-gate 		nm_end = strchr(nm_start, separator);
149*0Sstevel@tonic-gate #if defined(_LP64)
150*0Sstevel@tonic-gate 		/* LINTED assignment of 64-bit integer to 32-bit integer */
151*0Sstevel@tonic-gate 		nm_len = nm_end - nm_start;
152*0Sstevel@tonic-gate #else
153*0Sstevel@tonic-gate 		nm_len = nm_end - nm_start;
154*0Sstevel@tonic-gate #endif
155*0Sstevel@tonic-gate 		nm_len = (nm_len > (NAME_LIMIT - 1)) ? (NAME_LIMIT - 1) :
156*0Sstevel@tonic-gate 							nm_len;
157*0Sstevel@tonic-gate 		(void) strncpy(slot_array[count], nm_start, nm_len);
158*0Sstevel@tonic-gate 		slot_array[count][nm_len] = '\0';
159*0Sstevel@tonic-gate 		slot_args[count+CONST_SLOTS] = slot_array[count];
160*0Sstevel@tonic-gate 		/* get next name */
161*0Sstevel@tonic-gate 		nm_start = nm_end + 1;
162*0Sstevel@tonic-gate 	}
163*0Sstevel@tonic-gate 	/* null terminate string vector */
164*0Sstevel@tonic-gate 	slot_args[count+CONST_SLOTS] = NULL;
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate 	ASSIGN(buffer, tag, 		metatag_index);
167*0Sstevel@tonic-gate 	ASSIGN(buffer, name, 		probe_name);
168*0Sstevel@tonic-gate 	/* XXX Fix these properties sometime */
169*0Sstevel@tonic-gate 	ASSIGN(buffer, properties, 	&tnf_struct_properties);
170*0Sstevel@tonic-gate 	ASSIGN(buffer, slot_types,	probe_p->slot_types);
171*0Sstevel@tonic-gate #if defined(_LP64)
172*0Sstevel@tonic-gate 	/* LINTED */
173*0Sstevel@tonic-gate 	ASSIGN(buffer, type_size,	probe_p->tnf_event_size);
174*0Sstevel@tonic-gate #else
175*0Sstevel@tonic-gate 	ASSIGN(buffer, type_size,	probe_p->tnf_event_size);
176*0Sstevel@tonic-gate #endif
177*0Sstevel@tonic-gate 	ASSIGN(buffer, slot_names,	slot_args);
178*0Sstevel@tonic-gate 	ASSIGN(buffer, string,		(slot_end + 1));
179*0Sstevel@tonic-gate #if defined(_LP64)
180*0Sstevel@tonic-gate 	/* supress lint warning for _KERNEL mode, really need this? */
181*0Sstevel@tonic-gate 	/* LINTED assignment of 32-bit integer to 8-bit integer */
182*0Sstevel@tonic-gate 	ops->mode = saved_mode;
183*0Sstevel@tonic-gate #else
184*0Sstevel@tonic-gate 	ops->mode = saved_mode;
185*0Sstevel@tonic-gate #endif
186*0Sstevel@tonic-gate 	return (probe_p->index);
187*0Sstevel@tonic-gate }
188