xref: /freebsd/sys/kern/posix4_mib.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 1998
5  *	HD Associates, Inc.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by HD Associates, Inc
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/queue.h>
42 #include <sys/sysctl.h>
43 #include <sys/vnode.h>
44 #include <sys/proc.h>
45 #include <sys/posix4.h>
46 
47 static int facility[CTL_P1003_1B_MAXID - 1];
48 static int facility_initialized[CTL_P1003_1B_MAXID - 1];
49 
50 static int p31b_sysctl_proc(SYSCTL_HANDLER_ARGS);
51 
52 /* OID_AUTO isn't working with sysconf(3).  I guess I'd have to
53  * modify it to do a lookup by name from the index.
54  * For now I've left it a top-level sysctl.
55  */
56 
57 #if 1
58 
59 SYSCTL_DECL(_p1003_1b);
60 
61 #define P1B_SYSCTL(num, name)  \
62 	SYSCTL_INT(_p1003_1b, num, name, CTLFLAG_RD | CTLFLAG_CAPRD, \
63 	facility + num - 1, 0, "");
64 #define P1B_SYSCTL_RW(num, name)  \
65 	SYSCTL_PROC(_p1003_1b, num, name, \
66 	    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, NULL, num, \
67 	    p31b_sysctl_proc, "I", "");
68 
69 #else
70 
71 SYSCTL_DECL(_kern_p1003_1b);
72 
73 #define P1B_SYSCTL(num, name)  \
74 	SYSCTL_INT(_kern_p1003_1b, OID_AUTO, name, CTLFLAG_RD | CTLFLAG_CAPRD, \
75 	    facility + num - 1, 0, "");
76 #define P1B_SYSCTL_RW(num, name)  \
77 	SYSCTL_PROC(_p1003_1b, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW, NULL, \
78 	    num, p31b_sysctl_proc, "I", "");
79 SYSCTL_NODE(_kern, OID_AUTO, p1003_1b, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
80     "P1003.1B");
81 
82 #endif
83 
84 P1B_SYSCTL(CTL_P1003_1B_ASYNCHRONOUS_IO, asynchronous_io);
85 P1B_SYSCTL(CTL_P1003_1B_MAPPED_FILES, mapped_files);
86 P1B_SYSCTL(CTL_P1003_1B_MEMLOCK, memlock);
87 P1B_SYSCTL(CTL_P1003_1B_MEMLOCK_RANGE, memlock_range);
88 P1B_SYSCTL(CTL_P1003_1B_MEMORY_PROTECTION, memory_protection);
89 P1B_SYSCTL(CTL_P1003_1B_MESSAGE_PASSING, message_passing);
90 P1B_SYSCTL(CTL_P1003_1B_PRIORITIZED_IO, prioritized_io);
91 P1B_SYSCTL(CTL_P1003_1B_PRIORITY_SCHEDULING, priority_scheduling);
92 P1B_SYSCTL(CTL_P1003_1B_REALTIME_SIGNALS, realtime_signals);
93 P1B_SYSCTL(CTL_P1003_1B_SEMAPHORES, semaphores);
94 P1B_SYSCTL(CTL_P1003_1B_FSYNC, fsync);
95 P1B_SYSCTL(CTL_P1003_1B_SHARED_MEMORY_OBJECTS, shared_memory_objects);
96 P1B_SYSCTL(CTL_P1003_1B_SYNCHRONIZED_IO, synchronized_io);
97 P1B_SYSCTL(CTL_P1003_1B_TIMERS, timers);
98 P1B_SYSCTL(CTL_P1003_1B_AIO_MAX, aio_max);
99 P1B_SYSCTL(CTL_P1003_1B_AIO_PRIO_DELTA_MAX, aio_prio_delta_max);
100 P1B_SYSCTL(CTL_P1003_1B_DELAYTIMER_MAX, delaytimer_max);
101 P1B_SYSCTL(CTL_P1003_1B_MQ_OPEN_MAX, mq_open_max);
102 P1B_SYSCTL(CTL_P1003_1B_PAGESIZE, pagesize);
103 P1B_SYSCTL(CTL_P1003_1B_RTSIG_MAX, rtsig_max);
104 P1B_SYSCTL_RW(CTL_P1003_1B_SEM_NSEMS_MAX, sem_nsems_max);
105 P1B_SYSCTL(CTL_P1003_1B_SEM_VALUE_MAX, sem_value_max);
106 P1B_SYSCTL(CTL_P1003_1B_SIGQUEUE_MAX, sigqueue_max);
107 P1B_SYSCTL(CTL_P1003_1B_TIMER_MAX, timer_max);
108 
109 #define P31B_VALID(num)	((num) >= 1 && (num) < CTL_P1003_1B_MAXID)
110 
111 static int
112 p31b_sysctl_proc(SYSCTL_HANDLER_ARGS)
113 {
114 	int error, num, val;
115 
116 	num = arg2;
117 	if (!P31B_VALID(num))
118 		return (EINVAL);
119 	val = facility_initialized[num - 1] ? facility[num - 1] : 0;
120 	error = sysctl_handle_int(oidp, &val, 0, req);
121 	if (error == 0 && req->newptr != NULL && facility_initialized[num - 1])
122 		facility[num - 1] = val;
123 	return (error);
124 }
125 
126 /* p31b_setcfg: Set the configuration
127  */
128 void
129 p31b_setcfg(int num, int value)
130 {
131 
132 	if (P31B_VALID(num)) {
133 		facility[num - 1] = value;
134 		facility_initialized[num - 1] = 1;
135 	}
136 }
137 
138 void
139 p31b_unsetcfg(int num)
140 {
141 
142 	facility[num - 1] = 0;
143 	facility_initialized[num - 1] = 0;
144 }
145 
146 int
147 p31b_getcfg(int num)
148 {
149 
150 	if (P31B_VALID(num))
151 		return (facility[num - 1]);
152 	return (0);
153 }
154 
155 int
156 p31b_iscfg(int num)
157 {
158 
159 	if (P31B_VALID(num))
160 		return (facility_initialized[num - 1]);
161 	return (0);
162 }
163 
164 /*
165  * Turn on indications for standard (non-configurable) kernel features.
166  */
167 static void
168 p31b_set_standard(void *dummy)
169 {
170 
171 	p31b_setcfg(CTL_P1003_1B_FSYNC, 200112L);
172 	p31b_setcfg(CTL_P1003_1B_MAPPED_FILES, 200112L);
173 	p31b_setcfg(CTL_P1003_1B_SHARED_MEMORY_OBJECTS, 200112L);
174 	p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
175 }
176 
177 SYSINIT(p31b_set_standard, SI_SUB_P1003_1B, SI_ORDER_ANY, p31b_set_standard,
178     NULL);
179