xref: /freebsd/sys/cddl/dev/dtrace/dtrace_sysctl.c (revision 3078531de10dcae44b253a35125c949ff4235284)
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  * $FreeBSD$
22  *
23  */
24 
25 /* Report registered DTrace providers. */
26 static int
27 sysctl_dtrace_providers(SYSCTL_HANDLER_ARGS)
28 {
29 	char	*p_name	= NULL;
30 	dtrace_provider_t
31 		*prov	= dtrace_provider;
32 	int	error	= 0;
33 	size_t	len	= 0;
34 
35 	mutex_enter(&dtrace_provider_lock);
36 	mutex_enter(&dtrace_lock);
37 
38 	/* Compute the length of the space-separated provider name string. */
39 	while (prov != NULL) {
40 		len += strlen(prov->dtpv_name) + 1;
41 		prov = prov->dtpv_next;
42 	}
43 
44 	if ((p_name = kmem_alloc(len, KM_SLEEP)) == NULL)
45 		error = ENOMEM;
46 	else {
47 		/* Start with an empty string. */
48 		*p_name = '\0';
49 
50 		/* Point to the first provider again. */
51 		prov = dtrace_provider;
52 
53 		/* Loop through the providers, appending the names. */
54 		while (prov != NULL) {
55 			if (prov != dtrace_provider)
56 				(void) strlcat(p_name, " ", len);
57 
58 			(void) strlcat(p_name, prov->dtpv_name, len);
59 
60 			prov = prov->dtpv_next;
61 		}
62 	}
63 
64 	mutex_exit(&dtrace_lock);
65 	mutex_exit(&dtrace_provider_lock);
66 
67 	if (p_name != NULL) {
68 		error = sysctl_handle_string(oidp, p_name, len, req);
69 
70 		kmem_free(p_name, 0);
71 	}
72 
73 	return (error);
74 }
75 
76 SYSCTL_NODE(_debug, OID_AUTO, dtrace, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
77     "DTrace debug parameters");
78 
79 SYSCTL_PROC(_debug_dtrace, OID_AUTO, providers,
80     CTLTYPE_STRING | CTLFLAG_MPSAFE | CTLFLAG_RD, 0, 0, sysctl_dtrace_providers,
81     "A", "available DTrace providers");
82 
83 SYSCTL_NODE(_kern, OID_AUTO, dtrace, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
84     "DTrace parameters");
85 
86 SYSCTL_INT(_kern_dtrace, OID_AUTO, err_verbose, CTLFLAG_RW,
87     &dtrace_err_verbose, 0,
88     "print DIF and DOF validation errors to the message buffer");
89 
90 SYSCTL_INT(_kern_dtrace, OID_AUTO, memstr_max, CTLFLAG_RW, &dtrace_memstr_max,
91     0, "largest allowed argument to memstr(), 0 indicates no limit");
92 
93 SYSCTL_QUAD(_kern_dtrace, OID_AUTO, dof_maxsize, CTLFLAG_RW,
94     &dtrace_dof_maxsize, 0, "largest allowed DOF table");
95 
96 SYSCTL_QUAD(_kern_dtrace, OID_AUTO, helper_actions_max, CTLFLAG_RW,
97     &dtrace_helper_actions_max, 0, "maximum number of allowed helper actions");
98 
99 SYSCTL_INT(_kern_dtrace, OID_AUTO, bufsize_max, CTLFLAG_RWTUN,
100     &dtrace_bufsize_max_frac, 0,
101     "maximum fraction (1/n-th) of physical memory for principal buffers");
102 
103 SYSCTL_INT(_security_bsd, OID_AUTO, allow_destructive_dtrace, CTLFLAG_RDTUN,
104     &dtrace_allow_destructive, 1, "Allow destructive mode DTrace scripts");
105