xref: /f-stack/tools/compat/include/sys/sysctl.h (revision ebf5cedb)
1 /*
2  * Copyright (C) 2017 THL A29 Limited, a Tencent company.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *   list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *   this list of conditions and the following disclaimer in the documentation
12  *   and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *
26  *  Copied from FreeBSD's header files.
27  */
28 
29 #ifndef _COMPAT_SYS_SYSCTL_H
30 #define _COMPAT_SYS_SYSCTL_H
31 
32 #include <sys/queue.h>
33 #include <sys/types.h>
34 #include <inttypes.h>
35 
36 /*
37  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
38  * for objects that can be examined or modified.  The name is expressed as
39  * a sequence of integers.  Like a file path name, the meaning of each
40  * component depends on its place in the hierarchy.  The top-level and kern
41  * identifiers are defined here, and other identifiers are defined in the
42  * respective subsystem header files.
43  */
44 
45 #define CTL_MAXNAME       24    /* largest number of components supported */
46 
47 /*
48  * Each subsystem defined by sysctl defines a list of variables
49  * for that subsystem. Each name is either a node with further
50  * levels defined below it, or it is a leaf of some particular
51  * type given below. Each sysctl level defines a set of name/type
52  * pairs to be used by sysctl(8) in manipulating the subsystem.
53  */
54 struct ctlname {
55     char    *ctl_name;  /* subsystem name */
56     int  ctl_type;  /* type of name */
57 };
58 
59 #define CTLTYPE     0xf /* mask for the type */
60 #define CTLTYPE_NODE    1   /* name is a node */
61 #define CTLTYPE_INT 2   /* name describes an integer */
62 #define CTLTYPE_STRING  3   /* name describes a string */
63 #define CTLTYPE_S64 4   /* name describes a signed 64-bit number */
64 #define CTLTYPE_OPAQUE  5   /* name describes a structure */
65 #define CTLTYPE_STRUCT  CTLTYPE_OPAQUE  /* name describes a structure */
66 #define CTLTYPE_UINT    6   /* name describes an unsigned integer */
67 #define CTLTYPE_LONG    7   /* name describes a long */
68 #define CTLTYPE_ULONG   8   /* name describes an unsigned long */
69 #define CTLTYPE_U64 9   /* name describes an unsigned 64-bit number */
70 #define CTLTYPE_U8  0xa /* name describes an unsigned 8-bit number */
71 #define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */
72 #define CTLTYPE_S8  0xc /* name describes a signed 8-bit number */
73 #define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */
74 #define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */
75 #define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */
76 
77 #define CTLFLAG_RD  0x80000000  /* Allow reads of variable */
78 #define CTLFLAG_WR  0x40000000  /* Allow writes to the variable */
79 #define CTLFLAG_RW  (CTLFLAG_RD|CTLFLAG_WR)
80 #define CTLFLAG_ANYBODY 0x10000000  /* All users can set this var */
81 #define CTLFLAG_SECURE  0x08000000  /* Permit set only if securelevel<=0 */
82 #define CTLFLAG_PRISON  0x04000000  /* Prisoned roots can fiddle */
83 #define CTLFLAG_DYN 0x02000000  /* Dynamic oid - can be freed */
84 #define CTLFLAG_SKIP    0x01000000  /* Skip this sysctl when listing */
85 #define CTLMASK_SECURE  0x00F00000  /* Secure level */
86 #define CTLFLAG_TUN 0x00080000  /* Default value is loaded from getenv() */
87 #define CTLFLAG_RDTUN   (CTLFLAG_RD|CTLFLAG_TUN)
88 #define CTLFLAG_RWTUN   (CTLFLAG_RW|CTLFLAG_TUN)
89 #define CTLFLAG_MPSAFE  0x00040000  /* Handler is MP safe */
90 #define CTLFLAG_VNET    0x00020000  /* Prisons with vnet can fiddle */
91 #define CTLFLAG_DYING   0x00010000  /* Oid is being removed */
92 #define CTLFLAG_CAPRD   0x00008000  /* Can be read in capability mode */
93 #define CTLFLAG_CAPWR   0x00004000  /* Can be written in capability mode */
94 #define CTLFLAG_STATS   0x00002000  /* Statistics, not a tuneable */
95 #define CTLFLAG_NOFETCH 0x00001000  /* Don't fetch tunable from getenv() */
96 #define CTLFLAG_CAPRW   (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
97 
98 /*
99  * Secure level.   Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
100  *
101  * Secure when the securelevel is raised to at least N.
102  */
103 #define CTLSHIFT_SECURE 20
104 #define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
105 #define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
106 #define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
107 
108 /*
109  * USE THIS instead of a hardwired number from the categories below
110  * to get dynamically assigned sysctl entries using the linker-set
111  * technology. This is the way nearly all new sysctl variables should
112  * be implemented.
113  * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
114  */
115 #define OID_AUTO    (-1)
116 
117 /*
118  * The starting number for dynamically-assigned entries.  WARNING!
119  * ALL static sysctl entries should have numbers LESS than this!
120  */
121 #define CTL_AUTO_START  0x100
122 
123 /*
124  * Top-level identifiers
125  */
126 #define CTL_UNSPEC  0       /* unused */
127 #define CTL_KERN    1       /* "high kernel": proc, limits */
128 #define CTL_VM      2       /* virtual memory */
129 #define CTL_VFS     3       /* filesystem, mount type is next */
130 #define CTL_NET     4       /* network, see socket.h */
131 #define CTL_DEBUG   5       /* debugging parameters */
132 #define CTL_HW      6       /* generic cpu/io */
133 #define CTL_MACHDEP 7       /* machine dependent */
134 #define CTL_USER    8       /* user-level */
135 #define CTL_P1003_1B    9       /* POSIX 1003.1B */
136 
137 /*
138  * CTL_KERN identifiers
139  */
140 #define KERN_OSTYPE      1  /* string: system version */
141 #define KERN_OSRELEASE       2  /* string: system release */
142 #define KERN_OSREV       3  /* int: system revision */
143 #define KERN_VERSION         4  /* string: compile time info */
144 #define KERN_MAXVNODES       5  /* int: max vnodes */
145 #define KERN_MAXPROC         6  /* int: max processes */
146 #define KERN_MAXFILES        7  /* int: max open files */
147 #define KERN_ARGMAX      8  /* int: max arguments to exec */
148 #define KERN_SECURELVL       9  /* int: system security level */
149 #define KERN_HOSTNAME       10  /* string: hostname */
150 #define KERN_HOSTID     11  /* int: host identifier */
151 #define KERN_CLOCKRATE      12  /* struct: struct clockrate */
152 #define KERN_VNODE      13  /* struct: vnode structures */
153 #define KERN_PROC       14  /* struct: process entries */
154 #define KERN_FILE       15  /* struct: file entries */
155 #define KERN_PROF       16  /* node: kernel profiling info */
156 #define KERN_POSIX1     17  /* int: POSIX.1 version */
157 #define KERN_NGROUPS        18  /* int: # of supplemental group ids */
158 #define KERN_JOB_CONTROL    19  /* int: is job control available */
159 #define KERN_SAVED_IDS      20  /* int: saved set-user/group-ID */
160 #define KERN_BOOTTIME       21  /* struct: time kernel was booted */
161 #define KERN_NISDOMAINNAME  22  /* string: YP domain name */
162 #define KERN_UPDATEINTERVAL 23  /* int: update process sleep time */
163 #define KERN_OSRELDATE      24  /* int: kernel release date */
164 #define KERN_NTP_PLL        25  /* node: NTP PLL control */
165 #define KERN_BOOTFILE       26  /* string: name of booted kernel */
166 #define KERN_MAXFILESPERPROC    27  /* int: max open files per proc */
167 #define KERN_MAXPROCPERUID  28  /* int: max processes per uid */
168 #define KERN_DUMPDEV        29  /* struct cdev *: device to dump on */
169 #define KERN_IPC        30  /* node: anything related to IPC */
170 #define KERN_DUMMY      31  /* unused */
171 #define KERN_PS_STRINGS     32  /* int: address of PS_STRINGS */
172 #define KERN_USRSTACK       33  /* int: address of USRSTACK */
173 #define KERN_LOGSIGEXIT     34  /* int: do we log sigexit procs? */
174 #define KERN_IOV_MAX        35  /* int: value of UIO_MAXIOV */
175 #define KERN_HOSTUUID       36  /* string: host UUID identifier */
176 #define KERN_ARND       37  /* int: from arc4rand() */
177 /*
178  * KERN_PROC subtypes
179  */
180 #define KERN_PROC_ALL       0   /* everything */
181 #define KERN_PROC_PID       1   /* by process id */
182 #define KERN_PROC_PGRP      2   /* by process group id */
183 #define KERN_PROC_SESSION   3   /* by session of pid */
184 #define KERN_PROC_TTY       4   /* by controlling tty */
185 #define KERN_PROC_UID       5   /* by effective uid */
186 #define KERN_PROC_RUID      6   /* by real uid */
187 #define KERN_PROC_ARGS      7   /* get/set arguments/proctitle */
188 #define KERN_PROC_PROC      8   /* only return procs */
189 #define KERN_PROC_SV_NAME   9   /* get syscall vector name */
190 #define KERN_PROC_RGID      10  /* by real group id */
191 #define KERN_PROC_GID       11  /* by effective group id */
192 #define KERN_PROC_PATHNAME  12  /* path to executable */
193 #define KERN_PROC_OVMMAP    13  /* Old VM map entries for process */
194 #define KERN_PROC_OFILEDESC 14  /* Old file descriptors for process */
195 #define KERN_PROC_KSTACK    15  /* Kernel stacks for process */
196 #define KERN_PROC_INC_THREAD    0x10    /*
197                      * modifier for pid, pgrp, tty,
198                      * uid, ruid, gid, rgid and proc
199                      * This effectively uses 16-31
200                      */
201 #define KERN_PROC_VMMAP     32  /* VM map entries for process */
202 #define KERN_PROC_FILEDESC  33  /* File descriptors for process */
203 #define KERN_PROC_GROUPS    34  /* process groups */
204 #define KERN_PROC_ENV       35  /* get environment */
205 #define KERN_PROC_AUXV      36  /* get ELF auxiliary vector */
206 #define KERN_PROC_RLIMIT    37  /* process resource limits */
207 #define KERN_PROC_PS_STRINGS    38  /* get ps_strings location */
208 #define KERN_PROC_UMASK     39  /* process umask */
209 #define KERN_PROC_OSREL     40  /* osreldate for process binary */
210 #define KERN_PROC_SIGTRAMP  41  /* signal trampoline location */
211 #define KERN_PROC_CWD       42  /* process current working directory */
212 #define KERN_PROC_NFDS      43  /* number of open file descriptors */
213 
214 /*
215  * KERN_IPC identifiers
216  */
217 #define KIPC_MAXSOCKBUF     1   /* int: max size of a socket buffer */
218 #define KIPC_SOCKBUF_WASTE  2   /* int: wastage factor in sockbuf */
219 #define KIPC_SOMAXCONN      3   /* int: max length of connection q */
220 #define KIPC_MAX_LINKHDR    4   /* int: max length of link header */
221 #define KIPC_MAX_PROTOHDR   5   /* int: max length of network header */
222 #define KIPC_MAX_HDR        6   /* int: max total length of headers */
223 #define KIPC_MAX_DATALEN    7   /* int: max length of data? */
224 
225 /*
226  * CTL_HW identifiers
227  */
228 #define HW_MACHINE   1      /* string: machine class */
229 #define HW_MODEL     2      /* string: specific machine model */
230 #define HW_NCPU      3      /* int: number of cpus */
231 #define HW_BYTEORDER     4      /* int: machine byte order */
232 #define HW_PHYSMEM   5      /* int: total memory */
233 #define HW_USERMEM   6      /* int: non-kernel memory */
234 #define HW_PAGESIZE  7      /* int: software page size */
235 #define HW_DISKNAMES     8      /* strings: disk drive names */
236 #define HW_DISKSTATS     9      /* struct: diskstats[] */
237 #define HW_FLOATINGPT   10      /* int: has HW floating point? */
238 #define HW_MACHINE_ARCH 11      /* string: machine architecture */
239 #define HW_REALMEM  12      /* int: 'real' memory */
240 
241 /*
242  * CTL_USER definitions
243  */
244 #define USER_CS_PATH         1  /* string: _CS_PATH */
245 #define USER_BC_BASE_MAX     2  /* int: BC_BASE_MAX */
246 #define USER_BC_DIM_MAX      3  /* int: BC_DIM_MAX */
247 #define USER_BC_SCALE_MAX    4  /* int: BC_SCALE_MAX */
248 #define USER_BC_STRING_MAX   5  /* int: BC_STRING_MAX */
249 #define USER_COLL_WEIGHTS_MAX    6  /* int: COLL_WEIGHTS_MAX */
250 #define USER_EXPR_NEST_MAX   7  /* int: EXPR_NEST_MAX */
251 #define USER_LINE_MAX        8  /* int: LINE_MAX */
252 #define USER_RE_DUP_MAX      9  /* int: RE_DUP_MAX */
253 #define USER_POSIX2_VERSION 10  /* int: POSIX2_VERSION */
254 #define USER_POSIX2_C_BIND  11  /* int: POSIX2_C_BIND */
255 #define USER_POSIX2_C_DEV   12  /* int: POSIX2_C_DEV */
256 #define USER_POSIX2_CHAR_TERM   13  /* int: POSIX2_CHAR_TERM */
257 #define USER_POSIX2_FORT_DEV    14  /* int: POSIX2_FORT_DEV */
258 #define USER_POSIX2_FORT_RUN    15  /* int: POSIX2_FORT_RUN */
259 #define USER_POSIX2_LOCALEDEF   16  /* int: POSIX2_LOCALEDEF */
260 #define USER_POSIX2_SW_DEV  17  /* int: POSIX2_SW_DEV */
261 #define USER_POSIX2_UPE     18  /* int: POSIX2_UPE */
262 #define USER_STREAM_MAX     19  /* int: POSIX2_STREAM_MAX */
263 #define USER_TZNAME_MAX     20  /* int: POSIX2_TZNAME_MAX */
264 
265 #define CTL_P1003_1B_ASYNCHRONOUS_IO        1   /* boolean */
266 #define CTL_P1003_1B_MAPPED_FILES       2   /* boolean */
267 #define CTL_P1003_1B_MEMLOCK            3   /* boolean */
268 #define CTL_P1003_1B_MEMLOCK_RANGE      4   /* boolean */
269 #define CTL_P1003_1B_MEMORY_PROTECTION      5   /* boolean */
270 #define CTL_P1003_1B_MESSAGE_PASSING        6   /* boolean */
271 #define CTL_P1003_1B_PRIORITIZED_IO     7   /* boolean */
272 #define CTL_P1003_1B_PRIORITY_SCHEDULING    8   /* boolean */
273 #define CTL_P1003_1B_REALTIME_SIGNALS       9   /* boolean */
274 #define CTL_P1003_1B_SEMAPHORES         10  /* boolean */
275 #define CTL_P1003_1B_FSYNC          11  /* boolean */
276 #define CTL_P1003_1B_SHARED_MEMORY_OBJECTS  12  /* boolean */
277 #define CTL_P1003_1B_SYNCHRONIZED_IO        13  /* boolean */
278 #define CTL_P1003_1B_TIMERS         14  /* boolean */
279 #define CTL_P1003_1B_AIO_LISTIO_MAX     15  /* int */
280 #define CTL_P1003_1B_AIO_MAX            16  /* int */
281 #define CTL_P1003_1B_AIO_PRIO_DELTA_MAX     17  /* int */
282 #define CTL_P1003_1B_DELAYTIMER_MAX     18  /* int */
283 #define CTL_P1003_1B_MQ_OPEN_MAX        19  /* int */
284 #define CTL_P1003_1B_PAGESIZE           20  /* int */
285 #define CTL_P1003_1B_RTSIG_MAX          21  /* int */
286 #define CTL_P1003_1B_SEM_NSEMS_MAX      22  /* int */
287 #define CTL_P1003_1B_SEM_VALUE_MAX      23  /* int */
288 #define CTL_P1003_1B_SIGQUEUE_MAX       24  /* int */
289 #define CTL_P1003_1B_TIMER_MAX          25  /* int */
290 
291 #define CTL_P1003_1B_MAXID      26
292 
293 int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
294 int sysctlbyname(const char *, void *, size_t *, const void *, size_t);
295 int sysctlnametomib(const char *, int *, size_t *);
296 
297 #endif
298