1161454Simp#
2161454Simp# CDDL HEADER START
3161454Simp#
4161454Simp# The contents of this file are subject to the terms of the
5161454Simp# Common Development and Distribution License (the "License").
6161454Simp# You may not use this file except in compliance with the License.
7161454Simp#
8161454Simp# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9161454Simp# or http://www.opensolaris.org/os/licensing.
10161454Simp# See the License for the specific language governing permissions
11161454Simp# and limitations under the License.
12161454Simp#
13161454Simp# When distributing Covered Code, include this CDDL HEADER in each
14161454Simp# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15161454Simp# If applicable, add the following below this CDDL HEADER, with the
16161454Simp# fields enclosed by brackets "[]" replaced with your own identifying
17161454Simp# information: Portions Copyright [yyyy] [name of copyright owner]
18161454Simp#
19161454Simp# CDDL HEADER END
20161454Simp#
21161454Simp
22161454Simp#
23161454Simp# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24161454Simp#
25161454Simp
26161454Simpppriv -s A=basic,dtrace_proc,dtrace_user $$
27161454Simp
28161454Simp#
29161454Simp# When we have dtrace_proc (but lack dtrace_kernel), we expect to be able to
30161454Simp# read certain curpsinfo/curlwpsinfo/curcpu fields even though they require
31161454Simp# reading in-kernel state.  However, there are other fields in these translated
32161454Simp# structures that we know we shouldn't be able to read, as they require reading
33161454Simp# in-kernel state that we cannot read with only dtrace_proc.  Finally, there
34161454Simp# are a few fields that we may or may not be able to read depending on the
35161454Simp# specifics of context.  This test therefore asserts that we can read what we
36161454Simp# think we should be able to, that we can't read what we think we shouldn't be
37161454Simp# able to, and (for purposes of completeness) that we are indifferent about
38161454Simp# what we cannot assert one way or the other.
39161454Simp#
40161454Simp/usr/sbin/dtrace -q -Cs /dev/stdin <<EOF
41161454Simp
42161454Simp#define CANREAD(what, field) \
43161454Simp    BEGIN { errmsg = "can't read field from what"; printf("field: "); \
44161454Simp	trace(what->field); printf("\n"); }
45161454Simp
46161454Simp#define CANTREAD(what, field) \
47161454Simp    BEGIN { errmsg = ""; trace(what->field); \
48161454Simp	printf("\nable to successfully read field from what!"); exit(1); }
49161454Simp
50161454Simp#define MIGHTREAD(what, field) \
51161454Simp    BEGIN { errmsg = ""; printf("field: "); trace(what->field); printf("\n"); }
52161454Simp
53161454Simp#define CANREADVAR(vname) \
54161454Simp    BEGIN { errmsg = "can't read vname"; printf("vname: "); \
55161454Simp	trace(vname); printf("\n"); }
56161454Simp
57161454Simp#define CANTREADVAR(vname) \
58161454Simp    BEGIN { errmsg = ""; trace(vname); \
59161454Simp	printf("\nable to successfully read vname!"); exit(1); }
60161454Simp
61161454Simp#define MIGHTREADVAR(vname) \
62249222Skientzle    BEGIN { errmsg = ""; printf("vname: "); trace(vname); printf("\n"); }
63161454Simp
64161454SimpCANREAD(curpsinfo, pr_pid)
65161454SimpCANREAD(curpsinfo, pr_nlwp)
66161454SimpCANREAD(curpsinfo, pr_ppid)
67161454SimpCANREAD(curpsinfo, pr_uid)
68161454SimpCANREAD(curpsinfo, pr_euid)
69161454SimpCANREAD(curpsinfo, pr_gid)
70161454SimpCANREAD(curpsinfo, pr_egid)
71161454SimpCANREAD(curpsinfo, pr_addr)
72161454SimpCANREAD(curpsinfo, pr_start)
73161454SimpCANREAD(curpsinfo, pr_fname)
74161454SimpCANREAD(curpsinfo, pr_psargs)
75161454SimpCANREAD(curpsinfo, pr_argc)
76161454SimpCANREAD(curpsinfo, pr_argv)
77161454SimpCANREAD(curpsinfo, pr_envp)
78161454SimpCANREAD(curpsinfo, pr_dmodel)
79161454Simp
80161454Simp/*
81161454Simp * If our p_pgidp points to the same pid structure as our p_pidp, we will
82161454Simp * be able to read pr_pgid -- but we won't if not.
83161454Simp */
84161454SimpMIGHTREAD(curpsinfo, pr_pgid)
85161454Simp
86161454SimpCANTREAD(curpsinfo, pr_sid)
87161454SimpCANTREAD(curpsinfo, pr_ttydev)
88161454SimpCANTREAD(curpsinfo, pr_projid)
89161454SimpCANTREAD(curpsinfo, pr_zoneid)
90161454SimpCANTREAD(curpsinfo, pr_contract)
91161454Simp
92161454SimpCANREAD(curlwpsinfo, pr_flag)
93161454SimpCANREAD(curlwpsinfo, pr_lwpid)
94161454SimpCANREAD(curlwpsinfo, pr_addr)
95161454SimpCANREAD(curlwpsinfo, pr_wchan)
96161454SimpCANREAD(curlwpsinfo, pr_stype)
97161454SimpCANREAD(curlwpsinfo, pr_state)
98161454SimpCANREAD(curlwpsinfo, pr_sname)
99161454SimpCANREAD(curlwpsinfo, pr_syscall)
100161454SimpCANREAD(curlwpsinfo, pr_pri)
101161454SimpCANREAD(curlwpsinfo, pr_onpro)
102161454SimpCANREAD(curlwpsinfo, pr_bindpro)
103161454SimpCANREAD(curlwpsinfo, pr_bindpset)
104161454Simp
105161454SimpCANTREAD(curlwpsinfo, pr_clname)
106161454SimpCANTREAD(curlwpsinfo, pr_lgrp)
107161454Simp
108161454SimpCANREAD(curcpu, cpu_id)
109161454Simp
110161454SimpCANTREAD(curcpu, cpu_pset)
111161454SimpCANTREAD(curcpu, cpu_chip)
112161454SimpCANTREAD(curcpu, cpu_lgrp)
113161454SimpCANTREAD(curcpu, cpu_info)
114161454Simp
115161454Simp/*
116161454Simp * We cannot assert one thing or another about the variable "root":  for those
117161454Simp * with only dtrace_proc, it will be readable in the global but not readable in
118161454Simp * the non-global.
119161454Simp */
120161454SimpMIGHTREADVAR(root)
121161454Simp
122161454SimpCANREADVAR(cpu)
123161454SimpCANTREADVAR(pset)
124161454SimpCANTREADVAR(cwd)
125161454SimpCANTREADVAR(chip)
126161454SimpCANTREADVAR(lgrp)
127161454Simp
128161454SimpBEGIN
129161454Simp{
130161454Simp	exit(0);
131161454Simp}
132161454Simp
133161454SimpERROR
134161454Simp/errmsg != ""/
135161454Simp{
136161454Simp	printf("fatal error: %s", errmsg);
137161454Simp	exit(1);
138161454Simp}
139161454Simp