Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * sysctl.h: General linux system control interface
0004  *
0005  * Begun 24 March 1995, Stephen Tweedie
0006  *
0007  ****************************************************************
0008  ****************************************************************
0009  **
0010  **  WARNING:
0011  **  The values in this file are exported to user space via 
0012  **  the sysctl() binary interface.  Do *NOT* change the
0013  **  numbering of any existing values here, and do not change
0014  **  any numbers within any one set of values.  If you have to
0015  **  redefine an existing interface, use a new number for it.
0016  **  The kernel will then return -ENOTDIR to any application using
0017  **  the old binary interface.
0018  **
0019  ****************************************************************
0020  ****************************************************************
0021  */
0022 #ifndef _LINUX_SYSCTL_H
0023 #define _LINUX_SYSCTL_H
0024 
0025 #include <linux/list.h>
0026 #include <linux/rcupdate.h>
0027 #include <linux/wait.h>
0028 #include <linux/rbtree.h>
0029 #include <linux/uidgid.h>
0030 #include <uapi/linux/sysctl.h>
0031 
0032 /* For the /proc/sys support */
0033 struct completion;
0034 struct ctl_table;
0035 struct nsproxy;
0036 struct ctl_table_root;
0037 struct ctl_table_header;
0038 struct ctl_dir;
0039 
0040 /* Keep the same order as in fs/proc/proc_sysctl.c */
0041 #define SYSCTL_ZERO         ((void *)&sysctl_vals[0])
0042 #define SYSCTL_ONE          ((void *)&sysctl_vals[1])
0043 #define SYSCTL_TWO          ((void *)&sysctl_vals[2])
0044 #define SYSCTL_THREE            ((void *)&sysctl_vals[3])
0045 #define SYSCTL_FOUR         ((void *)&sysctl_vals[4])
0046 #define SYSCTL_ONE_HUNDRED      ((void *)&sysctl_vals[5])
0047 #define SYSCTL_TWO_HUNDRED      ((void *)&sysctl_vals[6])
0048 #define SYSCTL_ONE_THOUSAND     ((void *)&sysctl_vals[7])
0049 #define SYSCTL_THREE_THOUSAND       ((void *)&sysctl_vals[8])
0050 #define SYSCTL_INT_MAX          ((void *)&sysctl_vals[9])
0051 
0052 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
0053 #define SYSCTL_MAXOLDUID        ((void *)&sysctl_vals[10])
0054 #define SYSCTL_NEG_ONE          ((void *)&sysctl_vals[11])
0055 
0056 extern const int sysctl_vals[];
0057 
0058 #define SYSCTL_LONG_ZERO    ((void *)&sysctl_long_vals[0])
0059 #define SYSCTL_LONG_ONE     ((void *)&sysctl_long_vals[1])
0060 #define SYSCTL_LONG_MAX     ((void *)&sysctl_long_vals[2])
0061 
0062 extern const unsigned long sysctl_long_vals[];
0063 
0064 typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
0065         size_t *lenp, loff_t *ppos);
0066 
0067 int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *);
0068 int proc_dobool(struct ctl_table *table, int write, void *buffer,
0069         size_t *lenp, loff_t *ppos);
0070 int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *);
0071 int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
0072 int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
0073 int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
0074         size_t *lenp, loff_t *ppos);
0075 int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer,
0076             size_t *lenp, loff_t *ppos);
0077 int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
0078 int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
0079         void *buffer, size_t *lenp, loff_t *ppos);
0080 int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
0081         loff_t *);
0082 int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *,
0083         loff_t *);
0084 int proc_doulongvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
0085 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int, void *,
0086         size_t *, loff_t *);
0087 int proc_do_large_bitmap(struct ctl_table *, int, void *, size_t *, loff_t *);
0088 int proc_do_static_key(struct ctl_table *table, int write, void *buffer,
0089         size_t *lenp, loff_t *ppos);
0090 
0091 /*
0092  * Register a set of sysctl names by calling register_sysctl_table
0093  * with an initialised array of struct ctl_table's.  An entry with 
0094  * NULL procname terminates the table.  table->de will be
0095  * set up by the registration and need not be initialised in advance.
0096  *
0097  * sysctl names can be mirrored automatically under /proc/sys.  The
0098  * procname supplied controls /proc naming.
0099  *
0100  * The table's mode will be honoured for proc-fs access.
0101  *
0102  * Leaf nodes in the sysctl tree will be represented by a single file
0103  * under /proc; non-leaf nodes will be represented by directories.  A
0104  * null procname disables /proc mirroring at this node.
0105  *
0106  * The data and maxlen fields of the ctl_table
0107  * struct enable minimal validation of the values being written to be
0108  * performed, and the mode field allows minimal authentication.
0109  * 
0110  * There must be a proc_handler routine for any terminal nodes
0111  * mirrored under /proc/sys (non-terminals are handled by a built-in
0112  * directory handler).  Several default handlers are available to
0113  * cover common cases.
0114  */
0115 
0116 /* Support for userspace poll() to watch for changes */
0117 struct ctl_table_poll {
0118     atomic_t event;
0119     wait_queue_head_t wait;
0120 };
0121 
0122 static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
0123 {
0124     return (void *)(unsigned long)atomic_read(&poll->event);
0125 }
0126 
0127 #define __CTL_TABLE_POLL_INITIALIZER(name) {                \
0128     .event = ATOMIC_INIT(0),                    \
0129     .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
0130 
0131 #define DEFINE_CTL_TABLE_POLL(name)                 \
0132     struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
0133 
0134 /* A sysctl table is an array of struct ctl_table: */
0135 struct ctl_table {
0136     const char *procname;       /* Text ID for /proc/sys, or zero */
0137     void *data;
0138     int maxlen;
0139     umode_t mode;
0140     struct ctl_table *child;    /* Deprecated */
0141     proc_handler *proc_handler; /* Callback for text formatting */
0142     struct ctl_table_poll *poll;
0143     void *extra1;
0144     void *extra2;
0145 } __randomize_layout;
0146 
0147 struct ctl_node {
0148     struct rb_node node;
0149     struct ctl_table_header *header;
0150 };
0151 
0152 /* struct ctl_table_header is used to maintain dynamic lists of
0153    struct ctl_table trees. */
0154 struct ctl_table_header {
0155     union {
0156         struct {
0157             struct ctl_table *ctl_table;
0158             int used;
0159             int count;
0160             int nreg;
0161         };
0162         struct rcu_head rcu;
0163     };
0164     struct completion *unregistering;
0165     struct ctl_table *ctl_table_arg;
0166     struct ctl_table_root *root;
0167     struct ctl_table_set *set;
0168     struct ctl_dir *parent;
0169     struct ctl_node *node;
0170     struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
0171 };
0172 
0173 struct ctl_dir {
0174     /* Header must be at the start of ctl_dir */
0175     struct ctl_table_header header;
0176     struct rb_root root;
0177 };
0178 
0179 struct ctl_table_set {
0180     int (*is_seen)(struct ctl_table_set *);
0181     struct ctl_dir dir;
0182 };
0183 
0184 struct ctl_table_root {
0185     struct ctl_table_set default_set;
0186     struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
0187     void (*set_ownership)(struct ctl_table_header *head,
0188                   struct ctl_table *table,
0189                   kuid_t *uid, kgid_t *gid);
0190     int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
0191 };
0192 
0193 /* struct ctl_path describes where in the hierarchy a table is added */
0194 struct ctl_path {
0195     const char *procname;
0196 };
0197 
0198 #ifdef CONFIG_SYSCTL
0199 
0200 #define DECLARE_SYSCTL_BASE(_name, _table)              \
0201 static struct ctl_table _name##_base_table[] = {            \
0202     {                               \
0203         .procname   = #_name,               \
0204         .mode       = 0555,                 \
0205         .child      = _table,               \
0206     },                              \
0207     { },                                \
0208 }
0209 
0210 extern int __register_sysctl_base(struct ctl_table *base_table);
0211 
0212 #define register_sysctl_base(_name) __register_sysctl_base(_name##_base_table)
0213 
0214 void proc_sys_poll_notify(struct ctl_table_poll *poll);
0215 
0216 extern void setup_sysctl_set(struct ctl_table_set *p,
0217     struct ctl_table_root *root,
0218     int (*is_seen)(struct ctl_table_set *));
0219 extern void retire_sysctl_set(struct ctl_table_set *set);
0220 
0221 struct ctl_table_header *__register_sysctl_table(
0222     struct ctl_table_set *set,
0223     const char *path, struct ctl_table *table);
0224 struct ctl_table_header *__register_sysctl_paths(
0225     struct ctl_table_set *set,
0226     const struct ctl_path *path, struct ctl_table *table);
0227 struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
0228 struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
0229 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
0230                         struct ctl_table *table);
0231 
0232 void unregister_sysctl_table(struct ctl_table_header * table);
0233 
0234 extern int sysctl_init_bases(void);
0235 extern void __register_sysctl_init(const char *path, struct ctl_table *table,
0236                  const char *table_name);
0237 #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
0238 extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
0239 
0240 void do_sysctl_args(void);
0241 int do_proc_douintvec(struct ctl_table *table, int write,
0242               void *buffer, size_t *lenp, loff_t *ppos,
0243               int (*conv)(unsigned long *lvalp,
0244                   unsigned int *valp,
0245                   int write, void *data),
0246               void *data);
0247 
0248 extern int pwrsw_enabled;
0249 extern int unaligned_enabled;
0250 extern int unaligned_dump_stack;
0251 extern int no_unaligned_warning;
0252 
0253 extern struct ctl_table sysctl_mount_point[];
0254 
0255 #else /* CONFIG_SYSCTL */
0256 
0257 #define DECLARE_SYSCTL_BASE(_name, _table)
0258 
0259 static inline int __register_sysctl_base(struct ctl_table *base_table)
0260 {
0261     return 0;
0262 }
0263 
0264 #define register_sysctl_base(table) __register_sysctl_base(table)
0265 
0266 static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
0267 {
0268     return NULL;
0269 }
0270 
0271 static inline void register_sysctl_init(const char *path, struct ctl_table *table)
0272 {
0273 }
0274 
0275 static inline struct ctl_table_header *register_sysctl_mount_point(const char *path)
0276 {
0277     return NULL;
0278 }
0279 
0280 static inline struct ctl_table_header *register_sysctl_paths(
0281             const struct ctl_path *path, struct ctl_table *table)
0282 {
0283     return NULL;
0284 }
0285 
0286 static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
0287 {
0288     return NULL;
0289 }
0290 
0291 static inline void unregister_sysctl_table(struct ctl_table_header * table)
0292 {
0293 }
0294 
0295 static inline void setup_sysctl_set(struct ctl_table_set *p,
0296     struct ctl_table_root *root,
0297     int (*is_seen)(struct ctl_table_set *))
0298 {
0299 }
0300 
0301 static inline void do_sysctl_args(void)
0302 {
0303 }
0304 #endif /* CONFIG_SYSCTL */
0305 
0306 int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
0307         size_t *lenp, loff_t *ppos);
0308 
0309 #endif /* _LINUX_SYSCTL_H */