Print this page
2916 DTrace in a zone should be able to access fds[]


   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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  25  * Copyright (c) 2011 by Delphix. All rights reserved.
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <sys/modctl.h>
  30 #include <sys/systeminfo.h>
  31 #include <sys/resource.h>
  32 
  33 #include <libelf.h>
  34 #include <strings.h>
  35 #include <alloca.h>
  36 #include <limits.h>
  37 #include <unistd.h>
  38 #include <stdlib.h>
  39 #include <stdio.h>
  40 #include <fcntl.h>
  41 #include <errno.h>
  42 #include <assert.h>
  43 
  44 #define _POSIX_PTHREAD_SEMANTICS


  93  * modification to the version number.
  94  */
  95 #define DT_VERS_1_0     DT_VERSION_NUMBER(1, 0, 0)
  96 #define DT_VERS_1_1     DT_VERSION_NUMBER(1, 1, 0)
  97 #define DT_VERS_1_2     DT_VERSION_NUMBER(1, 2, 0)
  98 #define DT_VERS_1_2_1   DT_VERSION_NUMBER(1, 2, 1)
  99 #define DT_VERS_1_2_2   DT_VERSION_NUMBER(1, 2, 2)
 100 #define DT_VERS_1_3     DT_VERSION_NUMBER(1, 3, 0)
 101 #define DT_VERS_1_4     DT_VERSION_NUMBER(1, 4, 0)
 102 #define DT_VERS_1_4_1   DT_VERSION_NUMBER(1, 4, 1)
 103 #define DT_VERS_1_5     DT_VERSION_NUMBER(1, 5, 0)
 104 #define DT_VERS_1_6     DT_VERSION_NUMBER(1, 6, 0)
 105 #define DT_VERS_1_6_1   DT_VERSION_NUMBER(1, 6, 1)
 106 #define DT_VERS_1_6_2   DT_VERSION_NUMBER(1, 6, 2)
 107 #define DT_VERS_1_6_3   DT_VERSION_NUMBER(1, 6, 3)
 108 #define DT_VERS_1_7     DT_VERSION_NUMBER(1, 7, 0)
 109 #define DT_VERS_1_7_1   DT_VERSION_NUMBER(1, 7, 1)
 110 #define DT_VERS_1_8     DT_VERSION_NUMBER(1, 8, 0)
 111 #define DT_VERS_1_8_1   DT_VERSION_NUMBER(1, 8, 1)
 112 #define DT_VERS_1_9     DT_VERSION_NUMBER(1, 9, 0)
 113 #define DT_VERS_LATEST  DT_VERS_1_9
 114 #define DT_VERS_STRING  "Sun D 1.9"

 115 
 116 const dt_version_t _dtrace_versions[] = {
 117         DT_VERS_1_0,    /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
 118         DT_VERS_1_1,    /* D API 1.1.0 Solaris Express 6/05 */
 119         DT_VERS_1_2,    /* D API 1.2.0 Solaris 10 Update 1 */
 120         DT_VERS_1_2_1,  /* D API 1.2.1 Solaris Express 4/06 */
 121         DT_VERS_1_2_2,  /* D API 1.2.2 Solaris Express 6/06 */
 122         DT_VERS_1_3,    /* D API 1.3 Solaris Express 10/06 */
 123         DT_VERS_1_4,    /* D API 1.4 Solaris Express 2/07 */
 124         DT_VERS_1_4_1,  /* D API 1.4.1 Solaris Express 4/07 */
 125         DT_VERS_1_5,    /* D API 1.5 Solaris Express 7/07 */
 126         DT_VERS_1_6,    /* D API 1.6 */
 127         DT_VERS_1_6_1,  /* D API 1.6.1 */
 128         DT_VERS_1_6_2,  /* D API 1.6.2 */
 129         DT_VERS_1_6_3,  /* D API 1.6.3 */
 130         DT_VERS_1_7,    /* D API 1.7 */
 131         DT_VERS_1_7_1,  /* D API 1.7.1 */
 132         DT_VERS_1_8,    /* D API 1.8 */
 133         DT_VERS_1_8_1,  /* D API 1.8.1 */
 134         DT_VERS_1_9,    /* D API 1.9 */

 135         0
 136 };
 137 
 138 /*
 139  * Table of global identifiers.  This is used to populate the global identifier
 140  * hash when a new dtrace client open occurs.  For more info see dt_ident.h.
 141  * The global identifiers that represent functions use the dt_idops_func ops
 142  * and specify the private data pointer as a prototype string which is parsed
 143  * when the identifier is first encountered.  These prototypes look like ANSI
 144  * C function prototypes except that the special symbol "@" can be used as a
 145  * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
 146  * The standard "..." notation can also be used to represent varargs.  An empty
 147  * parameter list is taken to mean void (that is, no arguments are permitted).
 148  * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
 149  * argument.
 150  */
 151 static const dt_ident_t _dtrace_globals[] = {
 152 { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0,
 153         &dt_idops_func, "void *(size_t)" },
 154 { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0,


 228 { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
 229         &dt_idops_func, "void(int)" },
 230 { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN,
 231         DT_VERS_1_1, &dt_idops_func, "void(@, ...)" },
 232 { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN,
 233         DT_VERS_1_0, &dt_idops_func, "void()" },
 234 { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
 235         DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
 236 { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR,
 237         DT_ATTR_EVOLCMN, DT_VERS_1_0,
 238         &dt_idops_func, "genunix`major_t(genunix`dev_t)" },
 239 { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR,
 240         DT_ATTR_EVOLCMN, DT_VERS_1_0,
 241         &dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
 242 { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 243         &dt_idops_func, "uint32_t(uint32_t)" },
 244 { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 245         &dt_idops_func, "uint64_t(uint64_t)" },
 246 { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 247         &dt_idops_func, "uint16_t(uint16_t)" },


 248 { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0,
 249         &dt_idops_type, "gid_t" },
 250 { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0,
 251         &dt_idops_type, "uint_t" },
 252 { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
 253         &dt_idops_func, "int(const char *, const char *, [int])" },
 254 { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN,
 255         DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" },
 256 { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN,
 257         DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" },
 258 { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN,
 259         DT_VERS_1_5, &dt_idops_func, "string(int, void *)" },
 260 { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0,
 261         &dt_idops_type, "uint_t" },
 262 { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
 263         &dt_idops_func, "stack(...)" },
 264 { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
 265         &dt_idops_func, "string(int64_t, [int])" },
 266 { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN,
 267         DT_VERS_1_7, &dt_idops_func,




   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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  25  * Copyright (c) 2011 by Delphix. All rights reserved.
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <sys/modctl.h>
  30 #include <sys/systeminfo.h>
  31 #include <sys/resource.h>
  32 
  33 #include <libelf.h>
  34 #include <strings.h>
  35 #include <alloca.h>
  36 #include <limits.h>
  37 #include <unistd.h>
  38 #include <stdlib.h>
  39 #include <stdio.h>
  40 #include <fcntl.h>
  41 #include <errno.h>
  42 #include <assert.h>
  43 
  44 #define _POSIX_PTHREAD_SEMANTICS


  93  * modification to the version number.
  94  */
  95 #define DT_VERS_1_0     DT_VERSION_NUMBER(1, 0, 0)
  96 #define DT_VERS_1_1     DT_VERSION_NUMBER(1, 1, 0)
  97 #define DT_VERS_1_2     DT_VERSION_NUMBER(1, 2, 0)
  98 #define DT_VERS_1_2_1   DT_VERSION_NUMBER(1, 2, 1)
  99 #define DT_VERS_1_2_2   DT_VERSION_NUMBER(1, 2, 2)
 100 #define DT_VERS_1_3     DT_VERSION_NUMBER(1, 3, 0)
 101 #define DT_VERS_1_4     DT_VERSION_NUMBER(1, 4, 0)
 102 #define DT_VERS_1_4_1   DT_VERSION_NUMBER(1, 4, 1)
 103 #define DT_VERS_1_5     DT_VERSION_NUMBER(1, 5, 0)
 104 #define DT_VERS_1_6     DT_VERSION_NUMBER(1, 6, 0)
 105 #define DT_VERS_1_6_1   DT_VERSION_NUMBER(1, 6, 1)
 106 #define DT_VERS_1_6_2   DT_VERSION_NUMBER(1, 6, 2)
 107 #define DT_VERS_1_6_3   DT_VERSION_NUMBER(1, 6, 3)
 108 #define DT_VERS_1_7     DT_VERSION_NUMBER(1, 7, 0)
 109 #define DT_VERS_1_7_1   DT_VERSION_NUMBER(1, 7, 1)
 110 #define DT_VERS_1_8     DT_VERSION_NUMBER(1, 8, 0)
 111 #define DT_VERS_1_8_1   DT_VERSION_NUMBER(1, 8, 1)
 112 #define DT_VERS_1_9     DT_VERSION_NUMBER(1, 9, 0)
 113 #define DT_VERS_1_10    DT_VERSION_NUMBER(1, 10, 0)
 114 #define DT_VERS_LATEST  DT_VERS_1_10
 115 #define DT_VERS_STRING  "Sun D 1.10"
 116 
 117 const dt_version_t _dtrace_versions[] = {
 118         DT_VERS_1_0,    /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
 119         DT_VERS_1_1,    /* D API 1.1.0 Solaris Express 6/05 */
 120         DT_VERS_1_2,    /* D API 1.2.0 Solaris 10 Update 1 */
 121         DT_VERS_1_2_1,  /* D API 1.2.1 Solaris Express 4/06 */
 122         DT_VERS_1_2_2,  /* D API 1.2.2 Solaris Express 6/06 */
 123         DT_VERS_1_3,    /* D API 1.3 Solaris Express 10/06 */
 124         DT_VERS_1_4,    /* D API 1.4 Solaris Express 2/07 */
 125         DT_VERS_1_4_1,  /* D API 1.4.1 Solaris Express 4/07 */
 126         DT_VERS_1_5,    /* D API 1.5 Solaris Express 7/07 */
 127         DT_VERS_1_6,    /* D API 1.6 */
 128         DT_VERS_1_6_1,  /* D API 1.6.1 */
 129         DT_VERS_1_6_2,  /* D API 1.6.2 */
 130         DT_VERS_1_6_3,  /* D API 1.6.3 */
 131         DT_VERS_1_7,    /* D API 1.7 */
 132         DT_VERS_1_7_1,  /* D API 1.7.1 */
 133         DT_VERS_1_8,    /* D API 1.8 */
 134         DT_VERS_1_8_1,  /* D API 1.8.1 */
 135         DT_VERS_1_9,    /* D API 1.9 */
 136         DT_VERS_1_10,   /* D API 1.10 */
 137         0
 138 };
 139 
 140 /*
 141  * Table of global identifiers.  This is used to populate the global identifier
 142  * hash when a new dtrace client open occurs.  For more info see dt_ident.h.
 143  * The global identifiers that represent functions use the dt_idops_func ops
 144  * and specify the private data pointer as a prototype string which is parsed
 145  * when the identifier is first encountered.  These prototypes look like ANSI
 146  * C function prototypes except that the special symbol "@" can be used as a
 147  * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
 148  * The standard "..." notation can also be used to represent varargs.  An empty
 149  * parameter list is taken to mean void (that is, no arguments are permitted).
 150  * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
 151  * argument.
 152  */
 153 static const dt_ident_t _dtrace_globals[] = {
 154 { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0,
 155         &dt_idops_func, "void *(size_t)" },
 156 { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0,


 230 { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
 231         &dt_idops_func, "void(int)" },
 232 { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN,
 233         DT_VERS_1_1, &dt_idops_func, "void(@, ...)" },
 234 { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN,
 235         DT_VERS_1_0, &dt_idops_func, "void()" },
 236 { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
 237         DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
 238 { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR,
 239         DT_ATTR_EVOLCMN, DT_VERS_1_0,
 240         &dt_idops_func, "genunix`major_t(genunix`dev_t)" },
 241 { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR,
 242         DT_ATTR_EVOLCMN, DT_VERS_1_0,
 243         &dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
 244 { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 245         &dt_idops_func, "uint32_t(uint32_t)" },
 246 { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 247         &dt_idops_func, "uint64_t(uint64_t)" },
 248 { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
 249         &dt_idops_func, "uint16_t(uint16_t)" },
 250 { "getf", DT_IDENT_FUNC, 0, DIF_SUBR_GETF, DT_ATTR_STABCMN, DT_VERS_1_10,
 251         &dt_idops_func, "file_t *(int)" },
 252 { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0,
 253         &dt_idops_type, "gid_t" },
 254 { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0,
 255         &dt_idops_type, "uint_t" },
 256 { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
 257         &dt_idops_func, "int(const char *, const char *, [int])" },
 258 { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN,
 259         DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" },
 260 { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN,
 261         DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" },
 262 { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN,
 263         DT_VERS_1_5, &dt_idops_func, "string(int, void *)" },
 264 { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0,
 265         &dt_idops_type, "uint_t" },
 266 { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
 267         &dt_idops_func, "stack(...)" },
 268 { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
 269         &dt_idops_func, "string(int64_t, [int])" },
 270 { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN,
 271         DT_VERS_1_7, &dt_idops_func,