4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
35 #include "sdbc_stats.h"
39 static sigjmp_buf env
;
40 static sig_atomic_t sig_raised
= 0;
41 static void sig_handler(int);
56 * kstat_retrieve() - populate the ks_data field of the kstat_t structure
58 * This function is a user-land equivalent of a ks_snapshot
61 * kstat_ctl_t *kc - kstat_ctl_t structure representing returned from
63 * kstat_t *ksp - kstat_t strcture to popluate ks_data into
66 * NULL pointer on failure
67 * kstat_t * structure on success
70 kstat_retrieve(kstat_ctl_t
*kc
, kstat_t
*ksp
)
77 struct sigaction segv_act
; /* default actions */
82 if (ksp
->ks_data
== NULL
&&
83 kstat_read(kc
, ksp
, NULL
) == -1)
86 rval
= (kstat_t
*)calloc(1, sizeof (*ksp
));
87 (void) memcpy(rval
, ksp
, sizeof (*ksp
));
89 rval
->ks_data
= (void *) calloc(1, ksp
->ks_data_size
);
90 (void) memcpy(rval
->ks_data
, ksp
->ks_data
,
91 sizeof (kstat_named_t
) * ksp
->ks_ndata
);
93 /* special handling for variable length string KSTAT_DATA_STRING */
94 knp
= (kstat_named_t
*)rval
->ks_data
;
95 end
= (char *)(knp
+ ksp
->ks_ndata
);
96 for (i
= 0; i
< ksp
->ks_ndata
; i
++, knp
++) {
97 if (knp
->data_type
== KSTAT_DATA_STRING
&&
98 KSTAT_NAMED_STR_PTR(knp
) != NULL
) {
99 /* catch SIGSEGV (bug 6384130) */
101 (void) sigaction(SIGSEGV
, NULL
, &segv_act
);
102 (void) signal(SIGSEGV
, sig_handler
);
104 (void) strncpy(end
, KSTAT_NAMED_STR_PTR(knp
),
105 KSTAT_NAMED_STR_BUFLEN(knp
));
106 KSTAT_NAMED_STR_PTR(knp
) = end
;
107 end
+= KSTAT_NAMED_STR_BUFLEN(knp
);
110 (void) sigsetjmp(env
, 0);
112 bzero(end
, KSTAT_NAMED_STR_BUFLEN(knp
));
113 KSTAT_NAMED_STR_PTR(knp
) = end
;
114 end
+= KSTAT_NAMED_STR_BUFLEN(knp
);
116 (void) sigaction(SIGSEGV
, &segv_act
, NULL
);
124 * kstat_value() - retrieve value of a field in a kstat_named_t kstat.
127 * kstat_t *ksp - kstat containing the field
128 * char *name - text string representing the field name
131 * void * - pointer to data retrieved
134 kstat_value(kstat_t
*ksp
, char *name
)
138 if ((knm
= kstat_data_lookup(ksp
, name
)) == NULL
)
141 switch (knm
->data_type
) {
142 case KSTAT_DATA_CHAR
:
143 return (knm
->value
.c
);
144 case KSTAT_DATA_INT32
:
145 return (&knm
->value
.i32
);
146 case KSTAT_DATA_UINT32
:
147 return (&knm
->value
.ui32
);
148 case KSTAT_DATA_INT64
:
149 return (&knm
->value
.i64
);
150 case KSTAT_DATA_UINT64
:
151 return (&knm
->value
.ui64
);
152 case KSTAT_DATA_STRING
:
153 return (KSTAT_NAMED_STR_PTR(knm
));
160 * kstat_free() - deallocated memory associated with a kstat
163 * kstat_t ksp - kstat to be deallocated
169 kstat_free(kstat_t
*ksp
)
172 if (ksp
->ks_data
!= NULL
)
179 kstat_delta(kstat_t
*pksp
, kstat_t
*cksp
, char *name
)
183 pv
= kstat_value(pksp
, name
);
184 cv
= kstat_value(cksp
, name
);
186 return (u32_delta(*pv
, *cv
));