xref: /freebsd/sys/cddl/dev/dtrace/dtrace_sysctl.c (revision 5c9ef378541ddaf6c7606a454ba992c610c09dd0)
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 SYSCTL_NODE(_debug, OID_AUTO, dtrace, CTLFLAG_RD, 0, "DTrace debug parameters");
26 
27 int	dtrace_debug = 0;
28 SYSCTL_INT(_debug_dtrace, OID_AUTO, debug, CTLFLAG_RWTUN, &dtrace_debug, 0, "");
29 
30 /* Report registered DTrace providers. */
31 static int
32 sysctl_dtrace_providers(SYSCTL_HANDLER_ARGS)
33 {
34 	char	*p_name	= NULL;
35 	dtrace_provider_t
36 		*prov	= dtrace_provider;
37 	int	error	= 0;
38 	size_t	len	= 0;
39 
40 	mutex_enter(&dtrace_provider_lock);
41 	mutex_enter(&dtrace_lock);
42 
43 	/* Compute the length of the space-separated provider name string. */
44 	while (prov != NULL) {
45 		len += strlen(prov->dtpv_name) + 1;
46 		prov = prov->dtpv_next;
47 	}
48 
49 	if ((p_name = kmem_alloc(len, KM_SLEEP)) == NULL)
50 		error = ENOMEM;
51 	else {
52 		/* Start with an empty string. */
53 		*p_name = '\0';
54 
55 		/* Point to the first provider again. */
56 		prov = dtrace_provider;
57 
58 		/* Loop through the providers, appending the names. */
59 		while (prov != NULL) {
60 			if (prov != dtrace_provider)
61 				(void) strlcat(p_name, " ", len);
62 
63 			(void) strlcat(p_name, prov->dtpv_name, len);
64 
65 			prov = prov->dtpv_next;
66 		}
67 	}
68 
69 	mutex_exit(&dtrace_lock);
70 	mutex_exit(&dtrace_provider_lock);
71 
72 	if (p_name != NULL) {
73 		error = sysctl_handle_string(oidp, p_name, len, req);
74 
75 		kmem_free(p_name, 0);
76 	}
77 
78 	return (error);
79 }
80 
81 SYSCTL_PROC(_debug_dtrace, OID_AUTO, providers, CTLTYPE_STRING | CTLFLAG_RD,
82     0, 0, sysctl_dtrace_providers, "A", "available DTrace providers");
83 
84 SYSCTL_NODE(_kern, OID_AUTO, dtrace, CTLFLAG_RD, 0, "DTrace parameters");
85 
86 SYSCTL_INT(_kern_dtrace, OID_AUTO, memstr_max, CTLFLAG_RW, &dtrace_memstr_max,
87     0, "largest allowed argument to memstr(), 0 indicates no limit");
88 
89 SYSCTL_QUAD(_kern_dtrace, OID_AUTO, dof_maxsize, CTLFLAG_RW,
90     &dtrace_dof_maxsize, 0, "largest allowed DOF table");
91 
92 SYSCTL_QUAD(_kern_dtrace, OID_AUTO, helper_actions_max, CTLFLAG_RW,
93     &dtrace_helper_actions_max, 0, "maximum number of allowed helper actions");
94