Home | History | Annotate | Download | only in sys
      1     0  stevel /*
      2     0  stevel  * CDDL HEADER START
      3     0  stevel  *
      4     0  stevel  * The contents of this file are subject to the terms of the
      5  1710     ahl  * Common Development and Distribution License (the "License").
      6  1710     ahl  * You may not use this file except in compliance with the License.
      7     0  stevel  *
      8     0  stevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9     0  stevel  * or http://www.opensolaris.org/os/licensing.
     10     0  stevel  * See the License for the specific language governing permissions
     11     0  stevel  * and limitations under the License.
     12     0  stevel  *
     13     0  stevel  * When distributing Covered Code, include this CDDL HEADER in each
     14     0  stevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15     0  stevel  * If applicable, add the following below this CDDL HEADER, with the
     16     0  stevel  * fields enclosed by brackets "[]" replaced with your own identifying
     17     0  stevel  * information: Portions Copyright [yyyy] [name of copyright owner]
     18     0  stevel  *
     19     0  stevel  * CDDL HEADER END
     20     0  stevel  */
     21  1710     ahl 
     22     0  stevel /*
     23  6390     ahl  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     24     0  stevel  * Use is subject to license terms.
     25     0  stevel  */
     26     0  stevel 
     27     0  stevel #ifndef	_FASTTRAP_IMPL_H
     28     0  stevel #define	_FASTTRAP_IMPL_H
     29     0  stevel 
     30     0  stevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
     31     0  stevel 
     32     0  stevel #include <sys/types.h>
     33     0  stevel #include <sys/dtrace.h>
     34     0  stevel #include <sys/proc.h>
     35     0  stevel #include <sys/fasttrap.h>
     36     0  stevel #include <sys/fasttrap_isa.h>
     37     0  stevel 
     38     0  stevel #ifdef	__cplusplus
     39     0  stevel extern "C" {
     40     0  stevel #endif
     41     0  stevel 
     42     0  stevel /*
     43   532     ahl  * Fasttrap Providers, Probes and Tracepoints
     44   532     ahl  *
     45   532     ahl  * Each Solaris process can have multiple providers -- the pid provider as
     46   532     ahl  * well as any number of user-level statically defined tracing (USDT)
     47   532     ahl  * providers. Those providers are each represented by a fasttrap_provider_t.
     48   532     ahl  * All providers for a given process have a pointer to a shared
     49   532     ahl  * fasttrap_proc_t. The fasttrap_proc_t has two states: active or defunct.
     50  6390     ahl  * When the count of active providers goes to zero it becomes defunct; a
     51  6390     ahl  * provider drops its active count when it is removed individually or as part
     52  6390     ahl  * of a mass removal when a process exits or performs an exec.
     53   532     ahl  *
     54   532     ahl  * Each probe is represented by a fasttrap_probe_t which has a pointer to
     55   532     ahl  * its associated provider as well as a list of fasttrap_id_tp_t structures
     56   532     ahl  * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t.
     57   532     ahl  * A fasttrap_tracepoint_t represents the actual point of instrumentation
     58   532     ahl  * and it contains two lists of fasttrap_id_t structures (to be fired pre-
     59   532     ahl  * and post-instruction emulation) that identify the probes attached to the
     60   532     ahl  * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the
     61  6390     ahl  * process they trace which is used when looking up a tracepoint both when a
     62  6390     ahl  * probe fires and when enabling and disabling probes.
     63   532     ahl  *
     64   532     ahl  * It's important to note that probes are preallocated with the necessary
     65   532     ahl  * number of tracepoints, but that tracepoints can be shared by probes and
     66   532     ahl  * swapped between probes. If a probe's preallocated tracepoint is enabled
     67   532     ahl  * (and, therefore, the associated probe is enabled), and that probe is
     68   532     ahl  * then disabled, ownership of that tracepoint may be exchanged for an
     69   532     ahl  * unused tracepoint belonging to another probe that was attached to the
     70   532     ahl  * enabled tracepoint.
     71     0  stevel  */
     72     0  stevel 
     73   532     ahl typedef struct fasttrap_proc {
     74   532     ahl 	pid_t ftpc_pid;				/* process ID for this proc */
     75  4821     ahl 	uint64_t ftpc_acount;			/* count of active providers */
     76  6390     ahl 	uint64_t ftpc_rcount;			/* count of extant providers */
     77  6390     ahl 	kmutex_t ftpc_mtx;			/* lock on all but acount */
     78   532     ahl 	struct fasttrap_proc *ftpc_next;	/* next proc in hash chain */
     79   532     ahl } fasttrap_proc_t;
     80   532     ahl 
     81   532     ahl typedef struct fasttrap_provider {
     82   532     ahl 	pid_t ftp_pid;				/* process ID for this prov */
     83   532     ahl 	char ftp_name[DTRACE_PROVNAMELEN];	/* prov name (w/o the pid) */
     84     0  stevel 	dtrace_provider_id_t ftp_provid;	/* DTrace provider handle */
     85     0  stevel 	uint_t ftp_marked;			/* mark for possible removal */
     86   532     ahl 	uint_t ftp_retired;			/* mark when retired */
     87     0  stevel 	kmutex_t ftp_mtx;			/* provider lock */
     88  2179     ahl 	kmutex_t ftp_cmtx;			/* lock on creating probes */
     89     0  stevel 	uint64_t ftp_rcount;			/* enabled probes ref count */
     90     0  stevel 	uint64_t ftp_ccount;			/* consumers creating probes */
     91  1880     ahl 	uint64_t ftp_mcount;			/* meta provider count */
     92   532     ahl 	fasttrap_proc_t *ftp_proc;		/* shared proc for all provs */
     93   532     ahl 	struct fasttrap_provider *ftp_next;	/* next prov in hash chain */
     94   532     ahl } fasttrap_provider_t;
     95     0  stevel 
     96     0  stevel typedef struct fasttrap_id fasttrap_id_t;
     97     0  stevel typedef struct fasttrap_probe fasttrap_probe_t;
     98     0  stevel typedef struct fasttrap_tracepoint fasttrap_tracepoint_t;
     99     0  stevel 
    100     0  stevel struct fasttrap_id {
    101     0  stevel 	fasttrap_probe_t *fti_probe;		/* referrring probe */
    102     0  stevel 	fasttrap_id_t *fti_next;		/* enabled probe list on tp */
    103  1710     ahl 	fasttrap_probe_type_t fti_ptype;	/* probe type */
    104     0  stevel };
    105     0  stevel 
    106     0  stevel typedef struct fasttrap_id_tp {
    107     0  stevel 	fasttrap_id_t fit_id;
    108     0  stevel 	fasttrap_tracepoint_t *fit_tp;
    109     0  stevel } fasttrap_id_tp_t;
    110     0  stevel 
    111     0  stevel struct fasttrap_probe {
    112     0  stevel 	dtrace_id_t ftp_id;			/* DTrace probe identifier */
    113     0  stevel 	pid_t ftp_pid;				/* pid for this probe */
    114     0  stevel 	fasttrap_provider_t *ftp_prov;		/* this probe's provider */
    115     0  stevel 	uintptr_t ftp_faddr;			/* associated function's addr */
    116     0  stevel 	size_t ftp_fsize;			/* associated function's size */
    117     0  stevel 	uint64_t ftp_gen;			/* modification generation */
    118     0  stevel 	uint64_t ftp_ntps;			/* number of tracepoints */
    119     0  stevel 	uint8_t *ftp_argmap;			/* native to translated args */
    120     0  stevel 	uint8_t ftp_nargs;			/* translated argument count */
    121  1710     ahl 	uint8_t ftp_enabled;			/* is this probe enabled */
    122     0  stevel 	char *ftp_xtypes;			/* translated types index */
    123     0  stevel 	char *ftp_ntypes;			/* native types index */
    124     0  stevel 	fasttrap_id_tp_t ftp_tps[1];		/* flexible array */
    125     0  stevel };
    126     0  stevel 
    127     0  stevel #define	FASTTRAP_ID_INDEX(id)	\
    128     0  stevel ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \
    129     0  stevel &(id)->fti_probe->ftp_tps[0])
    130     0  stevel 
    131     0  stevel struct fasttrap_tracepoint {
    132  1710     ahl 	fasttrap_proc_t *ftt_proc;		/* associated process struct */
    133  1710     ahl 	uintptr_t ftt_pc;			/* address of tracepoint */
    134  1710     ahl 	pid_t ftt_pid;				/* pid of tracepoint */
    135  1710     ahl 	fasttrap_machtp_t ftt_mtp;		/* ISA-specific portion */
    136  1710     ahl 	fasttrap_id_t *ftt_ids;			/* NULL-terminated list */
    137  1710     ahl 	fasttrap_id_t *ftt_retids;		/* NULL-terminated list */
    138  1710     ahl 	fasttrap_tracepoint_t *ftt_next;	/* link in global hash */
    139     0  stevel };
    140     0  stevel 
    141     0  stevel typedef struct fasttrap_bucket {
    142  1710     ahl 	kmutex_t ftb_mtx;			/* bucket lock */
    143  1710     ahl 	void *ftb_data;				/* data payload */
    144     0  stevel 
    145  1710     ahl 	uint8_t ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)];
    146     0  stevel } fasttrap_bucket_t;
    147     0  stevel 
    148     0  stevel typedef struct fasttrap_hash {
    149  1710     ahl 	ulong_t fth_nent;			/* power-of-2 num. of entries */
    150  1710     ahl 	ulong_t fth_mask;			/* fth_nent - 1 */
    151  1710     ahl 	fasttrap_bucket_t *fth_table;		/* array of buckets */
    152     0  stevel } fasttrap_hash_t;
    153     0  stevel 
    154     0  stevel /*
    155     0  stevel  * If at some future point these assembly functions become observable by
    156     0  stevel  * DTrace, then these defines should become separate functions so that the
    157     0  stevel  * fasttrap provider doesn't trigger probes during internal operations.
    158     0  stevel  */
    159     0  stevel #define	fasttrap_copyout	copyout
    160     0  stevel #define	fasttrap_fuword32	fuword32
    161     0  stevel #define	fasttrap_suword32	suword32
    162     0  stevel 
    163     0  stevel #define	fasttrap_fulword	fulword
    164     0  stevel #define	fasttrap_sulword	sulword
    165     0  stevel 
    166     0  stevel extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t);
    167     0  stevel 
    168     0  stevel extern dtrace_id_t 		fasttrap_probe_id;
    169     0  stevel extern fasttrap_hash_t		fasttrap_tpoints;
    170     0  stevel 
    171     0  stevel #define	FASTTRAP_TPOINTS_INDEX(pid, pc) \
    172     0  stevel 	(((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask)
    173     0  stevel 
    174     0  stevel /*
    175     0  stevel  * Must be implemented by fasttrap_isa.c
    176     0  stevel  */
    177  1710     ahl extern int fasttrap_tracepoint_init(proc_t *, fasttrap_tracepoint_t *,
    178  1710     ahl     uintptr_t, fasttrap_probe_type_t);
    179     0  stevel extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *);
    180     0  stevel extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *);
    181     0  stevel 
    182     0  stevel extern int fasttrap_pid_probe(struct regs *);
    183     0  stevel extern int fasttrap_return_probe(struct regs *);
    184     0  stevel 
    185  2179     ahl extern uint64_t fasttrap_pid_getarg(void *, dtrace_id_t, void *, int, int);
    186     0  stevel extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int);
    187     0  stevel 
    188     0  stevel #ifdef	__cplusplus
    189     0  stevel }
    190     0  stevel #endif
    191     0  stevel 
    192     0  stevel #endif	/* _FASTTRAP_IMPL_H */
    193