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