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) 2012, Joyent, Inc. All rights reserved.
  24 #
  25 
  26 ppriv -s A=basic,dtrace_proc,dtrace_user $$
  27 
  28 #
  29 # When we have dtrace_proc (but lack dtrace_kernel), we expect to be able to
  30 # read certain curpsinfo/curlwpsinfo/curcpu fields even though they require
  31 # reading in-kernel state.  However, there are other fields in these translated
  32 # structures that we know we shouldn't be able to read, as they require reading
  33 # in-kernel state that we cannot read with only dtrace_proc.  Finally, there
  34 # are a few fields that we may or may not be able to read depending on the
  35 # specifics of context.  This test therefore asserts that we can read what we
  36 # think we should be able to, that we can't read what we think we shouldn't be
  37 # able to, and (for purposes of completeness) that we are indifferent about
  38 # what we cannot assert one way or the other.
  39 #
  40 /usr/sbin/dtrace -q -Cs /dev/stdin <<EOF
  41 
  42 #define CANREAD(what, field) \
  43     BEGIN { errmsg = "can't read field from what"; printf("field: "); \
  44         trace(what->field); printf("\n"); }
  45 
  46 #define CANTREAD(what, field) \
  47     BEGIN { errmsg = ""; trace(what->field); \
  48         printf("\nable to successfully read field from what!"); exit(1); }
  49 
  50 #define MIGHTREAD(what, field) \
  51     BEGIN { errmsg = ""; printf("field: "); trace(what->field); printf("\n"); }
  52 
  53 #define CANREADVAR(vname) \
  54     BEGIN { errmsg = "can't read vname"; printf("vname: "); \
  55         trace(vname); printf("\n"); }
  56 
  57 #define CANTREADVAR(vname) \
  58     BEGIN { errmsg = ""; trace(vname); \
  59         printf("\nable to successfully read vname!"); exit(1); }
  60 
  61 #define MIGHTREADVAR(vname) \
  62     BEGIN { errmsg = ""; printf("vname: "); trace(vname); printf("\n"); }
  63 
  64 CANREAD(curpsinfo, pr_pid)
  65 CANREAD(curpsinfo, pr_nlwp)
  66 CANREAD(curpsinfo, pr_ppid)
  67 CANREAD(curpsinfo, pr_uid)
  68 CANREAD(curpsinfo, pr_euid)
  69 CANREAD(curpsinfo, pr_gid)
  70 CANREAD(curpsinfo, pr_egid)
  71 CANREAD(curpsinfo, pr_addr)
  72 CANREAD(curpsinfo, pr_start)
  73 CANREAD(curpsinfo, pr_fname)
  74 CANREAD(curpsinfo, pr_psargs)
  75 CANREAD(curpsinfo, pr_argc)
  76 CANREAD(curpsinfo, pr_argv)
  77 CANREAD(curpsinfo, pr_envp)
  78 CANREAD(curpsinfo, pr_dmodel)
  79 
  80 /*
  81  * If our p_pgidp points to the same pid structure as our p_pidp, we will
  82  * be able to read pr_pgid -- but we won't if not.
  83  */
  84 MIGHTREAD(curpsinfo, pr_pgid)
  85 
  86 CANTREAD(curpsinfo, pr_sid)
  87 CANTREAD(curpsinfo, pr_ttydev)
  88 CANTREAD(curpsinfo, pr_projid)
  89 CANTREAD(curpsinfo, pr_zoneid)
  90 CANTREAD(curpsinfo, pr_contract)
  91 
  92 CANREAD(curlwpsinfo, pr_flag)
  93 CANREAD(curlwpsinfo, pr_lwpid)
  94 CANREAD(curlwpsinfo, pr_addr)
  95 CANREAD(curlwpsinfo, pr_wchan)
  96 CANREAD(curlwpsinfo, pr_stype)
  97 CANREAD(curlwpsinfo, pr_state)
  98 CANREAD(curlwpsinfo, pr_sname)
  99 CANREAD(curlwpsinfo, pr_syscall)
 100 CANREAD(curlwpsinfo, pr_pri)
 101 CANREAD(curlwpsinfo, pr_onpro)
 102 CANREAD(curlwpsinfo, pr_bindpro)
 103 CANREAD(curlwpsinfo, pr_bindpset)
 104 
 105 CANTREAD(curlwpsinfo, pr_clname)
 106 CANTREAD(curlwpsinfo, pr_lgrp)
 107 
 108 CANREAD(curcpu, cpu_id)
 109 
 110 CANTREAD(curcpu, cpu_pset)
 111 CANTREAD(curcpu, cpu_chip)
 112 CANTREAD(curcpu, cpu_lgrp)
 113 CANTREAD(curcpu, cpu_info)
 114 
 115 /*
 116  * We cannot assert one thing or another about the variable "root":  for those
 117  * with only dtrace_proc, it will be readable in the global but not readable in
 118  * the non-global.
 119  */
 120 MIGHTREADVAR(root)
 121 
 122 CANREADVAR(cpu)
 123 CANTREADVAR(pset)
 124 CANTREADVAR(cwd)
 125 CANTREADVAR(chip)
 126 CANTREADVAR(lgrp)
 127 
 128 BEGIN
 129 {
 130         exit(0);
 131 }
 132 
 133 ERROR
 134 /errmsg != ""/
 135 {
 136         printf("fatal error: %s", errmsg);
 137         exit(1);
 138 }