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 /* 29*7c478bd9Sstevel@tonic-gate * Includes 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifndef DEBUG 33*7c478bd9Sstevel@tonic-gate #define NDEBUG 1 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <assert.h> 37*7c478bd9Sstevel@tonic-gate #include <limits.h> 38*7c478bd9Sstevel@tonic-gate #include <values.h> 39*7c478bd9Sstevel@tonic-gate #include <stdio.h> 40*7c478bd9Sstevel@tonic-gate #include <string.h> 41*7c478bd9Sstevel@tonic-gate #include <unistd.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #include "tnf_trace.h" 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate /* 46*7c478bd9Sstevel@tonic-gate * Defines 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #define ASSERT(expr) assert(expr) 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #define ENCODED_TAG(tag, tagarg) \ 52*7c478bd9Sstevel@tonic-gate (((tag) | ((tagarg) & 0xfffc)) | TNF_REF32_T_PAIR) 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /* 55*7c478bd9Sstevel@tonic-gate * CAUTION: halfword_accessible assumes that the pointer is to a reclaimable 56*7c478bd9Sstevel@tonic-gate * block - i.e. negative offsets have a 0 in high bit 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate #define HALFWORD_ACCESSIBLE(x) \ 59*7c478bd9Sstevel@tonic-gate ((((x) & 0xffff8000) == 0) || (((x) & 0xffff8000) == 0x7fff8000)) 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * Check that x can be encoded in tagarg slot 63*7c478bd9Sstevel@tonic-gate * Same as above, but operates on ints (no space bit) 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate #define TAGARG_CHECK(x) \ 66*7c478bd9Sstevel@tonic-gate (((x) < 32767) && ((x) > -32768)) 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * Check that hi 32 bits of hrtime are zero 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate #define TIME_CHECK(x) \ 72*7c478bd9Sstevel@tonic-gate (((x) >> 32) == 0) 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate /* 75*7c478bd9Sstevel@tonic-gate * CAUTION: Use the following macro only when doing a self relative pointer 76*7c478bd9Sstevel@tonic-gate * to a target in the same block 77*7c478bd9Sstevel@tonic-gate */ 78*7c478bd9Sstevel@tonic-gate #define PTR_DIFF(item, ref) \ 79*7c478bd9Sstevel@tonic-gate ((tnf_ref32_t)((tnf_record_p)(item) - (tnf_record_p)(ref))) 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * Typedefs 83*7c478bd9Sstevel@tonic-gate */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate typedef struct { 86*7c478bd9Sstevel@tonic-gate tnf_probe_event_t probe_event; 87*7c478bd9Sstevel@tonic-gate tnf_time_delta_t time_delta; 88*7c478bd9Sstevel@tonic-gate } probe_event_prototype_t; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* 91*7c478bd9Sstevel@tonic-gate * tnf_trace_alloc 92*7c478bd9Sstevel@tonic-gate * the probe allocation function 93*7c478bd9Sstevel@tonic-gate */ 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate #define IS_NEWBLOCK(blockArray, dataBuffer) \ 96*7c478bd9Sstevel@tonic-gate (((caddr_t)&blockArray[1]) == (caddr_t)dataBuffer) 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate void * 99*7c478bd9Sstevel@tonic-gate tnf_trace_alloc(tnf_ops_t *ops, tnf_probe_control_t *probe_p, 100*7c478bd9Sstevel@tonic-gate tnf_probe_setup_t *set_p) 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate TNFW_B_WCB *wcb; 103*7c478bd9Sstevel@tonic-gate volatile char *file_start; 104*7c478bd9Sstevel@tonic-gate uintptr_t probe_index; 105*7c478bd9Sstevel@tonic-gate tnf_record_p sched_record_p; 106*7c478bd9Sstevel@tonic-gate tnf_reference_t sched_offset, tag_disp; 107*7c478bd9Sstevel@tonic-gate tnf_block_header_t *block; 108*7c478bd9Sstevel@tonic-gate tnf_uint32_t shift; 109*7c478bd9Sstevel@tonic-gate probe_event_prototype_t *buffer; 110*7c478bd9Sstevel@tonic-gate hrtime_t curr_time, time_diff; 111*7c478bd9Sstevel@tonic-gate tnf_schedule_t *sched; 112*7c478bd9Sstevel@tonic-gate tnf_ref32_t *fwd_p; 113*7c478bd9Sstevel@tonic-gate ulong_t size, asize; 114*7c478bd9Sstevel@tonic-gate #if defined(DEBUG) || defined(VERYVERBOSE) 115*7c478bd9Sstevel@tonic-gate char tmp_buf[512]; 116*7c478bd9Sstevel@tonic-gate #endif 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate ASSERT(ops != NULL); 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* check if already in a probe */ 121*7c478bd9Sstevel@tonic-gate if (ops->busy) 122*7c478bd9Sstevel@tonic-gate return (NULL); 123*7c478bd9Sstevel@tonic-gate ops->busy = 1; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 127*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: begin\n"); 128*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 129*7c478bd9Sstevel@tonic-gate #endif 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate /* 132*7c478bd9Sstevel@tonic-gate * CAUTION: Ordering of function calls in this file is critical because 133*7c478bd9Sstevel@tonic-gate * we call TNFW_B_GIVEBACK. Between the time we allocate space for the 134*7c478bd9Sstevel@tonic-gate * event and call TNFW_B_GIVEBACK there can be no other allocations!! 135*7c478bd9Sstevel@tonic-gate */ 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * Write probe tag if needed 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate probe_index = probe_p->index; 141*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 142*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: (1) probe_index=%p\n", probe_index); 143*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 144*7c478bd9Sstevel@tonic-gate #endif 145*7c478bd9Sstevel@tonic-gate if (probe_index == 0) { 146*7c478bd9Sstevel@tonic-gate if ((probe_index = tnf_probe_tag(ops, probe_p)) == 0) { 147*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 148*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: (2) probe_index=%p\n", 149*7c478bd9Sstevel@tonic-gate probe_index); 150*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 151*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: goto null_ret\n"); 152*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 153*7c478bd9Sstevel@tonic-gate fflush(stderr); 154*7c478bd9Sstevel@tonic-gate sleep(2); 155*7c478bd9Sstevel@tonic-gate #endif 156*7c478bd9Sstevel@tonic-gate goto null_ret; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 159*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: (3) probe_index=%p\n", 160*7c478bd9Sstevel@tonic-gate probe_index); 161*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 162*7c478bd9Sstevel@tonic-gate fflush(stderr); 163*7c478bd9Sstevel@tonic-gate #endif 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate /* 166*7c478bd9Sstevel@tonic-gate * Determine how much memory is required 167*7c478bd9Sstevel@tonic-gate */ 168*7c478bd9Sstevel@tonic-gate size = probe_p->tnf_event_size; 169*7c478bd9Sstevel@tonic-gate asize = size + sizeof (tnf_ref32_t); /* one fwd ptr */ 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate if (PROBE_IS_FILE_PTR(probe_index)) { 172*7c478bd9Sstevel@tonic-gate /* common case - probe_index is a file ptr */ 173*7c478bd9Sstevel@tonic-gate tag_disp = probe_index & PROBE_INDEX_LOW_MASK; 174*7c478bd9Sstevel@tonic-gate } else { 175*7c478bd9Sstevel@tonic-gate /* rare case -- get an extra fwd ptr */ 176*7c478bd9Sstevel@tonic-gate asize += sizeof (tnf_ref32_t); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * Allocate memory 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate wcb = &(ops->wcb); 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 185*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc, wcb=%p\n", wcb); 186*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 187*7c478bd9Sstevel@tonic-gate #endif 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate buffer = ops->alloc(wcb, asize, ops->mode); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 192*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc, buffer=%p\n", buffer); 193*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 194*7c478bd9Sstevel@tonic-gate #endif 195*7c478bd9Sstevel@tonic-gate if (buffer == NULL) 196*7c478bd9Sstevel@tonic-gate goto null_ret; 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */ 199*7c478bd9Sstevel@tonic-gate fwd_p = (tnf_ref32_t *) ((char *)(buffer) + size); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 202*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc, fwd_pr=%p\n", fwd_p); 203*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 204*7c478bd9Sstevel@tonic-gate #endif 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate /* set file_start after calling alloc because it allocs the file */ 207*7c478bd9Sstevel@tonic-gate file_start = _tnfw_b_control->tnf_buffer; 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate /* Check if the probe tag needs more work */ 210*7c478bd9Sstevel@tonic-gate if (!PROBE_IS_FILE_PTR(probe_index)) { 211*7c478bd9Sstevel@tonic-gate /* LINTED use up first fwd ptr */ 212*7c478bd9Sstevel@tonic-gate *fwd_p = TNF_REF32_MAKE_PERMANENT( 213*7c478bd9Sstevel@tonic-gate /* LINTED ptr subtraction */ 214*7c478bd9Sstevel@tonic-gate (tnf_record_p)probe_index - (tnf_record_p) file_start); 215*7c478bd9Sstevel@tonic-gate /* LINTED ptr subtraction */ 216*7c478bd9Sstevel@tonic-gate tag_disp = PTR_DIFF(fwd_p, buffer); 217*7c478bd9Sstevel@tonic-gate ASSERT(TAGARG_CHECK(tag_disp)); 218*7c478bd9Sstevel@tonic-gate tag_disp |= TNF_TAG16_T_REL; 219*7c478bd9Sstevel@tonic-gate tag_disp = tag_disp << TNF_REF32_TAG16_SHIFT; 220*7c478bd9Sstevel@tonic-gate fwd_p++; 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate /* 224*7c478bd9Sstevel@tonic-gate * Get timestamp 225*7c478bd9Sstevel@tonic-gate */ 226*7c478bd9Sstevel@tonic-gate curr_time = gethrtime(); 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate /* 229*7c478bd9Sstevel@tonic-gate * initialize and write schedule record if needed 230*7c478bd9Sstevel@tonic-gate * watch out for sched->record_p - it has to be checked after alloc is 231*7c478bd9Sstevel@tonic-gate * called for the event, because it could be side effected by alloc 232*7c478bd9Sstevel@tonic-gate * if a fork happened. Pre-requisite to our algorithm - if a fork 233*7c478bd9Sstevel@tonic-gate * happens all other threads have to be quiescent i.e. not in a probe. 234*7c478bd9Sstevel@tonic-gate */ 235*7c478bd9Sstevel@tonic-gate sched = &(ops->schedule); 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 238*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc, sched=%p\n", sched); 239*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 240*7c478bd9Sstevel@tonic-gate #endif 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate /* LINTED pointer cast */ 243*7c478bd9Sstevel@tonic-gate shift = ((tnf_buf_file_header_t *)file_start)->com.file_log_size; 244*7c478bd9Sstevel@tonic-gate block = (tnf_block_header_t *)((ulong_t)buffer & TNF_BLOCK_MASK); 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate if ((sched_record_p = sched->record_p) == NULL || 247*7c478bd9Sstevel@tonic-gate IS_NEWBLOCK(block, buffer)) { 248*7c478bd9Sstevel@tonic-gate /* No record written yet */ 249*7c478bd9Sstevel@tonic-gate goto new_schedule; 250*7c478bd9Sstevel@tonic-gate } 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate /* 253*7c478bd9Sstevel@tonic-gate * Note: Don't bother about space bit here, because we'll 254*7c478bd9Sstevel@tonic-gate * only use bits 15:2 anyway 255*7c478bd9Sstevel@tonic-gate */ 256*7c478bd9Sstevel@tonic-gate sched_offset = ((sched->record_gen - block->generation) << shift) + 257*7c478bd9Sstevel@tonic-gate /* LINTED - ptr subtraction */ 258*7c478bd9Sstevel@tonic-gate (uint_t) (sched_record_p - (caddr_t)buffer); 259*7c478bd9Sstevel@tonic-gate 260*7c478bd9Sstevel@tonic-gate if (!TAGARG_CHECK(sched_offset)) 261*7c478bd9Sstevel@tonic-gate /* Record too far away to reference */ 262*7c478bd9Sstevel@tonic-gate goto new_schedule; 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate time_diff = curr_time - sched->time_base; 265*7c478bd9Sstevel@tonic-gate if (!TIME_CHECK(time_diff)) 266*7c478bd9Sstevel@tonic-gate /* Time delta can't fit in 32 bits */ 267*7c478bd9Sstevel@tonic-gate goto new_schedule; 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate /* 270*7c478bd9Sstevel@tonic-gate * Can reuse existing schedule record 271*7c478bd9Sstevel@tonic-gate * Since we did not allocate any more space, can giveback 272*7c478bd9Sstevel@tonic-gate */ 273*7c478bd9Sstevel@tonic-gate /* LINTED - GIVEBACK returns a pointer subtraction */ 274*7c478bd9Sstevel@tonic-gate TNFW_B_GIVEBACK(wcb, fwd_p); 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate good_ret: 277*7c478bd9Sstevel@tonic-gate /* 278*7c478bd9Sstevel@tonic-gate * Store return params and two common event members, return buffer 279*7c478bd9Sstevel@tonic-gate */ 280*7c478bd9Sstevel@tonic-gate set_p->tpd_p = ops; 281*7c478bd9Sstevel@tonic-gate set_p->buffer_p = buffer; 282*7c478bd9Sstevel@tonic-gate set_p->probe_p = probe_p; 283*7c478bd9Sstevel@tonic-gate buffer->probe_event = ENCODED_TAG(tag_disp, sched_offset); 284*7c478bd9Sstevel@tonic-gate /* LINTED - TIME_CHECK already passed, see above */ 285*7c478bd9Sstevel@tonic-gate buffer->time_delta = tnf_time_delta(ops, (unsigned long)time_diff, 286*7c478bd9Sstevel@tonic-gate &buffer->probe_time_delta); 287*7c478bd9Sstevel@tonic-gate return (buffer); 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate new_schedule: 290*7c478bd9Sstevel@tonic-gate /* 291*7c478bd9Sstevel@tonic-gate * Write a new schedule record for this thread 292*7c478bd9Sstevel@tonic-gate */ 293*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 294*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, " tnf_trace_alloc: initializing " 295*7c478bd9Sstevel@tonic-gate "new schedule record\n"); 296*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 297*7c478bd9Sstevel@tonic-gate #endif 298*7c478bd9Sstevel@tonic-gate _tnf_sched_init(sched, curr_time); 299*7c478bd9Sstevel@tonic-gate time_diff = 0; 300*7c478bd9Sstevel@tonic-gate if ((sched_record_p = tnf_schedule_write(ops, sched)) != NULL) { 301*7c478bd9Sstevel@tonic-gate /* use one of the extra alloced words for the forwarding ptr */ 302*7c478bd9Sstevel@tonic-gate /* LINTED - ptr subtraction */ 303*7c478bd9Sstevel@tonic-gate *fwd_p = TNF_REF32_MAKE_RECLAIMABLE( 304*7c478bd9Sstevel@tonic-gate ((sched->record_gen - block->generation) << shift) + 305*7c478bd9Sstevel@tonic-gate (sched_record_p - (tnf_record_p)fwd_p)); 306*7c478bd9Sstevel@tonic-gate /* LINTED - ptr subtraction */ 307*7c478bd9Sstevel@tonic-gate sched_offset = PTR_DIFF(fwd_p, buffer); 308*7c478bd9Sstevel@tonic-gate ASSERT(TAGARG_CHECK(sched_offset)); 309*7c478bd9Sstevel@tonic-gate } else { 310*7c478bd9Sstevel@tonic-gate /* Allocation failed (tracing may have been stopped) */ 311*7c478bd9Sstevel@tonic-gate sched_offset = 0; 312*7c478bd9Sstevel@tonic-gate *fwd_p = TNF_NULL; 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate goto good_ret; 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate null_ret: 317*7c478bd9Sstevel@tonic-gate /* 318*7c478bd9Sstevel@tonic-gate * reset re-entrancy protector, because tnf_trace_end() will 319*7c478bd9Sstevel@tonic-gate * not be called 320*7c478bd9Sstevel@tonic-gate */ 321*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 322*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_alloc: null return\n"); 323*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 324*7c478bd9Sstevel@tonic-gate #endif 325*7c478bd9Sstevel@tonic-gate ops->busy = 0; 326*7c478bd9Sstevel@tonic-gate return (NULL); 327*7c478bd9Sstevel@tonic-gate } 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate /* 330*7c478bd9Sstevel@tonic-gate * tnf_trace_end 331*7c478bd9Sstevel@tonic-gate * the last (usually only) function in the list of probe functions 332*7c478bd9Sstevel@tonic-gate */ 333*7c478bd9Sstevel@tonic-gate void 334*7c478bd9Sstevel@tonic-gate tnf_trace_end(tnf_probe_setup_t *set_p) 335*7c478bd9Sstevel@tonic-gate { 336*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 337*7c478bd9Sstevel@tonic-gate char tmp_buf[512]; 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_end: \n"); 340*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 341*7c478bd9Sstevel@tonic-gate #endif 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate (set_p->probe_p->commit_func)(set_p); 344*7c478bd9Sstevel@tonic-gate set_p->tpd_p->busy = 0; 345*7c478bd9Sstevel@tonic-gate } 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate /* 348*7c478bd9Sstevel@tonic-gate * tnf_trace_commit 349*7c478bd9Sstevel@tonic-gate * a probe commit function that really commits trace data 350*7c478bd9Sstevel@tonic-gate */ 351*7c478bd9Sstevel@tonic-gate void 352*7c478bd9Sstevel@tonic-gate tnf_trace_commit(tnf_probe_setup_t *set_p) 353*7c478bd9Sstevel@tonic-gate { 354*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 355*7c478bd9Sstevel@tonic-gate char tmp_buf[512]; 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_commit: \n\n"); 358*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 359*7c478bd9Sstevel@tonic-gate #endif 360*7c478bd9Sstevel@tonic-gate (void) set_p->tpd_p->commit(&(set_p->tpd_p->wcb)); 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate return; 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate /* 367*7c478bd9Sstevel@tonic-gate * tnf_trace_rollback 368*7c478bd9Sstevel@tonic-gate * a probe commit function that unrolls trace data 369*7c478bd9Sstevel@tonic-gate */ 370*7c478bd9Sstevel@tonic-gate void 371*7c478bd9Sstevel@tonic-gate tnf_trace_rollback(tnf_probe_setup_t *set_p) 372*7c478bd9Sstevel@tonic-gate { 373*7c478bd9Sstevel@tonic-gate #ifdef VERYVERBOSE 374*7c478bd9Sstevel@tonic-gate char tmp_buf[512]; 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_trace_rollback: \n\n"); 377*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 378*7c478bd9Sstevel@tonic-gate #endif 379*7c478bd9Sstevel@tonic-gate (void) set_p->tpd_p->rollback(&(set_p->tpd_p->wcb)); 380*7c478bd9Sstevel@tonic-gate 381*7c478bd9Sstevel@tonic-gate return; 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate /* 386*7c478bd9Sstevel@tonic-gate * tnf_allocate 387*7c478bd9Sstevel@tonic-gate * exported interface for allocating trace memory 388*7c478bd9Sstevel@tonic-gate */ 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate void * 391*7c478bd9Sstevel@tonic-gate tnf_allocate(tnf_ops_t *ops, size_t size) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate void *retval; 394*7c478bd9Sstevel@tonic-gate char tmp_buf[512]; 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 397*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_allocate\n"); 398*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 399*7c478bd9Sstevel@tonic-gate #endif 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate retval = ops->alloc(&(ops->wcb), size, ops->mode); 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 404*7c478bd9Sstevel@tonic-gate sprintf(tmp_buf, "tnf_allocate, retval=%p\n", retval); 405*7c478bd9Sstevel@tonic-gate (void) write(2, tmp_buf, strlen(tmp_buf)); 406*7c478bd9Sstevel@tonic-gate #endif 407*7c478bd9Sstevel@tonic-gate 408*7c478bd9Sstevel@tonic-gate return (retval); 409*7c478bd9Sstevel@tonic-gate } 410