17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56fced65dSraf * Common Development and Distribution License (the "License"). 66fced65dSraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2153e568b1Sraf 227c478bd9Sstevel@tonic-gate /* 23*134a1f4eSCasper H.S. Dik * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <stdlib.h> 317c478bd9Sstevel@tonic-gate #include <unistd.h> 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <libproc.h> 347c478bd9Sstevel@tonic-gate #include "ramdata.h" 357c478bd9Sstevel@tonic-gate #include "proto.h" 367c478bd9Sstevel@tonic-gate #include "htbl.h" 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * ramdata.c -- read/write data definitions are collected here. 407c478bd9Sstevel@tonic-gate * Default initialization of zero applies in all cases. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate thread_key_t private_key; /* set by thr_keycreate() */ 447c478bd9Sstevel@tonic-gate char *command; /* name of command ("truss") */ 457c478bd9Sstevel@tonic-gate int interrupt; /* interrupt signal was received */ 467c478bd9Sstevel@tonic-gate int sigusr1; /* received SIGUSR1 (release process) */ 477c478bd9Sstevel@tonic-gate int sfd; /* shared tmp file descriptor */ 487c478bd9Sstevel@tonic-gate pid_t created; /* if process was created, its process id */ 497c478bd9Sstevel@tonic-gate uid_t Euid; /* truss's effective uid */ 507c478bd9Sstevel@tonic-gate uid_t Egid; /* truss's effective gid */ 517c478bd9Sstevel@tonic-gate uid_t Ruid; /* truss's real uid */ 527c478bd9Sstevel@tonic-gate uid_t Rgid; /* truss's real gid */ 537c478bd9Sstevel@tonic-gate prcred_t credentials; /* traced process credentials */ 54*134a1f4eSCasper H.S. Dik prpriv_t *privdata; /* traced process privileges */ 557c478bd9Sstevel@tonic-gate int istty; /* TRUE iff output is a tty */ 567c478bd9Sstevel@tonic-gate time_t starttime; /* start time */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate int Fflag; /* option flags from getopt() */ 597c478bd9Sstevel@tonic-gate int fflag; 607c478bd9Sstevel@tonic-gate int cflag; 617c478bd9Sstevel@tonic-gate int aflag; 627c478bd9Sstevel@tonic-gate int eflag; 637c478bd9Sstevel@tonic-gate int iflag; 647c478bd9Sstevel@tonic-gate int lflag; 657c478bd9Sstevel@tonic-gate int tflag; 667c478bd9Sstevel@tonic-gate int pflag; 677c478bd9Sstevel@tonic-gate int sflag; 687c478bd9Sstevel@tonic-gate int mflag; 697c478bd9Sstevel@tonic-gate int oflag; 707c478bd9Sstevel@tonic-gate int vflag; 717c478bd9Sstevel@tonic-gate int xflag; 727c478bd9Sstevel@tonic-gate int hflag; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate int dflag; 757c478bd9Sstevel@tonic-gate int Dflag; 767c478bd9Sstevel@tonic-gate int Eflag; 777c478bd9Sstevel@tonic-gate int Tflag; 787c478bd9Sstevel@tonic-gate int Sflag; 797c478bd9Sstevel@tonic-gate int Mflag; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate sysset_t trace; /* sys calls to trace */ 827c478bd9Sstevel@tonic-gate sysset_t traceeven; /* sys calls to trace even if not reported */ 837c478bd9Sstevel@tonic-gate sysset_t verbose; /* sys calls to be verbose about */ 847c478bd9Sstevel@tonic-gate sysset_t rawout; /* sys calls to show in raw mode */ 857c478bd9Sstevel@tonic-gate sigset_t signals; /* signals to trace */ 867c478bd9Sstevel@tonic-gate fltset_t faults; /* faults to trace */ 877c478bd9Sstevel@tonic-gate fileset_t readfd; /* read() file descriptors to dump */ 887c478bd9Sstevel@tonic-gate fileset_t writefd; /* write() file descriptors to dump */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate mutex_t truss_lock; /* protects almost everything */ 917c478bd9Sstevel@tonic-gate cond_t truss_cv; 927c478bd9Sstevel@tonic-gate mutex_t count_lock; /* lock protecting count struct Cp */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate htbl_t *fcall_tbl; /* ptr to hash tbl counting function calls */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate int truss_nlwp; /* number of truss lwps */ 977c478bd9Sstevel@tonic-gate int truss_maxlwp; /* number of entries in truss_lwpid */ 987c478bd9Sstevel@tonic-gate lwpid_t *truss_lwpid; /* array of truss lwpid's */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate struct counts *Cp; /* for counting: malloc() or shared memory */ 1017c478bd9Sstevel@tonic-gate struct global_psinfo *gps; /* contains global process information */ 1027c478bd9Sstevel@tonic-gate 103186f7fbfSEdward Pilatowicz struct dynlib *Dynlib; /* for tracing functions in shared libraries */ 1047c478bd9Sstevel@tonic-gate struct dynpat *Dynpat; 1057c478bd9Sstevel@tonic-gate struct dynpat *Lastpat; 1067c478bd9Sstevel@tonic-gate struct bkpt **bpt_hashtable; /* breakpoint hash table */ 1077c478bd9Sstevel@tonic-gate uint_t nthr_create; /* number of thr_create() calls seen so far */ 1087c478bd9Sstevel@tonic-gate struct callstack *callstack; /* the callstack array */ 1097c478bd9Sstevel@tonic-gate uint_t nstack; /* number of detected stacks */ 1107c478bd9Sstevel@tonic-gate rd_agent_t *Rdb_agent; /* run-time linker debug handle */ 1117c478bd9Sstevel@tonic-gate td_thragent_t *Thr_agent; /* thread debug handle */ 1127c478bd9Sstevel@tonic-gate int not_consist; /* used while rebuilding breakpoint table */ 1136fced65dSraf int delete_library; /* used while rebuilding breakpoint table */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate pid_t ancestor; /* top-level parent process id */ 1167c478bd9Sstevel@tonic-gate int descendent; /* TRUE iff descendent of top level */ 1177c478bd9Sstevel@tonic-gate int is_vfork_child; /* TRUE iff process is a vfork()ed child */ 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate int ngrab; /* number of pid's that were grabbed */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate struct ps_prochandle *Proc; /* global reference to process */ 1227c478bd9Sstevel@tonic-gate int data_model; /* PR_MODEL_LP64 or PR_MODEL_ILP32 */ 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate long pagesize; /* bytes per page; should be per-process */ 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate int exit_called; /* _exit() syscall was seen */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate lwpid_t primary_lwp; /* representative lwp on process grab */ 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate sysset_t syshang; /* sys calls to make process hang */ 1317c478bd9Sstevel@tonic-gate sigset_t sighang; /* signals to make process hang */ 1327c478bd9Sstevel@tonic-gate fltset_t flthang; /* faults to make process hang */ 1337c478bd9Sstevel@tonic-gate 13453e568b1Sraf sigset_t emptyset; /* no signals, for thr_sigsetmask() */ 13553e568b1Sraf sigset_t fillset; /* all signals, for thr_sigsetmask() */ 13653e568b1Sraf 1377c478bd9Sstevel@tonic-gate int leave_hung; /* if TRUE, leave the process hung */ 138