1/*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27/*	  All Rights Reserved  	*/
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <unistd.h>
32#include <sys/types.h>
33#include <libproc.h>
34#include "ramdata.h"
35#include "proto.h"
36#include "htbl.h"
37
38/*
39 * ramdata.c -- read/write data definitions are collected here.
40 * Default initialization of zero applies in all cases.
41 */
42
43thread_key_t private_key;	/* set by thr_keycreate() */
44char	*command;		/* name of command ("truss") */
45int	interrupt;		/* interrupt signal was received */
46int	sigusr1;		/* received SIGUSR1 (release process) */
47int	sfd;			/* shared tmp file descriptor */
48pid_t	created;		/* if process was created, its process id */
49uid_t	Euid;			/* truss's effective uid */
50uid_t	Egid;			/* truss's effective gid */
51uid_t	Ruid;			/* truss's real uid */
52uid_t	Rgid;			/* truss's real gid */
53prcred_t credentials;		/* traced process credentials */
54prpriv_t *privdata;		/* traced process privileges */
55int	istty;			/* TRUE iff output is a tty */
56time_t	starttime;		/* start time */
57
58int	Fflag;			/* option flags from getopt() */
59int	fflag;
60int	cflag;
61int	aflag;
62int	eflag;
63int	iflag;
64int	lflag;
65int	tflag;
66int	pflag;
67int	sflag;
68int	mflag;
69int	oflag;
70int	vflag;
71int	xflag;
72int	hflag;
73
74int	dflag;
75int	Dflag;
76int	Eflag;
77int	Tflag;
78int	Sflag;
79int	Mflag;
80
81sysset_t trace;			/* sys calls to trace */
82sysset_t traceeven;		/* sys calls to trace even if not reported */
83sysset_t verbose;		/* sys calls to be verbose about */
84sysset_t rawout;		/* sys calls to show in raw mode */
85sigset_t signals;		/* signals to trace */
86fltset_t faults;		/* faults to trace */
87fileset_t readfd;		/* read() file descriptors to dump */
88fileset_t writefd;		/* write() file descriptors to dump */
89
90mutex_t	truss_lock;		/* protects almost everything */
91cond_t	truss_cv;
92mutex_t count_lock;		/* lock protecting count struct Cp */
93
94htbl_t	*fcall_tbl;		/* ptr to hash tbl counting function calls */
95
96int	truss_nlwp;		/* number of truss lwps */
97int	truss_maxlwp;		/* number of entries in truss_lwpid */
98lwpid_t	*truss_lwpid;		/* array of truss lwpid's */
99
100struct counts *Cp;		/* for counting: malloc() or shared memory */
101struct global_psinfo *gps;	/* contains global process information */
102
103struct dynlib *Dynlib;		/* for tracing functions in shared libraries */
104struct dynpat *Dynpat;
105struct dynpat *Lastpat;
106struct bkpt **bpt_hashtable;	/* breakpoint hash table */
107uint_t	nthr_create;		/* number of thr_create() calls seen so far */
108struct callstack *callstack;	/* the callstack array */
109uint_t	nstack;			/* number of detected stacks */
110rd_agent_t *Rdb_agent;		/* run-time linker debug handle */
111td_thragent_t *Thr_agent;	/* thread debug handle */
112int	not_consist;		/* used while rebuilding breakpoint table */
113int	delete_library;		/* used while rebuilding breakpoint table */
114
115pid_t	ancestor;		/* top-level parent process id */
116int	descendent;		/* TRUE iff descendent of top level */
117int	is_vfork_child;		/* TRUE iff process is a vfork()ed child */
118
119int	ngrab;			/* number of pid's that were grabbed */
120
121struct ps_prochandle *Proc;	/* global reference to process */
122int	data_model;		/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
123
124long	pagesize;		/* bytes per page; should be per-process */
125
126int	exit_called;		/* _exit() syscall was seen */
127
128lwpid_t	primary_lwp;		/* representative lwp on process grab */
129
130sysset_t syshang;		/* sys calls to make process hang */
131sigset_t sighang;		/* signals to make process hang */
132fltset_t flthang;		/* faults to make process hang */
133
134sigset_t emptyset;		/* no signals, for thr_sigsetmask() */
135sigset_t fillset;		/* all signals, for thr_sigsetmask() */
136
137int	leave_hung;		/* if TRUE, leave the process hung */
138