50 #include <asm/uaccess.h>
52 #include <linux/errno.h>
53 #include <linux/time.h>
55 #include <linux/stat.h>
58 #include <linux/capability.h>
61 #include <linux/string.h>
70 #include <linux/resource.h>
71 #include <linux/module.h>
74 #include <linux/ptrace.h>
78 #include <linux/audit.h>
79 #include <linux/poll.h>
81 #include <linux/oom.h>
82 #include <linux/elf.h>
86 #include <linux/slab.h>
88 #ifdef CONFIG_HARDWALL
89 #include <asm/hardwall.h>
114 #define NOD(NAME, MODE, IOP, FOP, OP) { \
116 .len = sizeof(NAME) - 1, \
123 #define DIR(NAME, MODE, iops, fops) \
124 NOD(NAME, (S_IFDIR|(MODE)), &iops, &fops, {} )
125 #define LNK(NAME, get_link) \
126 NOD(NAME, (S_IFLNK|S_IRWXUGO), \
127 &proc_pid_link_inode_operations, NULL, \
128 { .proc_get_link = get_link } )
129 #define REG(NAME, MODE, fops) \
130 NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {})
131 #define INF(NAME, MODE, read) \
132 NOD(NAME, (S_IFREG|(MODE)), \
133 NULL, &proc_info_file_operations, \
134 { .proc_read = read } )
135 #define ONE(NAME, MODE, show) \
136 NOD(NAME, (S_IFREG|(MODE)), \
137 NULL, &proc_single_file_operations, \
138 { .proc_show = show } )
151 for (i = 0; i <
n; ++
i) {
165 get_fs_root(task->
fs, root);
180 get_fs_pwd(task->
fs, path);
184 put_task_struct(task);
189 static int proc_root_link(
struct dentry *dentry,
struct path *path)
195 result = get_task_root(task, path);
196 put_task_struct(task);
220 if (res > 0 && buffer[res-1] !=
'\0' && len <
PAGE_SIZE) {
238 static int proc_pid_auxv(
struct task_struct *task,
char *buffer)
241 int res = PTR_ERR(mm);
242 if (mm && !IS_ERR(mm)) {
243 unsigned int nwords = 0;
257 #ifdef CONFIG_KALLSYMS
262 static int proc_pid_wchan(
struct task_struct *task,
char *buffer)
273 return sprintf(buffer,
"%lu", wchan);
275 return sprintf(buffer,
"%s", symname);
296 #ifdef CONFIG_STACKTRACE
298 #define MAX_STACK_TRACE_DEPTH 64
303 struct stack_trace
trace;
312 trace.nr_entries = 0;
317 err = lock_trace(task);
321 for (i = 0; i <
trace.nr_entries; i++) {
323 (
void *)entries[i], (
void *)entries[i]);
333 #ifdef CONFIG_SCHEDSTATS
337 static int proc_pid_schedstat(
struct task_struct *task,
char *buffer)
339 return sprintf(buffer,
"%llu %llu %lu\n",
340 (
unsigned long long)task->
se.sum_exec_runtime,
341 (
unsigned long long)task->sched_info.run_delay,
342 task->sched_info.pcount);
346 #ifdef CONFIG_LATENCYTOP
347 static int lstats_show_proc(
struct seq_file *m,
void *
v)
355 seq_puts(m,
"Latency Top version : v0.1\n");
356 for (i = 0; i < 32; i++) {
357 struct latency_record *
lr = &task->latency_record[
i];
358 if (lr->backtrace[0]) {
361 lr->
count, lr->time, lr->max);
362 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
363 unsigned long bt = lr->backtrace[
q];
374 put_task_struct(task);
378 static int lstats_open(
struct inode *inode,
struct file *
file)
386 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
391 put_task_struct(task);
399 .write = lstats_write,
406 static int proc_oom_score(
struct task_struct *task,
char *buffer)
409 unsigned long points = 0;
416 return sprintf(buffer,
"%lu\n", points);
434 [
RLIMIT_AS] = {
"Max address space",
"bytes"},
444 static int proc_pid_limits(
struct task_struct *task,
char *buffer)
453 if (!lock_task_sighand(task, &flags))
456 unlock_task_sighand(task, &flags);
461 count +=
sprintf(&bufptr[count],
"%-25s %-20s %-20s %-10s\n",
462 "Limit",
"Soft Limit",
"Hard Limit",
"Units");
466 count +=
sprintf(&bufptr[count],
"%-25s %-20s ",
467 lnames[i].
name,
"unlimited");
469 count +=
sprintf(&bufptr[count],
"%-25s %-20lu ",
473 count +=
sprintf(&bufptr[count],
"%-20s ",
"unlimited");
475 count +=
sprintf(&bufptr[count],
"%-20lu ",
479 count +=
sprintf(&bufptr[count],
"%-10s\n",
482 count +=
sprintf(&bufptr[count],
"\n");
488 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
489 static int proc_pid_syscall(
struct task_struct *task,
char *buffer)
493 int res = lock_trace(task);
498 res =
sprintf(buffer,
"running\n");
500 res =
sprintf(buffer,
"%ld 0x%lx 0x%lx\n", nr, sp, pc);
503 "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
505 args[0], args[1], args[2], args[3], args[4], args[5],
517 static int proc_fd_access_allowed(
struct inode *inode)
525 task = get_proc_task(inode);
528 put_task_struct(task);
536 struct inode *inode = dentry->
d_inode;
546 attr->
ia_size != i_size_read(inode)) {
553 mark_inode_dirty(inode);
573 static int proc_pid_permission(
struct inode *inode,
int mask)
579 task = get_proc_task(inode);
582 has_perms = has_pid_permissions(pid, task, 1);
583 put_task_struct(task);
607 #define PROC_BLOCK_SIZE (3*1024)
609 static ssize_t proc_info_read(
struct file * file,
char __user * buf,
610 size_t count, loff_t *ppos)
612 struct inode * inode = file->
f_path.dentry->d_inode;
628 length = PROC_I(inode)->op.proc_read(task, (
char*)page);
634 put_task_struct(task);
640 .read = proc_info_read,
644 static int proc_single_show(
struct seq_file *m,
void *v)
646 struct inode *inode = m->
private;
652 ns = inode->
i_sb->s_fs_info;
653 pid = proc_pid(inode);
658 ret = PROC_I(inode)->op.proc_show(m, ns, pid, task);
660 put_task_struct(task);
664 static int proc_single_open(
struct inode *inode,
struct file *filp)
670 .open = proc_single_open,
676 static int __mem_open(
struct inode *inode,
struct file *file,
unsigned int mode)
685 put_task_struct(task);
702 static int mem_open(
struct inode *inode,
struct file *file)
712 static ssize_t mem_rw(
struct file *file,
char __user *buf,
713 size_t count, loff_t *ppos,
int write)
716 unsigned long addr = *ppos;
764 static ssize_t mem_read(
struct file *file,
char __user *buf,
765 size_t count, loff_t *ppos)
767 return mem_rw(file, buf, count, ppos, 0);
770 static ssize_t mem_write(
struct file *file,
const char __user *buf,
771 size_t count, loff_t *ppos)
773 return mem_rw(file, (
char __user*)buf, count, ppos, 1);
792 static int mem_release(
struct inode *inode,
struct file *file)
805 .release = mem_release,
808 static int environ_open(
struct inode *inode,
struct file *file)
813 static ssize_t environ_read(
struct file *file,
char __user *buf,
814 size_t count, loff_t *ppos)
817 unsigned long src = *ppos;
832 size_t this_len, max_len;
841 this_len =
min(max_len, this_len);
870 .open = environ_open,
871 .read = environ_read,
873 .release = mem_release,
876 static ssize_t oom_adj_read(
struct file *file,
char __user *buf,
size_t count,
887 if (lock_task_sighand(task, &flags)) {
893 unlock_task_sighand(task, &flags);
895 put_task_struct(task);
896 len =
snprintf(buffer,
sizeof(buffer),
"%d\n", oom_adj);
900 static ssize_t oom_adj_write(
struct file *file,
const char __user *buf,
901 size_t count, loff_t *ppos)
909 memset(buffer, 0,
sizeof(buffer));
910 if (count >
sizeof(buffer) - 1)
911 count =
sizeof(
buffer) - 1;
917 err =
kstrtoint(strstrip(buffer), 0, &oom_adj);
926 task = get_proc_task(file->
f_path.dentry->d_inode);
938 if (!lock_task_sighand(task, &flags)) {
947 if (oom_adj == OOM_ADJUST_MAX)
952 if (oom_adj < task->
signal->oom_score_adj &&
962 printk_once(
KERN_WARNING "%s (%d): /proc/%d/oom_adj is deprecated, please use /proc/%d/oom_score_adj instead.\n",
966 task->
signal->oom_score_adj = oom_adj;
967 trace_oom_score_adj_update(task);
969 unlock_task_sighand(task, &flags);
972 put_task_struct(task);
974 return err < 0 ? err :
count;
978 .read = oom_adj_read,
979 .write = oom_adj_write,
983 static ssize_t oom_score_adj_read(
struct file *file,
char __user *buf,
984 size_t count, loff_t *ppos)
994 if (lock_task_sighand(task, &flags)) {
995 oom_score_adj = task->
signal->oom_score_adj;
996 unlock_task_sighand(task, &flags);
998 put_task_struct(task);
999 len =
snprintf(buffer,
sizeof(buffer),
"%d\n", oom_score_adj);
1003 static ssize_t oom_score_adj_write(
struct file *file,
const char __user *buf,
1004 size_t count, loff_t *ppos)
1008 unsigned long flags;
1012 memset(buffer, 0,
sizeof(buffer));
1013 if (count >
sizeof(buffer) - 1)
1014 count =
sizeof(
buffer) - 1;
1020 err =
kstrtoint(strstrip(buffer), 0, &oom_score_adj);
1029 task = get_proc_task(file->
f_path.dentry->d_inode);
1041 if (!lock_task_sighand(task, &flags)) {
1046 if (oom_score_adj < task->
signal->oom_score_adj_min &&
1052 task->
signal->oom_score_adj = oom_score_adj;
1054 task->
signal->oom_score_adj_min = oom_score_adj;
1055 trace_oom_score_adj_update(task);
1058 unlock_task_sighand(task, &flags);
1061 put_task_struct(task);
1063 return err < 0 ? err :
count;
1067 .read = oom_score_adj_read,
1068 .write = oom_score_adj_write,
1072 #ifdef CONFIG_AUDITSYSCALL
1073 #define TMPBUFLEN 21
1074 static ssize_t proc_loginuid_read(
struct file * file,
char __user * buf,
1075 size_t count, loff_t *ppos)
1077 struct inode * inode = file->
f_path.dentry->d_inode;
1086 audit_get_loginuid(task)));
1087 put_task_struct(task);
1091 static ssize_t proc_loginuid_write(
struct file * file,
const char __user * buf,
1092 size_t count, loff_t *ppos)
1094 struct inode * inode = file->
f_path.dentry->d_inode;
1129 if (!uid_valid(kloginuid)) {
1144 .
read = proc_loginuid_read,
1145 .write = proc_loginuid_write,
1149 static ssize_t proc_sessionid_read(
struct file * file,
char __user * buf,
1150 size_t count, loff_t *ppos)
1152 struct inode * inode = file->
f_path.dentry->d_inode;
1160 audit_get_sessionid(task));
1161 put_task_struct(task);
1166 .
read = proc_sessionid_read,
1171 #ifdef CONFIG_FAULT_INJECTION
1172 static ssize_t proc_fault_inject_read(
struct file * file,
char __user * buf,
1173 size_t count, loff_t *ppos)
1175 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
1182 make_it_fail = task->make_it_fail;
1183 put_task_struct(task);
1185 len =
snprintf(buffer,
sizeof(buffer),
"%i\n", make_it_fail);
1190 static ssize_t proc_fault_inject_write(
struct file * file,
1191 const char __user * buf,
size_t count, loff_t *ppos)
1199 memset(buffer, 0,
sizeof(buffer));
1200 if (count >
sizeof(buffer) - 1)
1201 count =
sizeof(
buffer) - 1;
1207 task = get_proc_task(file->f_dentry->d_inode);
1210 task->make_it_fail = make_it_fail;
1211 put_task_struct(task);
1217 .
read = proc_fault_inject_read,
1218 .write = proc_fault_inject_write,
1224 #ifdef CONFIG_SCHED_DEBUG
1228 static int sched_show(
struct seq_file *m,
void *v)
1230 struct inode *inode = m->
private;
1233 p = get_proc_task(inode);
1244 sched_write(
struct file *file,
const char __user *buf,
1245 size_t count, loff_t *
offset)
1247 struct inode *inode = file->
f_path.dentry->d_inode;
1250 p = get_proc_task(inode);
1260 static int sched_open(
struct inode *inode,
struct file *filp)
1268 .write = sched_write,
1275 #ifdef CONFIG_SCHED_AUTOGROUP
1279 static int sched_autogroup_show(
struct seq_file *m,
void *v)
1281 struct inode *inode = m->
private;
1284 p = get_proc_task(inode);
1287 proc_sched_autogroup_show_task(p, m);
1295 sched_autogroup_write(
struct file *file,
const char __user *buf,
1296 size_t count, loff_t *offset)
1298 struct inode *inode = file->
f_path.dentry->d_inode;
1304 memset(buffer, 0,
sizeof(buffer));
1305 if (count >
sizeof(buffer) - 1)
1306 count =
sizeof(
buffer) - 1;
1310 err =
kstrtoint(strstrip(buffer), 0, &nice);
1314 p = get_proc_task(inode);
1318 err = proc_sched_autogroup_set_nice(p, nice);
1327 static int sched_autogroup_open(
struct inode *inode,
struct file *filp)
1340 static const struct file_operations proc_pid_sched_autogroup_operations = {
1341 .
open = sched_autogroup_open,
1343 .write = sched_autogroup_write,
1350 static ssize_t comm_write(
struct file *file,
const char __user *buf,
1351 size_t count, loff_t *offset)
1353 struct inode *inode = file->
f_path.dentry->d_inode;
1357 memset(buffer, 0,
sizeof(buffer));
1358 if (count >
sizeof(buffer) - 1)
1359 count =
sizeof(
buffer) - 1;
1363 p = get_proc_task(inode);
1367 if (same_thread_group(
current, p))
1377 static int comm_show(
struct seq_file *m,
void *v)
1379 struct inode *inode = m->
private;
1382 p = get_proc_task(inode);
1395 static int comm_open(
struct inode *inode,
struct file *filp)
1403 .write = comm_write,
1408 static int proc_exe_link(
struct dentry *dentry,
struct path *exe_path)
1412 struct file *exe_file;
1414 task = get_proc_task(dentry->
d_inode);
1418 put_task_struct(task);
1424 *exe_path = exe_file->
f_path;
1432 static void *proc_pid_follow_link(
struct dentry *dentry,
struct nameidata *nd)
1434 struct inode *inode = dentry->
d_inode;
1439 if (!proc_fd_access_allowed(inode))
1442 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
1449 return ERR_PTR(error);
1452 static int do_proc_readlink(
struct path *path,
char __user *buffer,
int buflen)
1462 len = PTR_ERR(pathname);
1463 if (IS_ERR(pathname))
1476 static int proc_pid_readlink(
struct dentry * dentry,
char __user * buffer,
int buflen)
1479 struct inode *inode = dentry->
d_inode;
1483 if (!proc_fd_access_allowed(inode))
1486 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
1490 error = do_proc_readlink(&path, buffer, buflen);
1497 .readlink = proc_pid_readlink,
1498 .follow_link = proc_pid_follow_link,
1507 struct inode *
inode;
1521 inode->
i_op = &proc_def_inode_operations;
1530 if (task_dumpable(task)) {
1549 struct inode *inode = dentry->
d_inode;
1561 if (!has_pid_permissions(pid, task, 2)) {
1570 task_dumpable(task)) {
1599 struct inode *
inode;
1607 task = get_proc_task(inode);
1611 task_dumpable(task)) {
1623 put_task_struct(task);
1633 .d_delete = pid_delete_dentry,
1651 const char *
name,
int len,
1655 struct inode *
inode;
1669 child = instantiate(dir->
d_inode,
new, task, ptr);
1676 if (!child || IS_ERR(child) || !child->
d_inode)
1677 goto end_instantiate;
1681 type = inode->
i_mode >> 12;
1689 return filldir(dirent, name, len, filp->
f_pos, ino, type);
1692 #ifdef CONFIG_CHECKPOINT_RESTORE
1698 static int dname_to_vma_addr(
struct dentry *dentry,
1699 unsigned long *
start,
unsigned long *end)
1701 if (
sscanf(dentry->
d_name.name,
"%lx-%lx", start, end) != 2)
1707 static int map_files_d_revalidate(
struct dentry *dentry,
unsigned int flags)
1709 unsigned long vm_start, vm_end;
1710 bool exact_vma_exists =
false;
1714 struct inode *
inode;
1726 task = get_proc_task(inode);
1731 if (IS_ERR_OR_NULL(mm))
1734 if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) {
1736 exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end);
1742 if (exact_vma_exists) {
1743 if (task_dumpable(task)) {
1758 put_task_struct(task);
1769 .d_delete = pid_delete_dentry,
1772 static int proc_map_files_get_link(
struct dentry *dentry,
struct path *path)
1774 unsigned long vm_start, vm_end;
1781 task = get_proc_task(dentry->
d_inode);
1786 put_task_struct(task);
1790 rc = dname_to_vma_addr(dentry, &vm_start, &vm_end);
1795 vma = find_exact_vma(mm, vm_start, vm_end);
1809 struct map_files_info {
1812 unsigned char name[4*
sizeof(
long)+2];
1815 static struct dentry *
1816 proc_map_files_instantiate(
struct inode *dir,
struct dentry *dentry,
1821 struct inode *
inode;
1839 d_set_d_op(dentry, &tid_map_files_dentry_operations);
1840 d_add(dentry, inode);
1845 static struct dentry *proc_map_files_lookup(
struct inode *dir,
1846 struct dentry *dentry,
unsigned int flags)
1848 unsigned long vm_start, vm_end;
1854 result = ERR_PTR(-
EACCES);
1858 result = ERR_PTR(-
ENOENT);
1859 task = get_proc_task(dir);
1863 result = ERR_PTR(-
EACCES);
1867 result = ERR_PTR(-
ENOENT);
1868 if (dname_to_vma_addr(dentry, &vm_start, &vm_end))
1876 vma = find_exact_vma(mm, vm_start, vm_end);
1881 result = proc_map_files_instantiate(dir, dentry, task,
1882 (
void *)(
unsigned long)vma->
vm_file->f_mode);
1888 put_task_struct(task);
1894 .
lookup = proc_map_files_lookup,
1900 proc_map_files_readdir(
struct file *filp,
void *
dirent,
filldir_t filldir)
1902 struct dentry *dentry = filp->
f_path.dentry;
1903 struct inode *inode = dentry->
d_inode;
1915 task = get_proc_task(inode);
1924 switch (filp->
f_pos) {
1927 if (filldir(dirent,
".", 1, 0, ino,
DT_DIR) < 0)
1932 if (filldir(dirent,
"..", 2, 1, ino,
DT_DIR) < 0)
1937 unsigned long nr_files,
pos,
i;
1939 struct map_files_info
info;
1940 struct map_files_info *
p;
1959 for (vma = mm->
mmap, pos = 2; vma; vma = vma->
vm_next) {
1976 for (i = 0, vma = mm->
mmap, pos = 2; vma;
1980 if (++pos <= filp->f_pos)
1985 sizeof(
info.name),
"%lx-%lx",
1993 for (i = 0; i < nr_files; i++) {
1997 proc_map_files_instantiate,
1999 (
void *)(
unsigned long)p->mode);
2011 put_task_struct(task);
2018 .readdir = proc_map_files_readdir,
2024 static struct dentry *proc_pident_instantiate(
struct inode *dir,
2025 struct dentry *dentry,
struct task_struct *task,
const void *ptr)
2028 struct inode *
inode;
2030 struct dentry *error = ERR_PTR(-
ENOENT);
2046 d_add(dentry, inode);
2054 static struct dentry *proc_pident_lookup(
struct inode *dir,
2055 struct dentry *dentry,
2059 struct dentry *
error;
2063 error = ERR_PTR(-
ENOENT);
2072 last = &ents[nents - 1];
2073 for (p = ents; p <= last; p++) {
2082 error = proc_pident_instantiate(dir, dentry, task, p);
2084 put_task_struct(task);
2089 static int proc_pident_fill_cache(
struct file *filp,
void *dirent,
2093 proc_pident_instantiate, task, p);
2096 static int proc_pident_readdir(
struct file *filp,
2098 const struct pid_entry *ents,
unsigned int nents)
2101 struct dentry *dentry = filp->
f_path.dentry;
2102 struct inode *inode = dentry->
d_inode;
2117 if (filldir(dirent,
".", 1, i, ino,
DT_DIR) < 0)
2124 if (filldir(dirent,
"..", 2, i, ino,
DT_DIR) < 0)
2136 last = &ents[nents - 1];
2138 if (proc_pident_fill_cache(filp, dirent, filldir, task, p) < 0)
2147 put_task_struct(task);
2152 #ifdef CONFIG_SECURITY
2153 static ssize_t proc_pid_attr_read(
struct file * file,
char __user * buf,
2154 size_t count, loff_t *ppos)
2156 struct inode * inode = file->
f_path.dentry->d_inode;
2165 (
char*)file->
f_path.dentry->d_name.name,
2167 put_task_struct(task);
2174 static ssize_t proc_pid_attr_write(
struct file * file,
const char __user * buf,
2175 size_t count, loff_t *ppos)
2177 struct inode * inode = file->
f_path.dentry->d_inode;
2208 (
char*)file->
f_path.dentry->d_name.name,
2209 (
void*)page, count);
2214 put_task_struct(task);
2220 .
read = proc_pid_attr_read,
2221 .write = proc_pid_attr_write,
2225 static const struct pid_entry attr_dir_stuff[] = {
2227 REG(
"prev",
S_IRUGO, proc_pid_attr_operations),
2234 static int proc_attr_dir_readdir(
struct file * filp,
2237 return proc_pident_readdir(filp,dirent,filldir,
2243 .readdir = proc_attr_dir_readdir,
2247 static struct dentry *proc_attr_dir_lookup(
struct inode *dir,
2248 struct dentry *dentry,
unsigned int flags)
2250 return proc_pident_lookup(dir, dentry,
2255 .
lookup = proc_attr_dir_lookup,
2262 #ifdef CONFIG_ELF_CORE
2263 static ssize_t proc_coredump_filter_read(
struct file *file,
char __user *buf,
2264 size_t count, loff_t *ppos)
2266 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
2278 len =
snprintf(buffer,
sizeof(buffer),
"%08lx\n",
2285 put_task_struct(task);
2290 static ssize_t proc_coredump_filter_write(
struct file *file,
2291 const char __user *buf,
2304 memset(buffer, 0,
sizeof(buffer));
2305 if (count >
sizeof(buffer) - 1)
2306 count =
sizeof(
buffer) - 1;
2314 if (end - buffer == 0)
2318 task = get_proc_task(file->f_dentry->d_inode);
2336 put_task_struct(task);
2341 static const struct file_operations proc_coredump_filter_operations = {
2342 .
read = proc_coredump_filter_read,
2343 .write = proc_coredump_filter_write,
2351 static int proc_self_readlink(
struct dentry *dentry,
char __user *buffer,
2363 static void *proc_self_follow_link(
struct dentry *dentry,
struct nameidata *nd)
2376 nd_set_link(nd, name);
2380 static void proc_self_put_link(
struct dentry *dentry,
struct nameidata *nd,
2383 char *
s = nd_get_link(nd);
2389 .readlink = proc_self_readlink,
2390 .follow_link = proc_self_follow_link,
2391 .put_link = proc_self_put_link,
2401 static const struct pid_entry proc_base_stuff[] = {
2403 &proc_self_inode_operations,
NULL, {}),
2406 static struct dentry *proc_base_instantiate(
struct inode *dir,
2407 struct dentry *dentry,
struct task_struct *task,
const void *ptr)
2410 struct inode *
inode;
2412 struct dentry *
error;
2415 error = ERR_PTR(-
ENOMEM);
2442 d_add(dentry, inode);
2451 static struct dentry *proc_base_lookup(
struct inode *dir,
struct dentry *dentry)
2453 struct dentry *
error;
2457 error = ERR_PTR(-
ENOENT);
2463 last = &proc_base_stuff[
ARRAY_SIZE(proc_base_stuff) - 1];
2464 for (p = proc_base_stuff; p <= last; p++) {
2473 error = proc_base_instantiate(dir, dentry, task, p);
2476 put_task_struct(task);
2481 static int proc_base_fill_cache(
struct file *filp,
void *dirent,
2485 proc_base_instantiate, task, p);
2488 #ifdef CONFIG_TASK_IO_ACCOUNTING
2489 static int do_io_accounting(
struct task_struct *task,
char *buffer,
int whole)
2492 unsigned long flags;
2504 if (whole && lock_task_sighand(task, &flags)) {
2507 task_io_accounting_add(&acct, &task->
signal->ioac);
2509 task_io_accounting_add(&acct, &t->
ioac);
2511 unlock_task_sighand(task, &flags);
2518 "read_bytes: %
llu\
n"
2519 "write_bytes: %
llu\
n"
2520 "cancelled_write_bytes: %
llu\
n",
2521 (
unsigned long long)acct.rchar,
2522 (
unsigned long long)acct.wchar,
2523 (
unsigned long long)acct.syscr,
2524 (
unsigned long long)acct.syscw,
2525 (
unsigned long long)acct.read_bytes,
2526 (
unsigned long long)acct.write_bytes,
2527 (
unsigned long long)acct.cancelled_write_bytes);
2535 return do_io_accounting(task, buffer, 0);
2538 static int proc_tgid_io_accounting(
struct task_struct *task,
char *buffer)
2540 return do_io_accounting(task, buffer, 1);
2544 #ifdef CONFIG_USER_NS
2545 static int proc_id_map_open(
struct inode *inode,
struct file *file,
2553 task = get_proc_task(inode);
2558 put_task_struct(task);
2577 static int proc_id_map_release(
struct inode *inode,
struct file *file)
2585 static int proc_uid_map_open(
struct inode *inode,
struct file *file)
2590 static int proc_gid_map_open(
struct inode *inode,
struct file *file)
2595 static int proc_projid_map_open(
struct inode *inode,
struct file *file)
2601 .
open = proc_uid_map_open,
2605 .release = proc_id_map_release,
2609 .
open = proc_gid_map_open,
2613 .release = proc_id_map_release,
2617 .
open = proc_projid_map_open,
2621 .release = proc_id_map_release,
2628 int err = lock_trace(task);
2642 static const struct pid_entry tgid_base_stuff[] = {
2645 #ifdef CONFIG_CHECKPOINT_RESTORE
2646 DIR(
"map_files",
S_IRUSR|
S_IXUSR, proc_map_files_inode_operations, proc_map_files_operations),
2653 REG(
"environ",
S_IRUSR, proc_environ_operations),
2656 ONE(
"personality",
S_IRUGO, proc_pid_personality),
2658 #ifdef CONFIG_SCHED_DEBUG
2661 #ifdef CONFIG_SCHED_AUTOGROUP
2665 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
2673 REG(
"numa_maps",
S_IRUGO, proc_pid_numa_maps_operations),
2676 LNK(
"cwd", proc_cwd_link),
2677 LNK(
"root", proc_root_link),
2678 LNK(
"exe", proc_exe_link),
2682 #ifdef CONFIG_PROC_PAGE_MONITOR
2683 REG(
"clear_refs",
S_IWUSR, proc_clear_refs_operations),
2684 REG(
"smaps",
S_IRUGO, proc_pid_smaps_operations),
2685 REG(
"pagemap",
S_IRUGO, proc_pagemap_operations),
2687 #ifdef CONFIG_SECURITY
2688 DIR(
"attr",
S_IRUGO|
S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
2690 #ifdef CONFIG_KALLSYMS
2693 #ifdef CONFIG_STACKTRACE
2696 #ifdef CONFIG_SCHEDSTATS
2697 INF(
"schedstat",
S_IRUGO, proc_pid_schedstat),
2699 #ifdef CONFIG_LATENCYTOP
2700 REG(
"latency",
S_IRUGO, proc_lstats_operations),
2702 #ifdef CONFIG_PROC_PID_CPUSET
2703 REG(
"cpuset",
S_IRUGO, proc_cpuset_operations),
2705 #ifdef CONFIG_CGROUPS
2711 #ifdef CONFIG_AUDITSYSCALL
2713 REG(
"sessionid",
S_IRUGO, proc_sessionid_operations),
2715 #ifdef CONFIG_FAULT_INJECTION
2718 #ifdef CONFIG_ELF_CORE
2721 #ifdef CONFIG_TASK_IO_ACCOUNTING
2724 #ifdef CONFIG_HARDWALL
2727 #ifdef CONFIG_USER_NS
2734 static int proc_tgid_base_readdir(
struct file * filp,
2737 return proc_pident_readdir(filp,dirent,filldir,
2738 tgid_base_stuff,
ARRAY_SIZE(tgid_base_stuff));
2743 .readdir = proc_tgid_base_readdir,
2747 static struct dentry *proc_tgid_base_lookup(
struct inode *dir,
struct dentry *dentry,
unsigned int flags)
2749 return proc_pident_lookup(dir, dentry,
2750 tgid_base_stuff,
ARRAY_SIZE(tgid_base_stuff));
2754 .lookup = proc_tgid_base_lookup,
2757 .permission = proc_pid_permission,
2762 struct dentry *dentry, *leader, *dir;
2767 name.len =
snprintf(buf,
sizeof(buf),
"%d", pid);
2776 name.len =
snprintf(buf,
sizeof(buf),
"%d", tgid);
2782 name.len =
strlen(name.name);
2785 goto out_put_leader;
2788 name.len =
snprintf(buf,
sizeof(buf),
"%d", pid);
2831 struct pid *
pid, *tgid;
2834 pid = task_pid(task);
2835 tgid = task_tgid(task);
2837 for (i = 0; i <= pid->
level; i++) {
2839 proc_flush_task_mnt(upid->
ns->proc_mnt, upid->
nr,
2848 static struct dentry *proc_pid_instantiate(
struct inode *dir,
2849 struct dentry * dentry,
2852 struct dentry *error = ERR_PTR(-
ENOENT);
2853 struct inode *
inode;
2860 inode->
i_op = &proc_tgid_base_inode_operations;
2861 inode->
i_fop = &proc_tgid_base_operations;
2864 set_nlink(inode, 2 + pid_entry_count_dirs(tgid_base_stuff,
2869 d_add(dentry, inode);
2877 struct dentry *
proc_pid_lookup(
struct inode *dir,
struct dentry * dentry,
unsigned int flags)
2884 result = proc_base_lookup(dir, dentry);
2885 if (!IS_ERR(result) || PTR_ERR(result) != -
ENOENT)
2888 tgid = name_to_int(dentry);
2892 ns = dentry->
d_sb->s_fs_info;
2901 result = proc_pid_instantiate(dir, dentry, task,
NULL);
2902 put_task_struct(task);
2920 put_task_struct(iter.task);
2940 if (!iter.task || !has_group_leader_pid(iter.task)) {
2950 #define TGID_OFFSET (FIRST_PROCESS_ENTRY + ARRAY_SIZE(proc_base_stuff))
2952 static int proc_pid_fill_cache(
struct file *filp,
void *dirent,
filldir_t filldir,
2956 int len =
snprintf(name,
sizeof(name),
"%d", iter.
tgid);
2958 proc_pid_instantiate, iter.
task,
NULL);
2961 static int fake_filldir(
void *buf,
const char *name,
int namelen,
2962 loff_t offset,
u64 ino,
unsigned d_type)
2980 reaper = get_proc_task(filp->
f_path.dentry->d_inode);
2986 if (proc_base_fill_cache(filp, dirent, filldir, reaper, p) < 0)
2990 ns = filp->f_dentry->d_sb->s_fs_info;
2993 for (iter = next_tgid(ns, iter);
2995 iter.
tgid += 1, iter = next_tgid(ns, iter)) {
2996 if (has_pid_permissions(ns, iter.
task, 2))
2997 __filldir = filldir;
2999 __filldir = fake_filldir;
3002 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
3003 put_task_struct(iter.
task);
3009 put_task_struct(reaper);
3017 static const struct pid_entry tid_base_stuff[] = {
3021 REG(
"environ",
S_IRUSR, proc_environ_operations),
3024 ONE(
"personality",
S_IRUGO, proc_pid_personality),
3026 #ifdef CONFIG_SCHED_DEBUG
3030 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
3037 #ifdef CONFIG_CHECKPOINT_RESTORE
3038 REG(
"children",
S_IRUGO, proc_tid_children_operations),
3041 REG(
"numa_maps",
S_IRUGO, proc_tid_numa_maps_operations),
3044 LNK(
"cwd", proc_cwd_link),
3045 LNK(
"root", proc_root_link),
3046 LNK(
"exe", proc_exe_link),
3049 #ifdef CONFIG_PROC_PAGE_MONITOR
3050 REG(
"clear_refs",
S_IWUSR, proc_clear_refs_operations),
3051 REG(
"smaps",
S_IRUGO, proc_tid_smaps_operations),
3052 REG(
"pagemap",
S_IRUGO, proc_pagemap_operations),
3054 #ifdef CONFIG_SECURITY
3055 DIR(
"attr",
S_IRUGO|
S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
3057 #ifdef CONFIG_KALLSYMS
3060 #ifdef CONFIG_STACKTRACE
3063 #ifdef CONFIG_SCHEDSTATS
3064 INF(
"schedstat",
S_IRUGO, proc_pid_schedstat),
3066 #ifdef CONFIG_LATENCYTOP
3067 REG(
"latency",
S_IRUGO, proc_lstats_operations),
3069 #ifdef CONFIG_PROC_PID_CPUSET
3070 REG(
"cpuset",
S_IRUGO, proc_cpuset_operations),
3072 #ifdef CONFIG_CGROUPS
3078 #ifdef CONFIG_AUDITSYSCALL
3080 REG(
"sessionid",
S_IRUGO, proc_sessionid_operations),
3082 #ifdef CONFIG_FAULT_INJECTION
3085 #ifdef CONFIG_TASK_IO_ACCOUNTING
3088 #ifdef CONFIG_HARDWALL
3091 #ifdef CONFIG_USER_NS
3098 static int proc_tid_base_readdir(
struct file * filp,
3101 return proc_pident_readdir(filp,dirent,filldir,
3105 static struct dentry *proc_tid_base_lookup(
struct inode *dir,
struct dentry *dentry,
unsigned int flags)
3107 return proc_pident_lookup(dir, dentry,
3113 .readdir = proc_tid_base_readdir,
3118 .lookup = proc_tid_base_lookup,
3123 static struct dentry *proc_task_instantiate(
struct inode *dir,
3124 struct dentry *dentry,
struct task_struct *task,
const void *ptr)
3126 struct dentry *error = ERR_PTR(-
ENOENT);
3127 struct inode *
inode;
3133 inode->
i_op = &proc_tid_base_inode_operations;
3134 inode->
i_fop = &proc_tid_base_operations;
3137 set_nlink(inode, 2 + pid_entry_count_dirs(tid_base_stuff,
3142 d_add(dentry, inode);
3150 static struct dentry *proc_task_lookup(
struct inode *dir,
struct dentry * dentry,
unsigned int flags)
3152 struct dentry *result = ERR_PTR(-
ENOENT);
3161 tid = name_to_int(dentry);
3165 ns = dentry->
d_sb->s_fs_info;
3173 if (!same_thread_group(leader, task))
3176 result = proc_task_instantiate(dir, dentry, task,
NULL);
3178 put_task_struct(task);
3180 put_task_struct(leader);
3204 if (tid && (nr > 0)) {
3212 if (nr && nr >= get_nr_threads(leader))
3218 for (pos = leader; nr > 0; --
nr) {
3219 pos = next_thread(pos);
3220 if (pos == leader) {
3242 if (pid_alive(start)) {
3243 pos = next_thread(start);
3244 if (thread_group_leader(pos))
3250 put_task_struct(start);
3254 static int proc_task_fill_cache(
struct file *filp,
void *dirent,
filldir_t filldir,
3258 int len =
snprintf(name,
sizeof(name),
"%d", tid);
3260 proc_task_instantiate, task,
NULL);
3264 static int proc_task_readdir(
struct file * filp,
void * dirent,
filldir_t filldir)
3266 struct dentry *dentry = filp->
f_path.dentry;
3267 struct inode *inode = dentry->
d_inode;
3275 task = get_proc_task(inode);
3279 if (pid_alive(task)) {
3284 put_task_struct(task);
3289 switch ((
unsigned long)filp->
f_pos) {
3292 if (filldir(dirent,
".", 1, filp->
f_pos, ino,
DT_DIR) < 0)
3298 if (filldir(dirent,
"..", 2, filp->
f_pos, ino,
DT_DIR) < 0)
3307 ns = filp->f_dentry->d_sb->s_fs_info;
3310 for (task = first_tid(leader, tid, filp->
f_pos - 2, ns);
3312 task = next_tid(task), filp->
f_pos++) {
3313 tid = task_pid_nr_ns(task, ns);
3314 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
3318 put_task_struct(task);
3323 put_task_struct(leader);
3328 static int proc_task_getattr(
struct vfsmount *mnt,
struct dentry *dentry,
struct kstat *
stat)
3330 struct inode *inode = dentry->
d_inode;
3335 stat->
nlink += get_nr_threads(p);
3343 .lookup = proc_task_lookup,
3344 .getattr = proc_task_getattr,
3346 .permission = proc_pid_permission,
3351 .readdir = proc_task_readdir,