1266986Smarkj# 2266986Smarkj# CDDL HEADER START 3266986Smarkj# 4266986Smarkj# The contents of this file are subject to the terms of the 5266986Smarkj# Common Development and Distribution License (the "License"). 6266986Smarkj# You may not use this file except in compliance with the License. 7266986Smarkj# 8266986Smarkj# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9266986Smarkj# or http://www.opensolaris.org/os/licensing. 10266986Smarkj# See the License for the specific language governing permissions 11266986Smarkj# and limitations under the License. 12266986Smarkj# 13266986Smarkj# When distributing Covered Code, include this CDDL HEADER in each 14266986Smarkj# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15266986Smarkj# If applicable, add the following below this CDDL HEADER, with the 16266986Smarkj# fields enclosed by brackets "[]" replaced with your own identifying 17266986Smarkj# information: Portions Copyright [yyyy] [name of copyright owner] 18266986Smarkj# 19266986Smarkj# CDDL HEADER END 20266986Smarkj# 21266986Smarkj 22266986Smarkj# 23266986Smarkj# Copyright (c) 2012, Joyent, Inc. All rights reserved. 24266986Smarkj# 25266986Smarkj 26266986Smarkjppriv -s A=basic,dtrace_proc,dtrace_user $$ 27266986Smarkj 28266986Smarkj# 29266986Smarkj# When we have dtrace_proc (but lack dtrace_kernel), we expect to be able to 30266986Smarkj# read certain curpsinfo/curlwpsinfo/curcpu fields even though they require 31266986Smarkj# reading in-kernel state. However, there are other fields in these translated 32266986Smarkj# structures that we know we shouldn't be able to read, as they require reading 33266986Smarkj# in-kernel state that we cannot read with only dtrace_proc. Finally, there 34266986Smarkj# are a few fields that we may or may not be able to read depending on the 35266986Smarkj# specifics of context. This test therefore asserts that we can read what we 36266986Smarkj# think we should be able to, that we can't read what we think we shouldn't be 37266986Smarkj# able to, and (for purposes of completeness) that we are indifferent about 38266986Smarkj# what we cannot assert one way or the other. 39266986Smarkj# 40266986Smarkj/usr/sbin/dtrace -q -Cs /dev/stdin <<EOF 41266986Smarkj 42266986Smarkj#define CANREAD(what, field) \ 43266986Smarkj BEGIN { errmsg = "can't read field from what"; printf("field: "); \ 44266986Smarkj trace(what->field); printf("\n"); } 45266986Smarkj 46266986Smarkj#define CANTREAD(what, field) \ 47266986Smarkj BEGIN { errmsg = ""; trace(what->field); \ 48266986Smarkj printf("\nable to successfully read field from what!"); exit(1); } 49266986Smarkj 50266986Smarkj#define MIGHTREAD(what, field) \ 51266986Smarkj BEGIN { errmsg = ""; printf("field: "); trace(what->field); printf("\n"); } 52266986Smarkj 53266986Smarkj#define CANREADVAR(vname) \ 54266986Smarkj BEGIN { errmsg = "can't read vname"; printf("vname: "); \ 55266986Smarkj trace(vname); printf("\n"); } 56266986Smarkj 57266986Smarkj#define CANTREADVAR(vname) \ 58266986Smarkj BEGIN { errmsg = ""; trace(vname); \ 59266986Smarkj printf("\nable to successfully read vname!"); exit(1); } 60266986Smarkj 61266986Smarkj#define MIGHTREADVAR(vname) \ 62266986Smarkj BEGIN { errmsg = ""; printf("vname: "); trace(vname); printf("\n"); } 63266986Smarkj 64266986SmarkjCANREAD(curpsinfo, pr_pid) 65266986SmarkjCANREAD(curpsinfo, pr_nlwp) 66266986SmarkjCANREAD(curpsinfo, pr_ppid) 67266986SmarkjCANREAD(curpsinfo, pr_uid) 68266986SmarkjCANREAD(curpsinfo, pr_euid) 69266986SmarkjCANREAD(curpsinfo, pr_gid) 70266986SmarkjCANREAD(curpsinfo, pr_egid) 71266986SmarkjCANREAD(curpsinfo, pr_addr) 72266986SmarkjCANREAD(curpsinfo, pr_start) 73266986SmarkjCANREAD(curpsinfo, pr_fname) 74266986SmarkjCANREAD(curpsinfo, pr_psargs) 75266986SmarkjCANREAD(curpsinfo, pr_argc) 76266986SmarkjCANREAD(curpsinfo, pr_argv) 77266986SmarkjCANREAD(curpsinfo, pr_envp) 78266986SmarkjCANREAD(curpsinfo, pr_dmodel) 79266986Smarkj 80266986Smarkj/* 81266986Smarkj * If our p_pgidp points to the same pid structure as our p_pidp, we will 82266986Smarkj * be able to read pr_pgid -- but we won't if not. 83266986Smarkj */ 84266986SmarkjMIGHTREAD(curpsinfo, pr_pgid) 85266986Smarkj 86266986SmarkjCANTREAD(curpsinfo, pr_sid) 87266986SmarkjCANTREAD(curpsinfo, pr_ttydev) 88266986SmarkjCANTREAD(curpsinfo, pr_projid) 89266986SmarkjCANTREAD(curpsinfo, pr_zoneid) 90266986SmarkjCANTREAD(curpsinfo, pr_contract) 91266986Smarkj 92266986SmarkjCANREAD(curlwpsinfo, pr_flag) 93266986SmarkjCANREAD(curlwpsinfo, pr_lwpid) 94266986SmarkjCANREAD(curlwpsinfo, pr_addr) 95266986SmarkjCANREAD(curlwpsinfo, pr_wchan) 96266986SmarkjCANREAD(curlwpsinfo, pr_stype) 97266986SmarkjCANREAD(curlwpsinfo, pr_state) 98266986SmarkjCANREAD(curlwpsinfo, pr_sname) 99266986SmarkjCANREAD(curlwpsinfo, pr_syscall) 100266986SmarkjCANREAD(curlwpsinfo, pr_pri) 101266986SmarkjCANREAD(curlwpsinfo, pr_onpro) 102266986SmarkjCANREAD(curlwpsinfo, pr_bindpro) 103266986SmarkjCANREAD(curlwpsinfo, pr_bindpset) 104266986Smarkj 105266986SmarkjCANTREAD(curlwpsinfo, pr_clname) 106266986SmarkjCANTREAD(curlwpsinfo, pr_lgrp) 107266986Smarkj 108266986SmarkjCANREAD(curcpu, cpu_id) 109266986Smarkj 110266986SmarkjCANTREAD(curcpu, cpu_pset) 111266986SmarkjCANTREAD(curcpu, cpu_chip) 112266986SmarkjCANTREAD(curcpu, cpu_lgrp) 113266986SmarkjCANTREAD(curcpu, cpu_info) 114266986Smarkj 115266986Smarkj/* 116266986Smarkj * We cannot assert one thing or another about the variable "root": for those 117266986Smarkj * with only dtrace_proc, it will be readable in the global but not readable in 118266986Smarkj * the non-global. 119266986Smarkj */ 120266986SmarkjMIGHTREADVAR(root) 121266986Smarkj 122266986SmarkjCANREADVAR(cpu) 123266986SmarkjCANTREADVAR(pset) 124266986SmarkjCANTREADVAR(cwd) 125266986SmarkjCANTREADVAR(chip) 126266986SmarkjCANTREADVAR(lgrp) 127266986Smarkj 128266986SmarkjBEGIN 129266986Smarkj{ 130266986Smarkj exit(0); 131266986Smarkj} 132266986Smarkj 133266986SmarkjERROR 134266986Smarkj/errmsg != ""/ 135266986Smarkj{ 136266986Smarkj printf("fatal error: %s", errmsg); 137266986Smarkj exit(1); 138266986Smarkj} 139