internal.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* Internal procfs definitions
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/proc_fs.h>
  12. #include <linux/proc_ns.h>
  13. #include <linux/refcount.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/atomic.h>
  16. #include <linux/binfmts.h>
  17. #include <linux/sched/coredump.h>
  18. #include <linux/sched/task.h>
  19. struct ctl_table_header;
  20. struct mempolicy;
  21. /*
  22. * This is not completely implemented yet. The idea is to
  23. * create an in-memory tree (like the actual /proc filesystem
  24. * tree) of these proc_dir_entries, so that we can dynamically
  25. * add new files to /proc.
  26. *
  27. * parent/subdir are used for the directory structure (every /proc file has a
  28. * parent, but "subdir" is empty for all non-directory entries).
  29. * subdir_node is used to build the rb tree "subdir" of the parent.
  30. */
  31. struct proc_dir_entry {
  32. /*
  33. * number of callers into module in progress;
  34. * negative -> it's going away RSN
  35. */
  36. atomic_t in_use;
  37. refcount_t refcnt;
  38. struct list_head pde_openers; /* who did ->open, but not ->release */
  39. /* protects ->pde_openers and all struct pde_opener instances */
  40. spinlock_t pde_unload_lock;
  41. struct completion *pde_unload_completion;
  42. const struct inode_operations *proc_iops;
  43. const struct file_operations *proc_fops;
  44. union {
  45. const struct seq_operations *seq_ops;
  46. int (*single_show)(struct seq_file *, void *);
  47. };
  48. proc_write_t write;
  49. void *data;
  50. unsigned int state_size;
  51. unsigned int low_ino;
  52. nlink_t nlink;
  53. kuid_t uid;
  54. kgid_t gid;
  55. loff_t size;
  56. struct proc_dir_entry *parent;
  57. struct rb_root subdir;
  58. struct rb_node subdir_node;
  59. char *name;
  60. umode_t mode;
  61. u8 namelen;
  62. char inline_name[];
  63. } __randomize_layout;
  64. #define OFFSETOF_PDE_NAME offsetof(struct proc_dir_entry, inline_name)
  65. #define SIZEOF_PDE_SLOT \
  66. (OFFSETOF_PDE_NAME + 34 <= 64 ? 64 : \
  67. OFFSETOF_PDE_NAME + 34 <= 128 ? 128 : \
  68. OFFSETOF_PDE_NAME + 34 <= 192 ? 192 : \
  69. OFFSETOF_PDE_NAME + 34 <= 256 ? 256 : \
  70. OFFSETOF_PDE_NAME + 34 <= 512 ? 512 : \
  71. 0)
  72. #define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE_SLOT - OFFSETOF_PDE_NAME)
  73. extern struct kmem_cache *proc_dir_entry_cache;
  74. void pde_free(struct proc_dir_entry *pde);
  75. union proc_op {
  76. int (*proc_get_link)(struct dentry *, struct path *);
  77. int (*proc_show)(struct seq_file *m,
  78. struct pid_namespace *ns, struct pid *pid,
  79. struct task_struct *task);
  80. };
  81. struct proc_inode {
  82. struct pid *pid;
  83. unsigned int fd;
  84. union proc_op op;
  85. struct proc_dir_entry *pde;
  86. struct ctl_table_header *sysctl;
  87. struct ctl_table *sysctl_entry;
  88. struct hlist_node sysctl_inodes;
  89. const struct proc_ns_operations *ns_ops;
  90. struct inode vfs_inode;
  91. } __randomize_layout;
  92. /*
  93. * General functions
  94. */
  95. static inline struct proc_inode *PROC_I(const struct inode *inode)
  96. {
  97. return container_of(inode, struct proc_inode, vfs_inode);
  98. }
  99. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  100. {
  101. return PROC_I(inode)->pde;
  102. }
  103. static inline void *__PDE_DATA(const struct inode *inode)
  104. {
  105. return PDE(inode)->data;
  106. }
  107. static inline struct pid *proc_pid(struct inode *inode)
  108. {
  109. return PROC_I(inode)->pid;
  110. }
  111. static inline struct task_struct *get_proc_task(struct inode *inode)
  112. {
  113. return get_pid_task(proc_pid(inode), PIDTYPE_PID);
  114. }
  115. void task_dump_owner(struct task_struct *task, umode_t mode,
  116. kuid_t *ruid, kgid_t *rgid);
  117. unsigned name_to_int(const struct qstr *qstr);
  118. /*
  119. * Offset of the first process in the /proc root directory..
  120. */
  121. #define FIRST_PROCESS_ENTRY 256
  122. /* Worst case buffer size needed for holding an integer. */
  123. #define PROC_NUMBUF 13
  124. /*
  125. * array.c
  126. */
  127. extern const struct file_operations proc_tid_children_operations;
  128. extern void proc_task_name(struct seq_file *m, struct task_struct *p,
  129. bool escape);
  130. extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
  131. struct pid *, struct task_struct *);
  132. extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,
  133. struct pid *, struct task_struct *);
  134. extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
  135. struct pid *, struct task_struct *);
  136. extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
  137. struct pid *, struct task_struct *);
  138. /*
  139. * base.c
  140. */
  141. extern const struct dentry_operations pid_dentry_operations;
  142. extern int pid_getattr(const struct path *, struct kstat *, u32, unsigned int);
  143. extern int proc_setattr(struct dentry *, struct iattr *);
  144. extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *, umode_t);
  145. extern void pid_update_inode(struct task_struct *, struct inode *);
  146. extern int pid_delete_dentry(const struct dentry *);
  147. extern int proc_pid_readdir(struct file *, struct dir_context *);
  148. extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned int);
  149. extern loff_t mem_lseek(struct file *, loff_t, int);
  150. /* Lookups */
  151. typedef struct dentry *instantiate_t(struct dentry *,
  152. struct task_struct *, const void *);
  153. bool proc_fill_cache(struct file *, struct dir_context *, const char *, unsigned int,
  154. instantiate_t, struct task_struct *, const void *);
  155. /*
  156. * generic.c
  157. */
  158. struct proc_dir_entry *proc_create_reg(const char *name, umode_t mode,
  159. struct proc_dir_entry **parent, void *data);
  160. struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
  161. struct proc_dir_entry *dp);
  162. extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
  163. struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
  164. extern int proc_readdir(struct file *, struct dir_context *);
  165. int proc_readdir_de(struct file *, struct dir_context *, struct proc_dir_entry *);
  166. static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
  167. {
  168. refcount_inc(&pde->refcnt);
  169. return pde;
  170. }
  171. extern void pde_put(struct proc_dir_entry *);
  172. static inline bool is_empty_pde(const struct proc_dir_entry *pde)
  173. {
  174. return S_ISDIR(pde->mode) && !pde->proc_iops;
  175. }
  176. extern ssize_t proc_simple_write(struct file *, const char __user *, size_t, loff_t *);
  177. /*
  178. * inode.c
  179. */
  180. struct pde_opener {
  181. struct file *file;
  182. struct list_head lh;
  183. bool closing;
  184. struct completion *c;
  185. } __randomize_layout;
  186. extern const struct inode_operations proc_link_inode_operations;
  187. extern const struct inode_operations proc_pid_link_inode_operations;
  188. void proc_init_kmemcache(void);
  189. void set_proc_pid_nlink(void);
  190. extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
  191. extern int proc_fill_super(struct super_block *, void *data, int flags);
  192. extern void proc_entry_rundown(struct proc_dir_entry *);
  193. /*
  194. * proc_namespaces.c
  195. */
  196. extern const struct inode_operations proc_ns_dir_inode_operations;
  197. extern const struct file_operations proc_ns_dir_operations;
  198. /*
  199. * proc_net.c
  200. */
  201. extern const struct file_operations proc_net_operations;
  202. extern const struct inode_operations proc_net_inode_operations;
  203. #ifdef CONFIG_NET
  204. extern int proc_net_init(void);
  205. #else
  206. static inline int proc_net_init(void) { return 0; }
  207. #endif
  208. /*
  209. * proc_self.c
  210. */
  211. extern int proc_setup_self(struct super_block *);
  212. /*
  213. * proc_thread_self.c
  214. */
  215. extern int proc_setup_thread_self(struct super_block *);
  216. extern void proc_thread_self_init(void);
  217. /*
  218. * proc_sysctl.c
  219. */
  220. #ifdef CONFIG_PROC_SYSCTL
  221. extern int proc_sys_init(void);
  222. extern void proc_sys_evict_inode(struct inode *inode,
  223. struct ctl_table_header *head);
  224. #else
  225. static inline void proc_sys_init(void) { }
  226. static inline void proc_sys_evict_inode(struct inode *inode,
  227. struct ctl_table_header *head) { }
  228. #endif
  229. /*
  230. * proc_tty.c
  231. */
  232. #ifdef CONFIG_TTY
  233. extern void proc_tty_init(void);
  234. #else
  235. static inline void proc_tty_init(void) {}
  236. #endif
  237. /*
  238. * root.c
  239. */
  240. extern struct proc_dir_entry proc_root;
  241. extern int proc_parse_options(char *options, struct pid_namespace *pid);
  242. extern void proc_self_init(void);
  243. extern int proc_remount(struct super_block *, int *, char *);
  244. /*
  245. * task_[no]mmu.c
  246. */
  247. struct mem_size_stats;
  248. struct proc_maps_private {
  249. struct inode *inode;
  250. struct task_struct *task;
  251. struct mm_struct *mm;
  252. struct mem_size_stats *rollup;
  253. #ifdef CONFIG_MMU
  254. struct vm_area_struct *tail_vma;
  255. #endif
  256. #ifdef CONFIG_NUMA
  257. struct mempolicy *task_mempolicy;
  258. #endif
  259. } __randomize_layout;
  260. struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
  261. extern const struct file_operations proc_pid_maps_operations;
  262. extern const struct file_operations proc_tid_maps_operations;
  263. extern const struct file_operations proc_pid_numa_maps_operations;
  264. extern const struct file_operations proc_tid_numa_maps_operations;
  265. extern const struct file_operations proc_pid_smaps_operations;
  266. extern const struct file_operations proc_pid_smaps_rollup_operations;
  267. extern const struct file_operations proc_tid_smaps_operations;
  268. extern const struct file_operations proc_clear_refs_operations;
  269. extern const struct file_operations proc_pagemap_operations;
  270. extern unsigned long task_vsize(struct mm_struct *);
  271. extern unsigned long task_statm(struct mm_struct *,
  272. unsigned long *, unsigned long *,
  273. unsigned long *, unsigned long *);
  274. extern void task_mem(struct seq_file *, struct mm_struct *);