internal.h 8.3 KB

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