dt_open.c revision 4edabff493bc4820f4297f981943f11de1cbf3be
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/systeminfo.h>
#include <sys/resource.h>
#include <libelf.h>
#include <strings.h>
#include <alloca.h>
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#define _POSIX_PTHREAD_SEMANTICS
#include <dirent.h>
#include <dt_impl.h>
#include <dt_program.h>
#include <dt_module.h>
#include <dt_printf.h>
#include <dt_string.h>
#include <dt_provider.h>
/*
* Stability and versioning definitions. These #defines are used in the tables
* of identifiers below to fill in the attribute and version fields associated
* with each identifier. The DT_ATTR_* macros are a convenience to permit more
* DT_VERS_* macros declare the encoded integer values of all versions used so
* far. DT_VERS_LATEST must correspond to the latest version value among all
* versions exported by the D compiler. DT_VERS_STRING must be an ASCII string
* that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta).
* You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version,
* and then add the new version to the _dtrace_versions[] array declared below.
* Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters
* respectively for an explanation of these DTrace features and their values.
*
* NOTE: Although the DTrace versioning scheme supports the labeling and
* introduction of incompatible changes (e.g. dropping an interface in a
* major release), the libdtrace code does not currently support this.
* All versions are assumed to strictly inherit from one another. If
* we ever need to provide divergent interfaces, this will need work.
*/
#define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \
#define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \
}
/*
* The version number should be increased for every customer visible release
* of Solaris. The major number should be incremented when a fundamental
* change has been made that would affect all consumers, and would reflect
* sweeping changes to DTrace or the D language. The minor number should be
* incremented when a change is introduced that could break scripts that had
* previously worked; for example, adding a new built-in variable could break
* a script which was already using that identifier. The micro number should
* be changed when introducing functionality changes or major bug fixes that
* do not affect backward compatibility -- this is merely to make capabilities
* easily determined from the version number. Minor bugs do not require any
* modification to the version number.
*/
#define DT_VERS_LATEST DT_VERS_1_4_1
#define DT_VERS_STRING "Sun D 1.4.1"
const dt_version_t _dtrace_versions[] = {
DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */
DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */
DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */
DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */
DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */
DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */
DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */
0
};
/*
* Table of global identifiers. This is used to populate the global identifier
* hash when a new dtrace client open occurs. For more info see dt_ident.h.
* The global identifiers that represent functions use the dt_idops_func ops
* and specify the private data pointer as a prototype string which is parsed
* when the identifier is first encountered. These prototypes look like ANSI
* C function prototypes except that the special symbol "@" can be used as a
* wildcard to represent a single parameter of any type (i.e. any dt_node_t).
* The standard "..." notation can also be used to represent varargs. An empty
* parameter list is taken to mean void (that is, no arguments are permitted).
* A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
* argument.
*/
static const dt_ident_t _dtrace_globals[] = {
&dt_idops_func, "void *(size_t)" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_type, "int64_t" },
&dt_idops_args, NULL },
&dt_idops_func, "void(@)" },
&dt_idops_func, "string(const char *)" },
&dt_idops_func, "void(void *, void *, size_t)" },
&dt_idops_func, "void()" },
&dt_idops_type, "uintptr_t" },
&dt_idops_func, "void(int)" },
&dt_idops_func, "void(...)" },
&dt_idops_func, "void(int)" },
&dt_idops_func, "void *(uintptr_t, size_t)" },
&dt_idops_func, "string(uintptr_t, [size_t])" },
&dt_idops_func, "void(void *, uintptr_t, size_t)" },
&dt_idops_func, "void(char *, uintptr_t, size_t)" },
&dt_idops_func, "void()" },
&dt_idops_type, "genunix`kthread_t *" },
&dt_idops_func, "string(void *, int64_t)" },
&dt_idops_func, "string(const char *)" },
&dt_idops_func, "void(int)" },
&dt_idops_type, "uint_t" },
&dt_idops_type, "int" },
&dt_idops_func, "void(int)" },
&dt_idops_func, "genunix`major_t(genunix`dev_t)" },
&dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
&dt_idops_func, "uint32_t(uint32_t)" },
&dt_idops_func, "uint64_t(uint64_t)" },
&dt_idops_func, "uint16_t(uint16_t)" },
&dt_idops_type, "gid_t" },
&dt_idops_type, "uint_t" },
&dt_idops_func, "int(const char *, const char *, [int])" },
&dt_idops_type, "uint_t" },
&dt_idops_func, "stack(...)" },
&dt_idops_func, "string(int64_t)" },
&dt_idops_func, "void(@, int32_t, int32_t, ...)" },
&dt_idops_func, "void(@)" },
&dt_idops_func, "void(@)" },
&dt_idops_func, "size_t(mblk_t *)" },
&dt_idops_func, "size_t(mblk_t *)" },
&dt_idops_func, "int(genunix`kmutex_t *)" },
&dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" },
&dt_idops_func, "int(genunix`kmutex_t *)" },
&dt_idops_func, "int(genunix`kmutex_t *)" },
&dt_idops_func, "uint32_t(uint32_t)" },
&dt_idops_func, "uint64_t(uint64_t)" },
&dt_idops_func, "uint16_t(uint16_t)" },
&dt_idops_func, "void()" },
&dt_idops_type, "pid_t" },
&dt_idops_type, "pid_t" },
&dt_idops_func, "void(@, ...)" },
&dt_idops_func, "void(@, ...)" },
&dt_idops_func, "int(pid_t)" },
&dt_idops_func, "void(@, ...)" },
&dt_idops_func, "void(int)" },
&dt_idops_func, "int()" },
&dt_idops_func, "int(const char *, const char *, [int])" },
&dt_idops_func, "int(genunix`krwlock_t *)" },
&dt_idops_func, "int(genunix`krwlock_t *)" },
&dt_idops_func, "int(genunix`krwlock_t *)" },
&dt_idops_type, "void" },
&dt_idops_func, "void(int)" },
&dt_idops_func, "int()" },
&dt_idops_func, "stack(...)" },
&dt_idops_type, "uint32_t" },
&dt_idops_func, "void()" },
&dt_idops_func, "string(const char *, char)" },
&dt_idops_func, "size_t(const char *)" },
&dt_idops_func, "string(const char *, const char *)" },
&dt_idops_func, "string(const char *, char)" },
&dt_idops_func, "string(const char *, const char *)" },
&dt_idops_func, "string(const char *, const char *)" },
&dt_idops_func, "string(const char *, int, [int])" },
&dt_idops_func, "void(@)" },
&dt_idops_func, "void(@, ...)" },
&dt_idops_type, "void" },
&dt_idops_type, "id_t" },
&dt_idops_type, "uint64_t" },
&dt_idops_func, "void(@)" },
&dt_idops_func, "void(@, size_t)" },
&dt_idops_type, "uid_t" },
&dt_idops_regs, NULL },
&dt_idops_func, "stack(...)" },
&dt_idops_type, "uint32_t" },
&dt_idops_type, "uint64_t" },
&dt_idops_type, "int64_t" },
};
/*
* Tables of ILP32 intrinsic integer and floating-point type templates to use
* to populate the dynamic "C" CTF type container.
*/
static const dt_intrinsic_t _dtrace_intrinsics_32[] = {
{ NULL, { 0, 0, 0 }, 0 }
};
/*
* Tables of LP64 intrinsic integer and floating-point type templates to use
* to populate the dynamic "C" CTF type container.
*/
static const dt_intrinsic_t _dtrace_intrinsics_64[] = {
{ NULL, { 0, 0, 0 }, 0 }
};
/*
* Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container.
*/
static const dt_typedef_t _dtrace_typedefs_32[] = {
{ "char", "int8_t" },
{ "short", "int16_t" },
{ "int", "int32_t" },
{ "long long", "int64_t" },
{ "int", "intptr_t" },
{ "int", "ssize_t" },
{ "unsigned char", "uint8_t" },
{ "unsigned short", "uint16_t" },
{ "unsigned", "uint32_t" },
{ "unsigned long long", "uint64_t" },
{ "unsigned char", "uchar_t" },
{ "unsigned short", "ushort_t" },
{ "unsigned", "uint_t" },
{ "unsigned long", "ulong_t" },
{ "unsigned long long", "u_longlong_t" },
{ "int", "ptrdiff_t" },
{ "unsigned", "uintptr_t" },
{ "unsigned", "size_t" },
{ "long", "id_t" },
{ "long", "pid_t" },
};
/*
* Tables of LP64 typedefs to use to populate the dynamic "D" CTF container.
*/
static const dt_typedef_t _dtrace_typedefs_64[] = {
{ "char", "int8_t" },
{ "short", "int16_t" },
{ "int", "int32_t" },
{ "long", "int64_t" },
{ "long", "intptr_t" },
{ "long", "ssize_t" },
{ "unsigned char", "uint8_t" },
{ "unsigned short", "uint16_t" },
{ "unsigned", "uint32_t" },
{ "unsigned long", "uint64_t" },
{ "unsigned char", "uchar_t" },
{ "unsigned short", "ushort_t" },
{ "unsigned", "uint_t" },
{ "unsigned long", "ulong_t" },
{ "unsigned long long", "u_longlong_t" },
{ "long", "ptrdiff_t" },
{ "unsigned long", "uintptr_t" },
{ "unsigned long", "size_t" },
{ "int", "id_t" },
{ "int", "pid_t" },
};
/*
* Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
* cache when a new dtrace client open occurs. Values are set by dtrace_open().
*/
static const dt_intdesc_t _dtrace_ints_32[] = {
};
/*
* Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
* cache when a new dtrace client open occurs. Values are set by dtrace_open().
*/
static const dt_intdesc_t _dtrace_ints_64[] = {
};
/*
* Table of macro variable templates used to populate the macro identifier hash
* when a new dtrace client open occurs. Values are set by dtrace_update().
*/
static const dt_ident_t _dtrace_macros[] = {
{ NULL, 0, 0, 0, { 0, 0, 0 }, 0 }
};
/*
* Hard-wired definition string to be compiled and cached every time a new
* DTrace library handle is initialized. This string should only be used to
* contain definitions that should be present regardless of DTRACE_O_NOLIBS.
*/
static const char _dtrace_hardwire[] = "\
inline long NULL = 0; \n\
#pragma D binding \"1.0\" NULL\n\
";
/*
* Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV.
* If DTRACE_O_NODEV is not set, we load the configuration from the kernel.
* The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are
* relying on the fact that when running dtrace(1M), isaexec will invoke the
* binary with the same bitness as the kernel, which is what we want by default
* when generating our DIF. The user can override the choice using oflags.
*/
static const dtrace_conf_t _dtrace_conf = {
DIF_VERSION, /* dtc_difversion */
DIF_DIR_NREGS, /* dtc_difintregs */
DIF_DTR_NREGS, /* dtc_diftupregs */
CTF_MODEL_NATIVE /* dtc_ctfmodel */
};
const dtrace_attribute_t _dtrace_maxattr = {
};
const dtrace_attribute_t _dtrace_defattr = {
};
const dtrace_attribute_t _dtrace_symattr = {
};
const dtrace_attribute_t _dtrace_typattr = {
};
const dtrace_attribute_t _dtrace_prvattr = {
};
const dtrace_pattr_t _dtrace_prvdesc = {
};
int _dtrace_debug = 0; /* debug messages enabled (off) */
typedef struct dt_fdlist {
int *df_fds; /* array of provider driver file descriptors */
} dt_fdlist_t;
#pragma init(_dtrace_init)
void
_dtrace_init(void)
{
for (; _dtrace_rdvers > 0; _dtrace_rdvers--) {
break;
}
}
static dtrace_hdl_t *
{
return (NULL);
}
static void
{
int fd;
return; /* failed to open directory; just skip it */
continue; /* skip "." and ".." */
break; /* skip the rest of this directory */
}
continue; /* failed to open driver; just skip it */
break;
}
}
}
static void
{
}
}
static const char *
{
char *p = buf;
*p++ = '_';
return (buf);
}
static dtrace_hdl_t *
{
int i, err;
const dt_intrinsic_t *dinp;
const dt_typedef_t *dtyp;
const dt_ident_t *idp;
if (version <= 0)
if (version > DTRACE_VERSION)
if (version < DTRACE_VERSION) {
/*
* Currently, increasing the library version number is used to
* denote a binary incompatible change. That is, a consumer
* of the library cannot run on a version of the library with
* a higher DTRACE_VERSION number than the consumer compiled
* against. Once the library API has been committed to,
* backwards binary compatibility will be required; at that
* time, this check should change to return EDT_OVERSION only
* if the specified version number is less than the version
* number at the time of interface commitment.
*/
}
if (flags & ~DTRACE_O_MASK)
goto alloc; /* do not attempt to open dtrace device */
/*
* Before we get going, crank our limit on file descriptors up to the
* hard limit. This is to allow for the fact that libproc keeps file
* descriptors to objects open for the lifetime of the proc handle;
* without raising our hard limit, we would have an acceptably small
* bound on the number of processes that we could concurrently
* instrument with the pid provider.
*/
}
/*
* Get the device path of each of the providers. We hold them open
* in the df.df_fds list until we open the DTrace driver itself,
* allowing us to see all of the probes provided on this system. Once
* we have the DTrace driver open, we can safely close all the providers
* now that they have registered with the framework.
*/
/*
* If we failed to open the dtrace device, fail dtrace_open().
* We convert some kernel errnos to custom libdtrace errnos to
* improve the resulting message from the usual strerror().
*/
if (dtfd == -1) {
switch (err) {
case ENOENT:
break;
case EBUSY:
break;
case EACCES:
err = EDT_ACCESS;
break;
}
}
for (i = 0; i < DTRACEOPT_MAX; i++)
if (flags & DTRACE_O_NODEV)
if (flags & DTRACE_O_LP64)
else if (flags & DTRACE_O_ILP32)
#ifdef __sparc
/*
* On SPARC systems, __sparc is always defined for <sys/isa_defs.h>
* and __sparcv9 is defined if we are doing a 64-bit compile.
*/
#endif
#ifdef __x86
/*
* On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
* compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC,
* they are defined exclusive of one another (see PSARC 2004/619).
*/
} else {
}
#endif
else
/*
* Populate the dt_macros identifier hash table by hand: we can't use
* the dt_idhash_populate() mechanism because we're not yet compiling
* and dtrace_update() needs to immediately reference these idents.
*/
}
/*
* the macro variable definitions according to the current process.
*/
/*
* Select the intrinsics and typedefs we want based on the data model.
* The intrinsics are under "C". The typedefs are added under "D".
*/
} else {
}
/*
* Create a dynamic CTF container under the "C" scope for intrinsic
* types and types defined in ANSI-C header files that are included.
*/
dt_dprintf("created CTF container for %s (%p)\n",
/*
* Fill the dynamic "C" CTF container with all of the intrinsic
* integer and floating-point types appropriate for this data model.
*/
} else {
}
dt_dprintf("failed to add %s to C container: %s\n",
}
}
dt_dprintf("failed to update C container: %s\n",
}
/*
* Add intrinsic pointer types that are needed to initialize printf
* format dictionary types (see table in dt_printf.c).
*/
dt_dprintf("failed to update C container: %s\n",
}
/*
* Create a dynamic CTF container under the "D" scope for types that
* are defined by the D program itself or on-the-fly by the D compiler.
* The "D" CTF container is a child of the "C" CTF container.
*/
dt_dprintf("created CTF container for %s (%p)\n",
dt_dprintf("failed to import D parent container: %s\n",
}
/*
* Fill the dynamic "D" CTF container with all of the built-in typedefs
* that we need to use for our D variable and function definitions.
* This ensures that basic inttypes.h names are always available to us.
*/
dt_dprintf("failed to add typedef %s %s to D "
}
}
/*
* Insert a CTF ID corresponding to a pointer to a type of kind
* CTF_K_FUNCTION we can use in the compiler for function pointers.
* CTF treats all function pointers as "int (*)()" so we only need one.
*/
/*
* We also insert CTF definitions for the special D intrinsic types
* string and <DYN> into the D container. The string type is added
* as a typedef of char[n]. The <DYN> type is an alias for void.
* We compare types to these special CTF ids throughout the compiler.
*/
dt_dprintf("failed to add intrinsic to D container: %s\n",
}
dt_dprintf("failed update D container: %s\n",
}
/*
* Initialize the integer description table used to convert integer
* constants to the appropriate types. Refer to the comments above
* dt_node_int() for a complete description of how this table is used.
*/
dt_dprintf("failed to lookup integer type %s: %s\n",
}
}
/*
* Now that we've created the "C" and "D" containers, move them to the
* start of the module list so that these types and symbols are found
* first (for stability) when iterating through the module list.
*/
/*
* If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default
* names and attributes of any providers or probes from the kernel.
*/
if (flags & DTRACE_O_NODEV)
/*
* Load hard-wired inlines into the definition cache by calling the
* compiler on the raw definition string defined above.
*/
dt_dprintf("failed to load hard-wired definitions: %s\n",
}
/*
* Set up the default DTrace library path. Once set, the next call to
* dt_compile() will compile all the libraries. We intentionally defer
* library processing to improve overhead for clients that don't ever
* compile, and to provide better error reporting (because the full
* reporting of compiler errors requires dtrace_open() to succeed).
*/
return (dtp);
}
{
}
{
}
void
{
int i;
}
}
}
int
{
int i = 0;
if (i < nmods)
}
return (i);
}
int
{
}