17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate *	Copyright (c) 1994, by Sun Microsytems, Inc.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate/*
297c478bdstevel@tonic-gate * Includes
307c478bdstevel@tonic-gate */
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#ifndef DEBUG
337c478bdstevel@tonic-gate#define	NDEBUG	1
347c478bdstevel@tonic-gate#endif
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#include <assert.h>
377c478bdstevel@tonic-gate#include <limits.h>
387c478bdstevel@tonic-gate#include <values.h>
397c478bdstevel@tonic-gate#include <stdio.h>
407c478bdstevel@tonic-gate#include <string.h>
417c478bdstevel@tonic-gate#include <unistd.h>
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gate#include "tnf_trace.h"
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gate/*
467c478bdstevel@tonic-gate * Defines
477c478bdstevel@tonic-gate */
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate#define	ASSERT(expr)	assert(expr)
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate#define	ENCODED_TAG(tag, tagarg) 		\
527c478bdstevel@tonic-gate	(((tag) | ((tagarg) & 0xfffc)) | TNF_REF32_T_PAIR)
537c478bdstevel@tonic-gate
547c478bdstevel@tonic-gate/*
557c478bdstevel@tonic-gate * CAUTION: halfword_accessible assumes that the pointer is to a reclaimable
567c478bdstevel@tonic-gate *		block - i.e. negative offsets have a 0 in high bit
577c478bdstevel@tonic-gate */
587c478bdstevel@tonic-gate#define	HALFWORD_ACCESSIBLE(x) 			\
597c478bdstevel@tonic-gate	((((x) & 0xffff8000) == 0) || (((x) & 0xffff8000) == 0x7fff8000))
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate/*
627c478bdstevel@tonic-gate * Check that x can be encoded in tagarg slot
637c478bdstevel@tonic-gate * Same as above, but operates on ints (no space bit)
647c478bdstevel@tonic-gate */
657c478bdstevel@tonic-gate#define	TAGARG_CHECK(x)				\
667c478bdstevel@tonic-gate	(((x) < 32767) && ((x) > -32768))
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate/*
697c478bdstevel@tonic-gate * Check that hi 32 bits of hrtime are zero
707c478bdstevel@tonic-gate */
717c478bdstevel@tonic-gate#define	TIME_CHECK(x)				\
727c478bdstevel@tonic-gate	(((x) >> 32) == 0)
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate/*
757c478bdstevel@tonic-gate * CAUTION: Use the following macro only when doing a self relative pointer
767c478bdstevel@tonic-gate *		to a target in the same block
777c478bdstevel@tonic-gate */
787c478bdstevel@tonic-gate#define	PTR_DIFF(item, ref)			\
797c478bdstevel@tonic-gate	((tnf_ref32_t)((tnf_record_p)(item) - (tnf_record_p)(ref)))
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate/*
827c478bdstevel@tonic-gate * Typedefs
837c478bdstevel@tonic-gate */
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gatetypedef struct {
867c478bdstevel@tonic-gate	tnf_probe_event_t		probe_event;
877c478bdstevel@tonic-gate	tnf_time_delta_t		time_delta;
887c478bdstevel@tonic-gate} probe_event_prototype_t;
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate/*
917c478bdstevel@tonic-gate * tnf_trace_alloc
927c478bdstevel@tonic-gate * 	the probe allocation function
937c478bdstevel@tonic-gate */
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate#define	IS_NEWBLOCK(blockArray, dataBuffer) \
967c478bdstevel@tonic-gate	    (((caddr_t)&blockArray[1]) == (caddr_t)dataBuffer)
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gatevoid *
997c478bdstevel@tonic-gatetnf_trace_alloc(tnf_ops_t *ops, tnf_probe_control_t *probe_p,
1007c478bdstevel@tonic-gate    tnf_probe_setup_t *set_p)
1017c478bdstevel@tonic-gate{
1027c478bdstevel@tonic-gate	TNFW_B_WCB		*wcb;
1037c478bdstevel@tonic-gate	volatile char 		*file_start;
1047c478bdstevel@tonic-gate	uintptr_t		probe_index;
1057c478bdstevel@tonic-gate	tnf_record_p		sched_record_p;
1067c478bdstevel@tonic-gate	tnf_reference_t		sched_offset, tag_disp;
1077c478bdstevel@tonic-gate	tnf_block_header_t	*block;
1087c478bdstevel@tonic-gate	tnf_uint32_t		shift;
1097c478bdstevel@tonic-gate	probe_event_prototype_t *buffer;
1107c478bdstevel@tonic-gate	hrtime_t 		curr_time, time_diff;
1117c478bdstevel@tonic-gate	tnf_schedule_t		*sched;
1127c478bdstevel@tonic-gate	tnf_ref32_t		*fwd_p;
1137c478bdstevel@tonic-gate	ulong_t			size, asize;
1147c478bdstevel@tonic-gate#if defined(DEBUG) || defined(VERYVERBOSE)
1157c478bdstevel@tonic-gate	char tmp_buf[512];
1167c478bdstevel@tonic-gate#endif
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate	ASSERT(ops != NULL);
1197c478bdstevel@tonic-gate
1207c478bdstevel@tonic-gate	/* check if already in a probe */
1217c478bdstevel@tonic-gate	if (ops->busy)
1227c478bdstevel@tonic-gate		return (NULL);
1237c478bdstevel@tonic-gate	ops->busy = 1;
1247c478bdstevel@tonic-gate
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gate#ifdef VERYVERBOSE
1277c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc: begin\n");
1287c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
1297c478bdstevel@tonic-gate#endif
1307c478bdstevel@tonic-gate
1317c478bdstevel@tonic-gate	/*
1327c478bdstevel@tonic-gate	 * CAUTION: Ordering of function calls in this file is critical because
1337c478bdstevel@tonic-gate	 * we call TNFW_B_GIVEBACK. Between the time we allocate space for the
1347c478bdstevel@tonic-gate	 * event and call TNFW_B_GIVEBACK there can be no other allocations!!
1357c478bdstevel@tonic-gate	 */
1367c478bdstevel@tonic-gate
1377c478bdstevel@tonic-gate	/*
1387c478bdstevel@tonic-gate	 * Write probe tag if needed
1397c478bdstevel@tonic-gate	 */
1407c478bdstevel@tonic-gate	probe_index = probe_p->index;
1417c478bdstevel@tonic-gate#ifdef VERYVERBOSE
1427c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc: (1) probe_index=%p\n", probe_index);
1437c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
1447c478bdstevel@tonic-gate#endif
1457c478bdstevel@tonic-gate	if (probe_index == 0) {
1467c478bdstevel@tonic-gate	    if ((probe_index = tnf_probe_tag(ops, probe_p)) == 0) {
1477c478bdstevel@tonic-gate#ifdef VERYVERBOSE
1487c478bdstevel@tonic-gate	    sprintf(tmp_buf, "tnf_trace_alloc: (2) probe_index=%p\n",
1497c478bdstevel@tonic-gate		    probe_index);
1507c478bdstevel@tonic-gate	    (void) write(2, tmp_buf, strlen(tmp_buf));
1517c478bdstevel@tonic-gate	    sprintf(tmp_buf, "tnf_trace_alloc: goto null_ret\n");
1527c478bdstevel@tonic-gate	    (void) write(2, tmp_buf, strlen(tmp_buf));
1537c478bdstevel@tonic-gate	    fflush(stderr);
1547c478bdstevel@tonic-gate	    sleep(2);
1557c478bdstevel@tonic-gate#endif
1567c478bdstevel@tonic-gate	    goto null_ret;
1577c478bdstevel@tonic-gate	    }
1587c478bdstevel@tonic-gate#ifdef VERYVERBOSE
1597c478bdstevel@tonic-gate	    sprintf(tmp_buf, "tnf_trace_alloc: (3) probe_index=%p\n",
1607c478bdstevel@tonic-gate		probe_index);
1617c478bdstevel@tonic-gate	    (void) write(2, tmp_buf, strlen(tmp_buf));
1627c478bdstevel@tonic-gate	    fflush(stderr);
1637c478bdstevel@tonic-gate#endif
1647c478bdstevel@tonic-gate	}
1657c478bdstevel@tonic-gate	/*
1667c478bdstevel@tonic-gate	 * Determine how much memory is required
1677c478bdstevel@tonic-gate	 */
1687c478bdstevel@tonic-gate	size = probe_p->tnf_event_size;
1697c478bdstevel@tonic-gate	asize = size + sizeof (tnf_ref32_t);	/* one fwd ptr */
1707c478bdstevel@tonic-gate
1717c478bdstevel@tonic-gate	if (PROBE_IS_FILE_PTR(probe_index)) {
1727c478bdstevel@tonic-gate		/* common case - probe_index is a file ptr */
1737c478bdstevel@tonic-gate		tag_disp = probe_index & PROBE_INDEX_LOW_MASK;
1747c478bdstevel@tonic-gate	} else {
1757c478bdstevel@tonic-gate		/* rare case -- get an extra fwd ptr */
1767c478bdstevel@tonic-gate		asize += sizeof (tnf_ref32_t);
1777c478bdstevel@tonic-gate	}
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate	/*
1807c478bdstevel@tonic-gate	 * Allocate memory
1817c478bdstevel@tonic-gate	 */
1827c478bdstevel@tonic-gate	wcb = &(ops->wcb);
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
1857c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc, wcb=%p\n", wcb);
1867c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
1877c478bdstevel@tonic-gate#endif
1887c478bdstevel@tonic-gate
1897c478bdstevel@tonic-gate	buffer = ops->alloc(wcb, asize, ops->mode);
1907c478bdstevel@tonic-gate
1917c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
1927c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc, buffer=%p\n", buffer);
1937c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
1947c478bdstevel@tonic-gate#endif
1957c478bdstevel@tonic-gate	if (buffer == NULL)
1967c478bdstevel@tonic-gate		goto null_ret;
1977c478bdstevel@tonic-gate
1987c478bdstevel@tonic-gate	/* LINTED pointer cast may result in improper alignment */
1997c478bdstevel@tonic-gate	fwd_p = (tnf_ref32_t *) ((char *)(buffer) + size);
2007c478bdstevel@tonic-gate
2017c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
2027c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc, fwd_pr=%p\n", fwd_p);
2037c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
2047c478bdstevel@tonic-gate#endif
2057c478bdstevel@tonic-gate
2067c478bdstevel@tonic-gate	/* set file_start after calling alloc because it allocs the file */
2077c478bdstevel@tonic-gate	file_start = _tnfw_b_control->tnf_buffer;
2087c478bdstevel@tonic-gate
2097c478bdstevel@tonic-gate	/* Check if the probe tag needs more work */
2107c478bdstevel@tonic-gate	if (!PROBE_IS_FILE_PTR(probe_index)) {
2117c478bdstevel@tonic-gate		/* LINTED use up first fwd ptr */
2127c478bdstevel@tonic-gate		*fwd_p = TNF_REF32_MAKE_PERMANENT(
2137c478bdstevel@tonic-gate		/* LINTED ptr subtraction */
2147c478bdstevel@tonic-gate			(tnf_record_p)probe_index - (tnf_record_p) file_start);
2157c478bdstevel@tonic-gate		/* LINTED ptr subtraction */
2167c478bdstevel@tonic-gate		tag_disp = PTR_DIFF(fwd_p, buffer);
2177c478bdstevel@tonic-gate		ASSERT(TAGARG_CHECK(tag_disp));
2187c478bdstevel@tonic-gate		tag_disp |= TNF_TAG16_T_REL;
2197c478bdstevel@tonic-gate		tag_disp = tag_disp << TNF_REF32_TAG16_SHIFT;
2207c478bdstevel@tonic-gate		fwd_p++;
2217c478bdstevel@tonic-gate	}
2227c478bdstevel@tonic-gate
2237c478bdstevel@tonic-gate	/*
2247c478bdstevel@tonic-gate	 * Get timestamp
2257c478bdstevel@tonic-gate	 */
2267c478bdstevel@tonic-gate	curr_time = gethrtime();
2277c478bdstevel@tonic-gate
2287c478bdstevel@tonic-gate	/*
2297c478bdstevel@tonic-gate	 * initialize and write schedule record if needed
2307c478bdstevel@tonic-gate	 * watch out for sched->record_p - it has to be checked after alloc is
2317c478bdstevel@tonic-gate	 * called for the event, because it could be side effected by alloc
2327c478bdstevel@tonic-gate	 * if a fork happened.  Pre-requisite to our algorithm - if a fork
2337c478bdstevel@tonic-gate	 * happens all other threads have to be quiescent i.e. not in a probe.
2347c478bdstevel@tonic-gate	 */
2357c478bdstevel@tonic-gate	sched = &(ops->schedule);
2367c478bdstevel@tonic-gate
2377c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
2387c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc, sched=%p\n", sched);
2397c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
2407c478bdstevel@tonic-gate#endif
2417c478bdstevel@tonic-gate
2427c478bdstevel@tonic-gate	/* LINTED pointer cast */
2437c478bdstevel@tonic-gate	shift = ((tnf_buf_file_header_t *)file_start)->com.file_log_size;
2447c478bdstevel@tonic-gate	block = (tnf_block_header_t *)((ulong_t)buffer & TNF_BLOCK_MASK);
2457c478bdstevel@tonic-gate
2467c478bdstevel@tonic-gate	if ((sched_record_p = sched->record_p) == NULL ||
2477c478bdstevel@tonic-gate	    IS_NEWBLOCK(block, buffer)) {
2487c478bdstevel@tonic-gate		/* No record written yet */
2497c478bdstevel@tonic-gate		goto new_schedule;
2507c478bdstevel@tonic-gate	}
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate	/*
2537c478bdstevel@tonic-gate	 * Note: Don't bother about space bit here, because we'll
2547c478bdstevel@tonic-gate	 * only use bits 15:2 anyway
2557c478bdstevel@tonic-gate	 */
2567c478bdstevel@tonic-gate	sched_offset = ((sched->record_gen - block->generation) << shift) +
2577c478bdstevel@tonic-gate		/* LINTED - ptr subtraction */
2587c478bdstevel@tonic-gate		(uint_t) (sched_record_p - (caddr_t)buffer);
2597c478bdstevel@tonic-gate
2607c478bdstevel@tonic-gate	if (!TAGARG_CHECK(sched_offset))
2617c478bdstevel@tonic-gate		/* Record too far away to reference */
2627c478bdstevel@tonic-gate		goto new_schedule;
2637c478bdstevel@tonic-gate
2647c478bdstevel@tonic-gate	time_diff = curr_time - sched->time_base;
2657c478bdstevel@tonic-gate	if (!TIME_CHECK(time_diff))
2667c478bdstevel@tonic-gate		/* Time delta can't fit in 32 bits */
2677c478bdstevel@tonic-gate		goto new_schedule;
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate	/*
2707c478bdstevel@tonic-gate	 * Can reuse existing schedule record
2717c478bdstevel@tonic-gate	 * Since we did not allocate any more space, can giveback
2727c478bdstevel@tonic-gate	 */
2737c478bdstevel@tonic-gate	/* LINTED - GIVEBACK returns a pointer subtraction */
2747c478bdstevel@tonic-gate	TNFW_B_GIVEBACK(wcb, fwd_p);
2757c478bdstevel@tonic-gate
2767c478bdstevel@tonic-gategood_ret:
2777c478bdstevel@tonic-gate	/*
2787c478bdstevel@tonic-gate	 * Store return params and two common event members, return buffer
2797c478bdstevel@tonic-gate	 */
2807c478bdstevel@tonic-gate	set_p->tpd_p = ops;
2817c478bdstevel@tonic-gate	set_p->buffer_p = buffer;
2827c478bdstevel@tonic-gate	set_p->probe_p = probe_p;
2837c478bdstevel@tonic-gate	buffer->probe_event = ENCODED_TAG(tag_disp, sched_offset);
2847c478bdstevel@tonic-gate	/* LINTED - TIME_CHECK already passed, see above */
2857c478bdstevel@tonic-gate	buffer->time_delta = tnf_time_delta(ops, (unsigned long)time_diff,
2867c478bdstevel@tonic-gate	    &buffer->probe_time_delta);
2877c478bdstevel@tonic-gate	return (buffer);
2887c478bdstevel@tonic-gate
2897c478bdstevel@tonic-gatenew_schedule:
2907c478bdstevel@tonic-gate	/*
2917c478bdstevel@tonic-gate	 * Write a new schedule record for this thread
2927c478bdstevel@tonic-gate	 */
2937c478bdstevel@tonic-gate#ifdef VERYVERBOSE
2947c478bdstevel@tonic-gate	sprintf(tmp_buf, "	tnf_trace_alloc: initializing "
2957c478bdstevel@tonic-gate				"new schedule record\n");
2967c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
2977c478bdstevel@tonic-gate#endif
2987c478bdstevel@tonic-gate	_tnf_sched_init(sched, curr_time);
2997c478bdstevel@tonic-gate	time_diff = 0;
3007c478bdstevel@tonic-gate	if ((sched_record_p = tnf_schedule_write(ops, sched)) != NULL) {
3017c478bdstevel@tonic-gate		/* use one of the extra alloced words for the forwarding ptr */
3027c478bdstevel@tonic-gate		/* LINTED - ptr subtraction */
3037c478bdstevel@tonic-gate		*fwd_p = TNF_REF32_MAKE_RECLAIMABLE(
3047c478bdstevel@tonic-gate			((sched->record_gen - block->generation) << shift) +
3057c478bdstevel@tonic-gate			(sched_record_p - (tnf_record_p)fwd_p));
3067c478bdstevel@tonic-gate		/* LINTED - ptr subtraction */
3077c478bdstevel@tonic-gate		sched_offset = PTR_DIFF(fwd_p, buffer);
3087c478bdstevel@tonic-gate		ASSERT(TAGARG_CHECK(sched_offset));
3097c478bdstevel@tonic-gate	} else {
3107c478bdstevel@tonic-gate		/* Allocation failed (tracing may have been stopped) */
3117c478bdstevel@tonic-gate		sched_offset = 0;
3127c478bdstevel@tonic-gate		*fwd_p = TNF_NULL;
3137c478bdstevel@tonic-gate	}
3147c478bdstevel@tonic-gate	goto good_ret;
3157c478bdstevel@tonic-gate
3167c478bdstevel@tonic-gatenull_ret:
3177c478bdstevel@tonic-gate	/*
3187c478bdstevel@tonic-gate	 * reset re-entrancy protector, because tnf_trace_end() will
3197c478bdstevel@tonic-gate	 * not be called
3207c478bdstevel@tonic-gate	 */
3217c478bdstevel@tonic-gate#ifdef VERYVERBOSE
3227c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_alloc: null return\n");
3237c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
3247c478bdstevel@tonic-gate#endif
3257c478bdstevel@tonic-gate	ops->busy = 0;
3267c478bdstevel@tonic-gate	return (NULL);
3277c478bdstevel@tonic-gate}
3287c478bdstevel@tonic-gate
3297c478bdstevel@tonic-gate/*
3307c478bdstevel@tonic-gate * tnf_trace_end
3317c478bdstevel@tonic-gate *	the last (usually only) function in the list of probe functions
3327c478bdstevel@tonic-gate */
3337c478bdstevel@tonic-gatevoid
3347c478bdstevel@tonic-gatetnf_trace_end(tnf_probe_setup_t *set_p)
3357c478bdstevel@tonic-gate{
3367c478bdstevel@tonic-gate#ifdef VERYVERBOSE
3377c478bdstevel@tonic-gate	char tmp_buf[512];
3387c478bdstevel@tonic-gate
3397c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_end: \n");
3407c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
3417c478bdstevel@tonic-gate#endif
3427c478bdstevel@tonic-gate
3437c478bdstevel@tonic-gate	(set_p->probe_p->commit_func)(set_p);
3447c478bdstevel@tonic-gate	set_p->tpd_p->busy = 0;
3457c478bdstevel@tonic-gate}
3467c478bdstevel@tonic-gate
3477c478bdstevel@tonic-gate/*
3487c478bdstevel@tonic-gate * tnf_trace_commit
3497c478bdstevel@tonic-gate *	a probe commit function that really commits trace data
3507c478bdstevel@tonic-gate */
3517c478bdstevel@tonic-gatevoid
3527c478bdstevel@tonic-gatetnf_trace_commit(tnf_probe_setup_t *set_p)
3537c478bdstevel@tonic-gate{
3547c478bdstevel@tonic-gate#ifdef VERYVERBOSE
3557c478bdstevel@tonic-gate	char tmp_buf[512];
3567c478bdstevel@tonic-gate
3577c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_commit: \n\n");
3587c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
3597c478bdstevel@tonic-gate#endif
3607c478bdstevel@tonic-gate	(void) set_p->tpd_p->commit(&(set_p->tpd_p->wcb));
3617c478bdstevel@tonic-gate
3627c478bdstevel@tonic-gate	return;
3637c478bdstevel@tonic-gate
3647c478bdstevel@tonic-gate}
3657c478bdstevel@tonic-gate
3667c478bdstevel@tonic-gate/*
3677c478bdstevel@tonic-gate * tnf_trace_rollback
3687c478bdstevel@tonic-gate *	a probe commit function that unrolls trace data
3697c478bdstevel@tonic-gate */
3707c478bdstevel@tonic-gatevoid
3717c478bdstevel@tonic-gatetnf_trace_rollback(tnf_probe_setup_t *set_p)
3727c478bdstevel@tonic-gate{
3737c478bdstevel@tonic-gate#ifdef VERYVERBOSE
3747c478bdstevel@tonic-gate	char tmp_buf[512];
3757c478bdstevel@tonic-gate
3767c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_trace_rollback: \n\n");
3777c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
3787c478bdstevel@tonic-gate#endif
3797c478bdstevel@tonic-gate	(void) set_p->tpd_p->rollback(&(set_p->tpd_p->wcb));
3807c478bdstevel@tonic-gate
3817c478bdstevel@tonic-gate	return;
3827c478bdstevel@tonic-gate
3837c478bdstevel@tonic-gate}
3847c478bdstevel@tonic-gate
3857c478bdstevel@tonic-gate/*
3867c478bdstevel@tonic-gate * tnf_allocate
3877c478bdstevel@tonic-gate *	exported interface for allocating trace memory
3887c478bdstevel@tonic-gate */
3897c478bdstevel@tonic-gate
3907c478bdstevel@tonic-gatevoid *
3917c478bdstevel@tonic-gatetnf_allocate(tnf_ops_t *ops, size_t size)
3927c478bdstevel@tonic-gate{
3937c478bdstevel@tonic-gate	void *retval;
3947c478bdstevel@tonic-gate	char tmp_buf[512];
3957c478bdstevel@tonic-gate
3967c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
3977c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_allocate\n");
3987c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
3997c478bdstevel@tonic-gate#endif
4007c478bdstevel@tonic-gate
4017c478bdstevel@tonic-gate	retval = ops->alloc(&(ops->wcb), size, ops->mode);
4027c478bdstevel@tonic-gate
4037c478bdstevel@tonic-gate#ifdef _TNF_VERBOSE
4047c478bdstevel@tonic-gate	sprintf(tmp_buf, "tnf_allocate, retval=%p\n", retval);
4057c478bdstevel@tonic-gate	(void) write(2, tmp_buf, strlen(tmp_buf));
4067c478bdstevel@tonic-gate#endif
4077c478bdstevel@tonic-gate
4087c478bdstevel@tonic-gate	return (retval);
4097c478bdstevel@tonic-gate}
410