4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * proc base directory handling functions
8 * 1999, Al Viro. Rewritten. Now it covers the whole per-process part.
9 * Instead of using magical inumbers to determine the kind of object
10 * we allocate and fill in-core inodes upon lookup. They don't even
11 * go into icache. We cache the reference to task_struct upon lookup too.
12 * Eventually it should become a filesystem in its own. We don't use the
13 * rest of procfs anymore.
19 * Bruna Moreira <bruna.moreira@indt.org.br>
20 * Edjard Mota <edjard.mota@indt.org.br>
21 * Ilias Biris <ilias.biris@indt.org.br>
22 * Mauricio Lin <mauricio.lin@indt.org.br>
24 * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
26 * A new process specific entry (smaps) included in /proc. It shows the
27 * size of rss for each memory area. The maps entry lacks information
28 * about physical memory size (rss) for each mapped file, i.e.,
29 * rss information for executables and library files.
30 * This additional information is useful for any tools that need to know
31 * about physical memory consumption for a process specific library.
35 * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
36 * Pud inclusion in the page table walking.
40 * 10LE Instituto Nokia de Tecnologia - INdT:
41 * A better way to walks through the page table as suggested by Hugh Dickins.
43 * Simo Piiroinen <simo.piiroinen@nokia.com>:
44 * Smaps information related to shared, private, clean and dirty pages.
46 * Paul Mundt <paul.mundt@nokia.com>:
47 * Overall revision about smaps.
50 #include <asm/uaccess.h>
52 #include <linux/errno.h>
53 #include <linux/time.h>
54 #include <linux/proc_fs.h>
55 #include <linux/stat.h>
56 #include <linux/init.h>
57 #include <linux/capability.h>
58 #include <linux/file.h>
59 #include <linux/string.h>
60 #include <linux/seq_file.h>
61 #include <linux/namei.h>
62 #include <linux/mnt_namespace.h>
64 #include <linux/rcupdate.h>
65 #include <linux/kallsyms.h>
66 #include <linux/resource.h>
67 #include <linux/module.h>
68 #include <linux/mount.h>
69 #include <linux/security.h>
70 #include <linux/ptrace.h>
71 #include <linux/cgroup.h>
72 #include <linux/cpuset.h>
73 #include <linux/audit.h>
74 #include <linux/poll.h>
75 #include <linux/nsproxy.h>
76 #include <linux/oom.h>
77 #include <linux/elf.h>
78 #include <linux/pid_namespace.h>
82 * Implementing inode permission operations in /proc is almost
83 * certainly an error. Permission checks need to happen during
84 * each system call not at open time. The reason is that most of
85 * what we wish to check for permissions in /proc varies at runtime.
87 * The classic example of a problem is opening file descriptors
88 * in /proc for a task before it execs a suid executable.
95 const struct inode_operations
*iop
;
96 const struct file_operations
*fop
;
100 #define NOD(NAME, MODE, IOP, FOP, OP) { \
102 .len = sizeof(NAME) - 1, \
109 #define DIR(NAME, MODE, OTYPE) \
110 NOD(NAME, (S_IFDIR|(MODE)), \
111 &proc_##OTYPE##_inode_operations, &proc_##OTYPE##_operations, \
113 #define LNK(NAME, OTYPE) \
114 NOD(NAME, (S_IFLNK|S_IRWXUGO), \
115 &proc_pid_link_inode_operations, NULL, \
116 { .proc_get_link = &proc_##OTYPE##_link } )
117 #define REG(NAME, MODE, OTYPE) \
118 NOD(NAME, (S_IFREG|(MODE)), NULL, \
119 &proc_##OTYPE##_operations, {})
120 #define INF(NAME, MODE, OTYPE) \
121 NOD(NAME, (S_IFREG|(MODE)), \
122 NULL, &proc_info_file_operations, \
123 { .proc_read = &proc_##OTYPE } )
126 EXPORT_SYMBOL(maps_protect
);
128 static struct fs_struct
*get_fs_struct(struct task_struct
*task
)
130 struct fs_struct
*fs
;
134 atomic_inc(&fs
->count
);
139 static int get_nr_threads(struct task_struct
*tsk
)
141 /* Must be called with the rcu_read_lock held */
145 if (lock_task_sighand(tsk
, &flags
)) {
146 count
= atomic_read(&tsk
->signal
->count
);
147 unlock_task_sighand(tsk
, &flags
);
152 static int proc_cwd_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
154 struct task_struct
*task
= get_proc_task(inode
);
155 struct fs_struct
*fs
= NULL
;
156 int result
= -ENOENT
;
159 fs
= get_fs_struct(task
);
160 put_task_struct(task
);
163 read_lock(&fs
->lock
);
164 *mnt
= mntget(fs
->pwdmnt
);
165 *dentry
= dget(fs
->pwd
);
166 read_unlock(&fs
->lock
);
173 static int proc_root_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
175 struct task_struct
*task
= get_proc_task(inode
);
176 struct fs_struct
*fs
= NULL
;
177 int result
= -ENOENT
;
180 fs
= get_fs_struct(task
);
181 put_task_struct(task
);
184 read_lock(&fs
->lock
);
185 *mnt
= mntget(fs
->rootmnt
);
186 *dentry
= dget(fs
->root
);
187 read_unlock(&fs
->lock
);
194 #define MAY_PTRACE(task) \
195 (task == current || \
196 (task->parent == current && \
197 (task->ptrace & PT_PTRACED) && \
198 (task_is_stopped_or_traced(task)) && \
199 security_ptrace(current,task) == 0))
201 struct mm_struct
*mm_for_maps(struct task_struct
*task
)
203 struct mm_struct
*mm
= get_task_mm(task
);
206 down_read(&mm
->mmap_sem
);
210 if (task
->mm
!= current
->mm
&& __ptrace_may_attach(task
) < 0)
216 up_read(&mm
->mmap_sem
);
221 static int proc_pid_cmdline(struct task_struct
*task
, char * buffer
)
225 struct mm_struct
*mm
= get_task_mm(task
);
229 goto out_mm
; /* Shh! No looking before we're done */
231 len
= mm
->arg_end
- mm
->arg_start
;
236 res
= access_process_vm(task
, mm
->arg_start
, buffer
, len
, 0);
238 // If the nul at the end of args has been overwritten, then
239 // assume application is using setproctitle(3).
240 if (res
> 0 && buffer
[res
-1] != '\0' && len
< PAGE_SIZE
) {
241 len
= strnlen(buffer
, res
);
245 len
= mm
->env_end
- mm
->env_start
;
246 if (len
> PAGE_SIZE
- res
)
247 len
= PAGE_SIZE
- res
;
248 res
+= access_process_vm(task
, mm
->env_start
, buffer
+res
, len
, 0);
249 res
= strnlen(buffer
, res
);
258 static int proc_pid_auxv(struct task_struct
*task
, char *buffer
)
261 struct mm_struct
*mm
= get_task_mm(task
);
263 unsigned int nwords
= 0;
266 while (mm
->saved_auxv
[nwords
- 2] != 0); /* AT_NULL */
267 res
= nwords
* sizeof(mm
->saved_auxv
[0]);
270 memcpy(buffer
, mm
->saved_auxv
, res
);
277 #ifdef CONFIG_KALLSYMS
279 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
280 * Returns the resolved symbol. If that fails, simply return the address.
282 static int proc_pid_wchan(struct task_struct
*task
, char *buffer
)
285 char symname
[KSYM_NAME_LEN
];
287 wchan
= get_wchan(task
);
289 if (lookup_symbol_name(wchan
, symname
) < 0)
290 return sprintf(buffer
, "%lu", wchan
);
292 return sprintf(buffer
, "%s", symname
);
294 #endif /* CONFIG_KALLSYMS */
296 #ifdef CONFIG_SCHEDSTATS
298 * Provides /proc/PID/schedstat
300 static int proc_pid_schedstat(struct task_struct
*task
, char *buffer
)
302 return sprintf(buffer
, "%llu %llu %lu\n",
303 task
->sched_info
.cpu_time
,
304 task
->sched_info
.run_delay
,
305 task
->sched_info
.pcount
);
309 #ifdef CONFIG_LATENCYTOP
310 static int lstats_show_proc(struct seq_file
*m
, void *v
)
313 struct task_struct
*task
= m
->private;
314 seq_puts(m
, "Latency Top version : v0.1\n");
316 for (i
= 0; i
< 32; i
++) {
317 if (task
->latency_record
[i
].backtrace
[0]) {
319 seq_printf(m
, "%i %li %li ",
320 task
->latency_record
[i
].count
,
321 task
->latency_record
[i
].time
,
322 task
->latency_record
[i
].max
);
323 for (q
= 0; q
< LT_BACKTRACEDEPTH
; q
++) {
324 char sym
[KSYM_NAME_LEN
];
326 if (!task
->latency_record
[i
].backtrace
[q
])
328 if (task
->latency_record
[i
].backtrace
[q
] == ULONG_MAX
)
330 sprint_symbol(sym
, task
->latency_record
[i
].backtrace
[q
]);
331 c
= strchr(sym
, '+');
334 seq_printf(m
, "%s ", sym
);
343 static int lstats_open(struct inode
*inode
, struct file
*file
)
347 struct task_struct
*task
= get_proc_task(inode
);
349 ret
= single_open(file
, lstats_show_proc
, NULL
);
351 m
= file
->private_data
;
357 static ssize_t
lstats_write(struct file
*file
, const char __user
*buf
,
358 size_t count
, loff_t
*offs
)
361 struct task_struct
*task
;
363 m
= file
->private_data
;
365 clear_all_latency_tracing(task
);
370 static const struct file_operations proc_lstats_operations
= {
373 .write
= lstats_write
,
375 .release
= single_release
,
380 /* The badness from the OOM killer */
381 unsigned long badness(struct task_struct
*p
, unsigned long uptime
);
382 static int proc_oom_score(struct task_struct
*task
, char *buffer
)
384 unsigned long points
;
385 struct timespec uptime
;
387 do_posix_clock_monotonic_gettime(&uptime
);
388 read_lock(&tasklist_lock
);
389 points
= badness(task
, uptime
.tv_sec
);
390 read_unlock(&tasklist_lock
);
391 return sprintf(buffer
, "%lu\n", points
);
399 static const struct limit_names lnames
[RLIM_NLIMITS
] = {
400 [RLIMIT_CPU
] = {"Max cpu time", "ms"},
401 [RLIMIT_FSIZE
] = {"Max file size", "bytes"},
402 [RLIMIT_DATA
] = {"Max data size", "bytes"},
403 [RLIMIT_STACK
] = {"Max stack size", "bytes"},
404 [RLIMIT_CORE
] = {"Max core file size", "bytes"},
405 [RLIMIT_RSS
] = {"Max resident set", "bytes"},
406 [RLIMIT_NPROC
] = {"Max processes", "processes"},
407 [RLIMIT_NOFILE
] = {"Max open files", "files"},
408 [RLIMIT_MEMLOCK
] = {"Max locked memory", "bytes"},
409 [RLIMIT_AS
] = {"Max address space", "bytes"},
410 [RLIMIT_LOCKS
] = {"Max file locks", "locks"},
411 [RLIMIT_SIGPENDING
] = {"Max pending signals", "signals"},
412 [RLIMIT_MSGQUEUE
] = {"Max msgqueue size", "bytes"},
413 [RLIMIT_NICE
] = {"Max nice priority", NULL
},
414 [RLIMIT_RTPRIO
] = {"Max realtime priority", NULL
},
417 /* Display limits for a process */
418 static int proc_pid_limits(struct task_struct
*task
, char *buffer
)
423 char *bufptr
= buffer
;
425 struct rlimit rlim
[RLIM_NLIMITS
];
428 if (!lock_task_sighand(task
,&flags
)) {
432 memcpy(rlim
, task
->signal
->rlim
, sizeof(struct rlimit
) * RLIM_NLIMITS
);
433 unlock_task_sighand(task
, &flags
);
437 * print the file header
439 count
+= sprintf(&bufptr
[count
], "%-25s %-20s %-20s %-10s\n",
440 "Limit", "Soft Limit", "Hard Limit", "Units");
442 for (i
= 0; i
< RLIM_NLIMITS
; i
++) {
443 if (rlim
[i
].rlim_cur
== RLIM_INFINITY
)
444 count
+= sprintf(&bufptr
[count
], "%-25s %-20s ",
445 lnames
[i
].name
, "unlimited");
447 count
+= sprintf(&bufptr
[count
], "%-25s %-20lu ",
448 lnames
[i
].name
, rlim
[i
].rlim_cur
);
450 if (rlim
[i
].rlim_max
== RLIM_INFINITY
)
451 count
+= sprintf(&bufptr
[count
], "%-20s ", "unlimited");
453 count
+= sprintf(&bufptr
[count
], "%-20lu ",
457 count
+= sprintf(&bufptr
[count
], "%-10s\n",
460 count
+= sprintf(&bufptr
[count
], "\n");
466 /************************************************************************/
467 /* Here the fs part begins */
468 /************************************************************************/
470 /* permission checks */
471 static int proc_fd_access_allowed(struct inode
*inode
)
473 struct task_struct
*task
;
475 /* Allow access to a task's file descriptors if it is us or we
476 * may use ptrace attach to the process and find out that
479 task
= get_proc_task(inode
);
481 allowed
= ptrace_may_attach(task
);
482 put_task_struct(task
);
487 static int proc_setattr(struct dentry
*dentry
, struct iattr
*attr
)
490 struct inode
*inode
= dentry
->d_inode
;
492 if (attr
->ia_valid
& ATTR_MODE
)
495 error
= inode_change_ok(inode
, attr
);
497 error
= inode_setattr(inode
, attr
);
501 static const struct inode_operations proc_def_inode_operations
= {
502 .setattr
= proc_setattr
,
505 extern struct seq_operations mounts_op
;
511 static int mounts_open(struct inode
*inode
, struct file
*file
)
513 struct task_struct
*task
= get_proc_task(inode
);
515 struct mnt_namespace
*ns
= NULL
;
516 struct proc_mounts
*p
;
521 nsp
= task_nsproxy(task
);
529 put_task_struct(task
);
534 p
= kmalloc(sizeof(struct proc_mounts
), GFP_KERNEL
);
536 file
->private_data
= &p
->m
;
537 ret
= seq_open(file
, &mounts_op
);
540 p
->event
= ns
->event
;
550 static int mounts_release(struct inode
*inode
, struct file
*file
)
552 struct seq_file
*m
= file
->private_data
;
553 struct mnt_namespace
*ns
= m
->private;
555 return seq_release(inode
, file
);
558 static unsigned mounts_poll(struct file
*file
, poll_table
*wait
)
560 struct proc_mounts
*p
= file
->private_data
;
561 struct mnt_namespace
*ns
= p
->m
.private;
564 poll_wait(file
, &ns
->poll
, wait
);
566 spin_lock(&vfsmount_lock
);
567 if (p
->event
!= ns
->event
) {
568 p
->event
= ns
->event
;
571 spin_unlock(&vfsmount_lock
);
576 static const struct file_operations proc_mounts_operations
= {
580 .release
= mounts_release
,
584 extern struct seq_operations mountstats_op
;
585 static int mountstats_open(struct inode
*inode
, struct file
*file
)
587 int ret
= seq_open(file
, &mountstats_op
);
590 struct seq_file
*m
= file
->private_data
;
592 struct mnt_namespace
*mnt_ns
= NULL
;
593 struct task_struct
*task
= get_proc_task(inode
);
597 nsp
= task_nsproxy(task
);
599 mnt_ns
= nsp
->mnt_ns
;
605 put_task_struct(task
);
611 seq_release(inode
, file
);
618 static const struct file_operations proc_mountstats_operations
= {
619 .open
= mountstats_open
,
622 .release
= mounts_release
,
625 #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
627 static ssize_t
proc_info_read(struct file
* file
, char __user
* buf
,
628 size_t count
, loff_t
*ppos
)
630 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
633 struct task_struct
*task
= get_proc_task(inode
);
639 if (count
> PROC_BLOCK_SIZE
)
640 count
= PROC_BLOCK_SIZE
;
643 if (!(page
= __get_free_page(GFP_TEMPORARY
)))
646 length
= PROC_I(inode
)->op
.proc_read(task
, (char*)page
);
649 length
= simple_read_from_buffer(buf
, count
, ppos
, (char *)page
, length
);
652 put_task_struct(task
);
657 static const struct file_operations proc_info_file_operations
= {
658 .read
= proc_info_read
,
661 static int mem_open(struct inode
* inode
, struct file
* file
)
663 file
->private_data
= (void*)((long)current
->self_exec_id
);
667 static ssize_t
mem_read(struct file
* file
, char __user
* buf
,
668 size_t count
, loff_t
*ppos
)
670 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
672 unsigned long src
= *ppos
;
674 struct mm_struct
*mm
;
679 if (!MAY_PTRACE(task
) || !ptrace_may_attach(task
))
683 page
= (char *)__get_free_page(GFP_TEMPORARY
);
689 mm
= get_task_mm(task
);
695 if (file
->private_data
!= (void*)((long)current
->self_exec_id
))
701 int this_len
, retval
;
703 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
704 retval
= access_process_vm(task
, src
, page
, this_len
, 0);
705 if (!retval
|| !MAY_PTRACE(task
) || !ptrace_may_attach(task
)) {
711 if (copy_to_user(buf
, page
, retval
)) {
726 free_page((unsigned long) page
);
728 put_task_struct(task
);
733 #define mem_write NULL
736 /* This is a security hazard */
737 static ssize_t
mem_write(struct file
* file
, const char __user
*buf
,
738 size_t count
, loff_t
*ppos
)
742 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
743 unsigned long dst
= *ppos
;
749 if (!MAY_PTRACE(task
) || !ptrace_may_attach(task
))
753 page
= (char *)__get_free_page(GFP_TEMPORARY
);
759 int this_len
, retval
;
761 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
762 if (copy_from_user(page
, buf
, this_len
)) {
766 retval
= access_process_vm(task
, dst
, page
, this_len
, 1);
778 free_page((unsigned long) page
);
780 put_task_struct(task
);
786 static loff_t
mem_lseek(struct file
* file
, loff_t offset
, int orig
)
790 file
->f_pos
= offset
;
793 file
->f_pos
+= offset
;
798 force_successful_syscall_return();
802 static const struct file_operations proc_mem_operations
= {
809 static ssize_t
environ_read(struct file
*file
, char __user
*buf
,
810 size_t count
, loff_t
*ppos
)
812 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
814 unsigned long src
= *ppos
;
816 struct mm_struct
*mm
;
821 if (!ptrace_may_attach(task
))
825 page
= (char *)__get_free_page(GFP_TEMPORARY
);
831 mm
= get_task_mm(task
);
836 int this_len
, retval
, max_len
;
838 this_len
= mm
->env_end
- (mm
->env_start
+ src
);
843 max_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
844 this_len
= (this_len
> max_len
) ? max_len
: this_len
;
846 retval
= access_process_vm(task
, (mm
->env_start
+ src
),
854 if (copy_to_user(buf
, page
, retval
)) {
868 free_page((unsigned long) page
);
870 put_task_struct(task
);
875 static const struct file_operations proc_environ_operations
= {
876 .read
= environ_read
,
879 static ssize_t
oom_adjust_read(struct file
*file
, char __user
*buf
,
880 size_t count
, loff_t
*ppos
)
882 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
883 char buffer
[PROC_NUMBUF
];
889 oom_adjust
= task
->oomkilladj
;
890 put_task_struct(task
);
892 len
= snprintf(buffer
, sizeof(buffer
), "%i\n", oom_adjust
);
894 return simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
897 static ssize_t
oom_adjust_write(struct file
*file
, const char __user
*buf
,
898 size_t count
, loff_t
*ppos
)
900 struct task_struct
*task
;
901 char buffer
[PROC_NUMBUF
], *end
;
904 memset(buffer
, 0, sizeof(buffer
));
905 if (count
> sizeof(buffer
) - 1)
906 count
= sizeof(buffer
) - 1;
907 if (copy_from_user(buffer
, buf
, count
))
909 oom_adjust
= simple_strtol(buffer
, &end
, 0);
910 if ((oom_adjust
< OOM_ADJUST_MIN
|| oom_adjust
> OOM_ADJUST_MAX
) &&
911 oom_adjust
!= OOM_DISABLE
)
915 task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
918 if (oom_adjust
< task
->oomkilladj
&& !capable(CAP_SYS_RESOURCE
)) {
919 put_task_struct(task
);
922 task
->oomkilladj
= oom_adjust
;
923 put_task_struct(task
);
924 if (end
- buffer
== 0)
929 static const struct file_operations proc_oom_adjust_operations
= {
930 .read
= oom_adjust_read
,
931 .write
= oom_adjust_write
,
934 #ifdef CONFIG_AUDITSYSCALL
936 static ssize_t
proc_loginuid_read(struct file
* file
, char __user
* buf
,
937 size_t count
, loff_t
*ppos
)
939 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
940 struct task_struct
*task
= get_proc_task(inode
);
942 char tmpbuf
[TMPBUFLEN
];
946 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u",
947 audit_get_loginuid(task
));
948 put_task_struct(task
);
949 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
952 static ssize_t
proc_loginuid_write(struct file
* file
, const char __user
* buf
,
953 size_t count
, loff_t
*ppos
)
955 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
960 if (!capable(CAP_AUDIT_CONTROL
))
963 if (current
!= pid_task(proc_pid(inode
), PIDTYPE_PID
))
966 if (count
>= PAGE_SIZE
)
967 count
= PAGE_SIZE
- 1;
970 /* No partial writes. */
973 page
= (char*)__get_free_page(GFP_TEMPORARY
);
977 if (copy_from_user(page
, buf
, count
))
981 loginuid
= simple_strtoul(page
, &tmp
, 10);
987 length
= audit_set_loginuid(current
, loginuid
);
988 if (likely(length
== 0))
992 free_page((unsigned long) page
);
996 static const struct file_operations proc_loginuid_operations
= {
997 .read
= proc_loginuid_read
,
998 .write
= proc_loginuid_write
,
1002 #ifdef CONFIG_FAULT_INJECTION
1003 static ssize_t
proc_fault_inject_read(struct file
* file
, char __user
* buf
,
1004 size_t count
, loff_t
*ppos
)
1006 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
1007 char buffer
[PROC_NUMBUF
];
1013 make_it_fail
= task
->make_it_fail
;
1014 put_task_struct(task
);
1016 len
= snprintf(buffer
, sizeof(buffer
), "%i\n", make_it_fail
);
1018 return simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
1021 static ssize_t
proc_fault_inject_write(struct file
* file
,
1022 const char __user
* buf
, size_t count
, loff_t
*ppos
)
1024 struct task_struct
*task
;
1025 char buffer
[PROC_NUMBUF
], *end
;
1028 if (!capable(CAP_SYS_RESOURCE
))
1030 memset(buffer
, 0, sizeof(buffer
));
1031 if (count
> sizeof(buffer
) - 1)
1032 count
= sizeof(buffer
) - 1;
1033 if (copy_from_user(buffer
, buf
, count
))
1035 make_it_fail
= simple_strtol(buffer
, &end
, 0);
1038 task
= get_proc_task(file
->f_dentry
->d_inode
);
1041 task
->make_it_fail
= make_it_fail
;
1042 put_task_struct(task
);
1043 if (end
- buffer
== 0)
1045 return end
- buffer
;
1048 static const struct file_operations proc_fault_inject_operations
= {
1049 .read
= proc_fault_inject_read
,
1050 .write
= proc_fault_inject_write
,
1055 #ifdef CONFIG_SCHED_DEBUG
1057 * Print out various scheduling related per-task fields:
1059 static int sched_show(struct seq_file
*m
, void *v
)
1061 struct inode
*inode
= m
->private;
1062 struct task_struct
*p
;
1066 p
= get_proc_task(inode
);
1069 proc_sched_show_task(p
, m
);
1077 sched_write(struct file
*file
, const char __user
*buf
,
1078 size_t count
, loff_t
*offset
)
1080 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
1081 struct task_struct
*p
;
1085 p
= get_proc_task(inode
);
1088 proc_sched_set_task(p
);
1095 static int sched_open(struct inode
*inode
, struct file
*filp
)
1099 ret
= single_open(filp
, sched_show
, NULL
);
1101 struct seq_file
*m
= filp
->private_data
;
1108 static const struct file_operations proc_pid_sched_operations
= {
1111 .write
= sched_write
,
1112 .llseek
= seq_lseek
,
1113 .release
= single_release
,
1118 static void *proc_pid_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1120 struct inode
*inode
= dentry
->d_inode
;
1121 int error
= -EACCES
;
1123 /* We don't need a base pointer in the /proc filesystem */
1126 /* Are we allowed to snoop on the tasks file descriptors? */
1127 if (!proc_fd_access_allowed(inode
))
1130 error
= PROC_I(inode
)->op
.proc_get_link(inode
, &nd
->dentry
, &nd
->mnt
);
1131 nd
->last_type
= LAST_BIND
;
1133 return ERR_PTR(error
);
1136 static int do_proc_readlink(struct dentry
*dentry
, struct vfsmount
*mnt
,
1137 char __user
*buffer
, int buflen
)
1139 struct inode
* inode
;
1140 char *tmp
= (char*)__get_free_page(GFP_TEMPORARY
);
1147 inode
= dentry
->d_inode
;
1148 path
= d_path(dentry
, mnt
, tmp
, PAGE_SIZE
);
1149 len
= PTR_ERR(path
);
1152 len
= tmp
+ PAGE_SIZE
- 1 - path
;
1156 if (copy_to_user(buffer
, path
, len
))
1159 free_page((unsigned long)tmp
);
1163 static int proc_pid_readlink(struct dentry
* dentry
, char __user
* buffer
, int buflen
)
1165 int error
= -EACCES
;
1166 struct inode
*inode
= dentry
->d_inode
;
1168 struct vfsmount
*mnt
= NULL
;
1170 /* Are we allowed to snoop on the tasks file descriptors? */
1171 if (!proc_fd_access_allowed(inode
))
1174 error
= PROC_I(inode
)->op
.proc_get_link(inode
, &de
, &mnt
);
1178 error
= do_proc_readlink(de
, mnt
, buffer
, buflen
);
1185 static const struct inode_operations proc_pid_link_inode_operations
= {
1186 .readlink
= proc_pid_readlink
,
1187 .follow_link
= proc_pid_follow_link
,
1188 .setattr
= proc_setattr
,
1192 /* building an inode */
1194 static int task_dumpable(struct task_struct
*task
)
1197 struct mm_struct
*mm
;
1202 dumpable
= get_dumpable(mm
);
1210 static struct inode
*proc_pid_make_inode(struct super_block
* sb
, struct task_struct
*task
)
1212 struct inode
* inode
;
1213 struct proc_inode
*ei
;
1215 /* We need a new inode */
1217 inode
= new_inode(sb
);
1223 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
1224 inode
->i_op
= &proc_def_inode_operations
;
1227 * grab the reference to task.
1229 ei
->pid
= get_task_pid(task
, PIDTYPE_PID
);
1235 if (task_dumpable(task
)) {
1236 inode
->i_uid
= task
->euid
;
1237 inode
->i_gid
= task
->egid
;
1239 security_task_to_inode(task
, inode
);
1249 static int pid_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
, struct kstat
*stat
)
1251 struct inode
*inode
= dentry
->d_inode
;
1252 struct task_struct
*task
;
1253 generic_fillattr(inode
, stat
);
1258 task
= pid_task(proc_pid(inode
), PIDTYPE_PID
);
1260 if ((inode
->i_mode
== (S_IFDIR
|S_IRUGO
|S_IXUGO
)) ||
1261 task_dumpable(task
)) {
1262 stat
->uid
= task
->euid
;
1263 stat
->gid
= task
->egid
;
1273 * Exceptional case: normally we are not allowed to unhash a busy
1274 * directory. In this case, however, we can do it - no aliasing problems
1275 * due to the way we treat inodes.
1277 * Rewrite the inode's ownerships here because the owning task may have
1278 * performed a setuid(), etc.
1280 * Before the /proc/pid/status file was created the only way to read
1281 * the effective uid of a /process was to stat /proc/pid. Reading
1282 * /proc/pid/status is slow enough that procps and other packages
1283 * kept stating /proc/pid. To keep the rules in /proc simple I have
1284 * made this apply to all per process world readable and executable
1287 static int pid_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
1289 struct inode
*inode
= dentry
->d_inode
;
1290 struct task_struct
*task
= get_proc_task(inode
);
1292 if ((inode
->i_mode
== (S_IFDIR
|S_IRUGO
|S_IXUGO
)) ||
1293 task_dumpable(task
)) {
1294 inode
->i_uid
= task
->euid
;
1295 inode
->i_gid
= task
->egid
;
1300 inode
->i_mode
&= ~(S_ISUID
| S_ISGID
);
1301 security_task_to_inode(task
, inode
);
1302 put_task_struct(task
);
1309 static int pid_delete_dentry(struct dentry
* dentry
)
1311 /* Is the task we represent dead?
1312 * If so, then don't put the dentry on the lru list,
1313 * kill it immediately.
1315 return !proc_pid(dentry
->d_inode
)->tasks
[PIDTYPE_PID
].first
;
1318 static struct dentry_operations pid_dentry_operations
=
1320 .d_revalidate
= pid_revalidate
,
1321 .d_delete
= pid_delete_dentry
,
1326 typedef struct dentry
*instantiate_t(struct inode
*, struct dentry
*,
1327 struct task_struct
*, const void *);
1330 * Fill a directory entry.
1332 * If possible create the dcache entry and derive our inode number and
1333 * file type from dcache entry.
1335 * Since all of the proc inode numbers are dynamically generated, the inode
1336 * numbers do not exist until the inode is cache. This means creating the
1337 * the dcache entry in readdir is necessary to keep the inode numbers
1338 * reported by readdir in sync with the inode numbers reported
1341 static int proc_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
1342 char *name
, int len
,
1343 instantiate_t instantiate
, struct task_struct
*task
, const void *ptr
)
1345 struct dentry
*child
, *dir
= filp
->f_path
.dentry
;
1346 struct inode
*inode
;
1349 unsigned type
= DT_UNKNOWN
;
1353 qname
.hash
= full_name_hash(name
, len
);
1355 child
= d_lookup(dir
, &qname
);
1358 new = d_alloc(dir
, &qname
);
1360 child
= instantiate(dir
->d_inode
, new, task
, ptr
);
1367 if (!child
|| IS_ERR(child
) || !child
->d_inode
)
1368 goto end_instantiate
;
1369 inode
= child
->d_inode
;
1372 type
= inode
->i_mode
>> 12;
1377 ino
= find_inode_number(dir
, &qname
);
1380 return filldir(dirent
, name
, len
, filp
->f_pos
, ino
, type
);
1383 static unsigned name_to_int(struct dentry
*dentry
)
1385 const char *name
= dentry
->d_name
.name
;
1386 int len
= dentry
->d_name
.len
;
1389 if (len
> 1 && *name
== '0')
1392 unsigned c
= *name
++ - '0';
1395 if (n
>= (~0U-9)/10)
1405 #define PROC_FDINFO_MAX 64
1407 static int proc_fd_info(struct inode
*inode
, struct dentry
**dentry
,
1408 struct vfsmount
**mnt
, char *info
)
1410 struct task_struct
*task
= get_proc_task(inode
);
1411 struct files_struct
*files
= NULL
;
1413 int fd
= proc_fd(inode
);
1416 files
= get_files_struct(task
);
1417 put_task_struct(task
);
1421 * We are not taking a ref to the file structure, so we must
1424 spin_lock(&files
->file_lock
);
1425 file
= fcheck_files(files
, fd
);
1428 *mnt
= mntget(file
->f_path
.mnt
);
1430 *dentry
= dget(file
->f_path
.dentry
);
1432 snprintf(info
, PROC_FDINFO_MAX
,
1435 (long long) file
->f_pos
,
1437 spin_unlock(&files
->file_lock
);
1438 put_files_struct(files
);
1441 spin_unlock(&files
->file_lock
);
1442 put_files_struct(files
);
1447 static int proc_fd_link(struct inode
*inode
, struct dentry
**dentry
,
1448 struct vfsmount
**mnt
)
1450 return proc_fd_info(inode
, dentry
, mnt
, NULL
);
1453 static int tid_fd_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
1455 struct inode
*inode
= dentry
->d_inode
;
1456 struct task_struct
*task
= get_proc_task(inode
);
1457 int fd
= proc_fd(inode
);
1458 struct files_struct
*files
;
1461 files
= get_files_struct(task
);
1464 if (fcheck_files(files
, fd
)) {
1466 put_files_struct(files
);
1467 if (task_dumpable(task
)) {
1468 inode
->i_uid
= task
->euid
;
1469 inode
->i_gid
= task
->egid
;
1474 inode
->i_mode
&= ~(S_ISUID
| S_ISGID
);
1475 security_task_to_inode(task
, inode
);
1476 put_task_struct(task
);
1480 put_files_struct(files
);
1482 put_task_struct(task
);
1488 static struct dentry_operations tid_fd_dentry_operations
=
1490 .d_revalidate
= tid_fd_revalidate
,
1491 .d_delete
= pid_delete_dentry
,
1494 static struct dentry
*proc_fd_instantiate(struct inode
*dir
,
1495 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1497 unsigned fd
= *(const unsigned *)ptr
;
1499 struct files_struct
*files
;
1500 struct inode
*inode
;
1501 struct proc_inode
*ei
;
1502 struct dentry
*error
= ERR_PTR(-ENOENT
);
1504 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1509 files
= get_files_struct(task
);
1512 inode
->i_mode
= S_IFLNK
;
1515 * We are not taking a ref to the file structure, so we must
1518 spin_lock(&files
->file_lock
);
1519 file
= fcheck_files(files
, fd
);
1522 if (file
->f_mode
& 1)
1523 inode
->i_mode
|= S_IRUSR
| S_IXUSR
;
1524 if (file
->f_mode
& 2)
1525 inode
->i_mode
|= S_IWUSR
| S_IXUSR
;
1526 spin_unlock(&files
->file_lock
);
1527 put_files_struct(files
);
1529 inode
->i_op
= &proc_pid_link_inode_operations
;
1531 ei
->op
.proc_get_link
= proc_fd_link
;
1532 dentry
->d_op
= &tid_fd_dentry_operations
;
1533 d_add(dentry
, inode
);
1534 /* Close the race of the process dying before we return the dentry */
1535 if (tid_fd_revalidate(dentry
, NULL
))
1541 spin_unlock(&files
->file_lock
);
1542 put_files_struct(files
);
1548 static struct dentry
*proc_lookupfd_common(struct inode
*dir
,
1549 struct dentry
*dentry
,
1550 instantiate_t instantiate
)
1552 struct task_struct
*task
= get_proc_task(dir
);
1553 unsigned fd
= name_to_int(dentry
);
1554 struct dentry
*result
= ERR_PTR(-ENOENT
);
1561 result
= instantiate(dir
, dentry
, task
, &fd
);
1563 put_task_struct(task
);
1568 static int proc_readfd_common(struct file
* filp
, void * dirent
,
1569 filldir_t filldir
, instantiate_t instantiate
)
1571 struct dentry
*dentry
= filp
->f_path
.dentry
;
1572 struct inode
*inode
= dentry
->d_inode
;
1573 struct task_struct
*p
= get_proc_task(inode
);
1574 unsigned int fd
, ino
;
1576 struct files_struct
* files
;
1577 struct fdtable
*fdt
;
1587 if (filldir(dirent
, ".", 1, 0, inode
->i_ino
, DT_DIR
) < 0)
1591 ino
= parent_ino(dentry
);
1592 if (filldir(dirent
, "..", 2, 1, ino
, DT_DIR
) < 0)
1596 files
= get_files_struct(p
);
1600 fdt
= files_fdtable(files
);
1601 for (fd
= filp
->f_pos
-2;
1603 fd
++, filp
->f_pos
++) {
1604 char name
[PROC_NUMBUF
];
1607 if (!fcheck_files(files
, fd
))
1611 len
= snprintf(name
, sizeof(name
), "%d", fd
);
1612 if (proc_fill_cache(filp
, dirent
, filldir
,
1613 name
, len
, instantiate
,
1621 put_files_struct(files
);
1629 static struct dentry
*proc_lookupfd(struct inode
*dir
, struct dentry
*dentry
,
1630 struct nameidata
*nd
)
1632 return proc_lookupfd_common(dir
, dentry
, proc_fd_instantiate
);
1635 static int proc_readfd(struct file
*filp
, void *dirent
, filldir_t filldir
)
1637 return proc_readfd_common(filp
, dirent
, filldir
, proc_fd_instantiate
);
1640 static ssize_t
proc_fdinfo_read(struct file
*file
, char __user
*buf
,
1641 size_t len
, loff_t
*ppos
)
1643 char tmp
[PROC_FDINFO_MAX
];
1644 int err
= proc_fd_info(file
->f_path
.dentry
->d_inode
, NULL
, NULL
, tmp
);
1646 err
= simple_read_from_buffer(buf
, len
, ppos
, tmp
, strlen(tmp
));
1650 static const struct file_operations proc_fdinfo_file_operations
= {
1651 .open
= nonseekable_open
,
1652 .read
= proc_fdinfo_read
,
1655 static const struct file_operations proc_fd_operations
= {
1656 .read
= generic_read_dir
,
1657 .readdir
= proc_readfd
,
1661 * /proc/pid/fd needs a special permission handler so that a process can still
1662 * access /proc/self/fd after it has executed a setuid().
1664 static int proc_fd_permission(struct inode
*inode
, int mask
,
1665 struct nameidata
*nd
)
1669 rv
= generic_permission(inode
, mask
, NULL
);
1672 if (task_pid(current
) == proc_pid(inode
))
1678 * proc directories can do almost nothing..
1680 static const struct inode_operations proc_fd_inode_operations
= {
1681 .lookup
= proc_lookupfd
,
1682 .permission
= proc_fd_permission
,
1683 .setattr
= proc_setattr
,
1686 static struct dentry
*proc_fdinfo_instantiate(struct inode
*dir
,
1687 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1689 unsigned fd
= *(unsigned *)ptr
;
1690 struct inode
*inode
;
1691 struct proc_inode
*ei
;
1692 struct dentry
*error
= ERR_PTR(-ENOENT
);
1694 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1699 inode
->i_mode
= S_IFREG
| S_IRUSR
;
1700 inode
->i_fop
= &proc_fdinfo_file_operations
;
1701 dentry
->d_op
= &tid_fd_dentry_operations
;
1702 d_add(dentry
, inode
);
1703 /* Close the race of the process dying before we return the dentry */
1704 if (tid_fd_revalidate(dentry
, NULL
))
1711 static struct dentry
*proc_lookupfdinfo(struct inode
*dir
,
1712 struct dentry
*dentry
,
1713 struct nameidata
*nd
)
1715 return proc_lookupfd_common(dir
, dentry
, proc_fdinfo_instantiate
);
1718 static int proc_readfdinfo(struct file
*filp
, void *dirent
, filldir_t filldir
)
1720 return proc_readfd_common(filp
, dirent
, filldir
,
1721 proc_fdinfo_instantiate
);
1724 static const struct file_operations proc_fdinfo_operations
= {
1725 .read
= generic_read_dir
,
1726 .readdir
= proc_readfdinfo
,
1730 * proc directories can do almost nothing..
1732 static const struct inode_operations proc_fdinfo_inode_operations
= {
1733 .lookup
= proc_lookupfdinfo
,
1734 .setattr
= proc_setattr
,
1738 static struct dentry
*proc_pident_instantiate(struct inode
*dir
,
1739 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1741 const struct pid_entry
*p
= ptr
;
1742 struct inode
*inode
;
1743 struct proc_inode
*ei
;
1744 struct dentry
*error
= ERR_PTR(-EINVAL
);
1746 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1751 inode
->i_mode
= p
->mode
;
1752 if (S_ISDIR(inode
->i_mode
))
1753 inode
->i_nlink
= 2; /* Use getattr to fix if necessary */
1755 inode
->i_op
= p
->iop
;
1757 inode
->i_fop
= p
->fop
;
1759 dentry
->d_op
= &pid_dentry_operations
;
1760 d_add(dentry
, inode
);
1761 /* Close the race of the process dying before we return the dentry */
1762 if (pid_revalidate(dentry
, NULL
))
1768 static struct dentry
*proc_pident_lookup(struct inode
*dir
,
1769 struct dentry
*dentry
,
1770 const struct pid_entry
*ents
,
1773 struct inode
*inode
;
1774 struct dentry
*error
;
1775 struct task_struct
*task
= get_proc_task(dir
);
1776 const struct pid_entry
*p
, *last
;
1778 error
= ERR_PTR(-ENOENT
);
1785 * Yes, it does not scale. And it should not. Don't add
1786 * new entries into /proc/<tgid>/ without very good reasons.
1788 last
= &ents
[nents
- 1];
1789 for (p
= ents
; p
<= last
; p
++) {
1790 if (p
->len
!= dentry
->d_name
.len
)
1792 if (!memcmp(dentry
->d_name
.name
, p
->name
, p
->len
))
1798 error
= proc_pident_instantiate(dir
, dentry
, task
, p
);
1800 put_task_struct(task
);
1805 static int proc_pident_fill_cache(struct file
*filp
, void *dirent
,
1806 filldir_t filldir
, struct task_struct
*task
, const struct pid_entry
*p
)
1808 return proc_fill_cache(filp
, dirent
, filldir
, p
->name
, p
->len
,
1809 proc_pident_instantiate
, task
, p
);
1812 static int proc_pident_readdir(struct file
*filp
,
1813 void *dirent
, filldir_t filldir
,
1814 const struct pid_entry
*ents
, unsigned int nents
)
1817 struct dentry
*dentry
= filp
->f_path
.dentry
;
1818 struct inode
*inode
= dentry
->d_inode
;
1819 struct task_struct
*task
= get_proc_task(inode
);
1820 const struct pid_entry
*p
, *last
;
1833 if (filldir(dirent
, ".", 1, i
, ino
, DT_DIR
) < 0)
1839 ino
= parent_ino(dentry
);
1840 if (filldir(dirent
, "..", 2, i
, ino
, DT_DIR
) < 0)
1852 last
= &ents
[nents
- 1];
1854 if (proc_pident_fill_cache(filp
, dirent
, filldir
, task
, p
) < 0)
1863 put_task_struct(task
);
1868 #ifdef CONFIG_SECURITY
1869 static ssize_t
proc_pid_attr_read(struct file
* file
, char __user
* buf
,
1870 size_t count
, loff_t
*ppos
)
1872 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
1875 struct task_struct
*task
= get_proc_task(inode
);
1880 length
= security_getprocattr(task
,
1881 (char*)file
->f_path
.dentry
->d_name
.name
,
1883 put_task_struct(task
);
1885 length
= simple_read_from_buffer(buf
, count
, ppos
, p
, length
);
1890 static ssize_t
proc_pid_attr_write(struct file
* file
, const char __user
* buf
,
1891 size_t count
, loff_t
*ppos
)
1893 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
1896 struct task_struct
*task
= get_proc_task(inode
);
1901 if (count
> PAGE_SIZE
)
1904 /* No partial writes. */
1910 page
= (char*)__get_free_page(GFP_TEMPORARY
);
1915 if (copy_from_user(page
, buf
, count
))
1918 length
= security_setprocattr(task
,
1919 (char*)file
->f_path
.dentry
->d_name
.name
,
1920 (void*)page
, count
);
1922 free_page((unsigned long) page
);
1924 put_task_struct(task
);
1929 static const struct file_operations proc_pid_attr_operations
= {
1930 .read
= proc_pid_attr_read
,
1931 .write
= proc_pid_attr_write
,
1934 static const struct pid_entry attr_dir_stuff
[] = {
1935 REG("current", S_IRUGO
|S_IWUGO
, pid_attr
),
1936 REG("prev", S_IRUGO
, pid_attr
),
1937 REG("exec", S_IRUGO
|S_IWUGO
, pid_attr
),
1938 REG("fscreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1939 REG("keycreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1940 REG("sockcreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1943 static int proc_attr_dir_readdir(struct file
* filp
,
1944 void * dirent
, filldir_t filldir
)
1946 return proc_pident_readdir(filp
,dirent
,filldir
,
1947 attr_dir_stuff
,ARRAY_SIZE(attr_dir_stuff
));
1950 static const struct file_operations proc_attr_dir_operations
= {
1951 .read
= generic_read_dir
,
1952 .readdir
= proc_attr_dir_readdir
,
1955 static struct dentry
*proc_attr_dir_lookup(struct inode
*dir
,
1956 struct dentry
*dentry
, struct nameidata
*nd
)
1958 return proc_pident_lookup(dir
, dentry
,
1959 attr_dir_stuff
, ARRAY_SIZE(attr_dir_stuff
));
1962 static const struct inode_operations proc_attr_dir_inode_operations
= {
1963 .lookup
= proc_attr_dir_lookup
,
1964 .getattr
= pid_getattr
,
1965 .setattr
= proc_setattr
,
1970 #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
1971 static ssize_t
proc_coredump_filter_read(struct file
*file
, char __user
*buf
,
1972 size_t count
, loff_t
*ppos
)
1974 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
1975 struct mm_struct
*mm
;
1976 char buffer
[PROC_NUMBUF
];
1984 mm
= get_task_mm(task
);
1986 len
= snprintf(buffer
, sizeof(buffer
), "%08lx\n",
1987 ((mm
->flags
& MMF_DUMP_FILTER_MASK
) >>
1988 MMF_DUMP_FILTER_SHIFT
));
1990 ret
= simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
1993 put_task_struct(task
);
1998 static ssize_t
proc_coredump_filter_write(struct file
*file
,
1999 const char __user
*buf
,
2003 struct task_struct
*task
;
2004 struct mm_struct
*mm
;
2005 char buffer
[PROC_NUMBUF
], *end
;
2012 memset(buffer
, 0, sizeof(buffer
));
2013 if (count
> sizeof(buffer
) - 1)
2014 count
= sizeof(buffer
) - 1;
2015 if (copy_from_user(buffer
, buf
, count
))
2019 val
= (unsigned int)simple_strtoul(buffer
, &end
, 0);
2022 if (end
- buffer
== 0)
2026 task
= get_proc_task(file
->f_dentry
->d_inode
);
2031 mm
= get_task_mm(task
);
2035 for (i
= 0, mask
= 1; i
< MMF_DUMP_FILTER_BITS
; i
++, mask
<<= 1) {
2037 set_bit(i
+ MMF_DUMP_FILTER_SHIFT
, &mm
->flags
);
2039 clear_bit(i
+ MMF_DUMP_FILTER_SHIFT
, &mm
->flags
);
2044 put_task_struct(task
);
2049 static const struct file_operations proc_coredump_filter_operations
= {
2050 .read
= proc_coredump_filter_read
,
2051 .write
= proc_coredump_filter_write
,
2058 static int proc_self_readlink(struct dentry
*dentry
, char __user
*buffer
,
2061 char tmp
[PROC_NUMBUF
];
2062 sprintf(tmp
, "%d", task_tgid_vnr(current
));
2063 return vfs_readlink(dentry
,buffer
,buflen
,tmp
);
2066 static void *proc_self_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
2068 char tmp
[PROC_NUMBUF
];
2069 sprintf(tmp
, "%d", task_tgid_vnr(current
));
2070 return ERR_PTR(vfs_follow_link(nd
,tmp
));
2073 static const struct inode_operations proc_self_inode_operations
= {
2074 .readlink
= proc_self_readlink
,
2075 .follow_link
= proc_self_follow_link
,
2081 * These are the directory entries in the root directory of /proc
2082 * that properly belong to the /proc filesystem, as they describe
2083 * describe something that is process related.
2085 static const struct pid_entry proc_base_stuff
[] = {
2086 NOD("self", S_IFLNK
|S_IRWXUGO
,
2087 &proc_self_inode_operations
, NULL
, {}),
2091 * Exceptional case: normally we are not allowed to unhash a busy
2092 * directory. In this case, however, we can do it - no aliasing problems
2093 * due to the way we treat inodes.
2095 static int proc_base_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
2097 struct inode
*inode
= dentry
->d_inode
;
2098 struct task_struct
*task
= get_proc_task(inode
);
2100 put_task_struct(task
);
2107 static struct dentry_operations proc_base_dentry_operations
=
2109 .d_revalidate
= proc_base_revalidate
,
2110 .d_delete
= pid_delete_dentry
,
2113 static struct dentry
*proc_base_instantiate(struct inode
*dir
,
2114 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
2116 const struct pid_entry
*p
= ptr
;
2117 struct inode
*inode
;
2118 struct proc_inode
*ei
;
2119 struct dentry
*error
= ERR_PTR(-EINVAL
);
2121 /* Allocate the inode */
2122 error
= ERR_PTR(-ENOMEM
);
2123 inode
= new_inode(dir
->i_sb
);
2127 /* Initialize the inode */
2129 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
2132 * grab the reference to the task.
2134 ei
->pid
= get_task_pid(task
, PIDTYPE_PID
);
2140 inode
->i_mode
= p
->mode
;
2141 if (S_ISDIR(inode
->i_mode
))
2143 if (S_ISLNK(inode
->i_mode
))
2146 inode
->i_op
= p
->iop
;
2148 inode
->i_fop
= p
->fop
;
2150 dentry
->d_op
= &proc_base_dentry_operations
;
2151 d_add(dentry
, inode
);
2160 static struct dentry
*proc_base_lookup(struct inode
*dir
, struct dentry
*dentry
)
2162 struct dentry
*error
;
2163 struct task_struct
*task
= get_proc_task(dir
);
2164 const struct pid_entry
*p
, *last
;
2166 error
= ERR_PTR(-ENOENT
);
2171 /* Lookup the directory entry */
2172 last
= &proc_base_stuff
[ARRAY_SIZE(proc_base_stuff
) - 1];
2173 for (p
= proc_base_stuff
; p
<= last
; p
++) {
2174 if (p
->len
!= dentry
->d_name
.len
)
2176 if (!memcmp(dentry
->d_name
.name
, p
->name
, p
->len
))
2182 error
= proc_base_instantiate(dir
, dentry
, task
, p
);
2185 put_task_struct(task
);
2190 static int proc_base_fill_cache(struct file
*filp
, void *dirent
,
2191 filldir_t filldir
, struct task_struct
*task
, const struct pid_entry
*p
)
2193 return proc_fill_cache(filp
, dirent
, filldir
, p
->name
, p
->len
,
2194 proc_base_instantiate
, task
, p
);
2197 #ifdef CONFIG_TASK_IO_ACCOUNTING
2198 static int proc_pid_io_accounting(struct task_struct
*task
, char *buffer
)
2200 return sprintf(buffer
,
2201 #ifdef CONFIG_TASK_XACCT
2207 "read_bytes: %llu\n"
2208 "write_bytes: %llu\n"
2209 "cancelled_write_bytes: %llu\n",
2210 #ifdef CONFIG_TASK_XACCT
2211 (unsigned long long)task
->rchar
,
2212 (unsigned long long)task
->wchar
,
2213 (unsigned long long)task
->syscr
,
2214 (unsigned long long)task
->syscw
,
2216 (unsigned long long)task
->ioac
.read_bytes
,
2217 (unsigned long long)task
->ioac
.write_bytes
,
2218 (unsigned long long)task
->ioac
.cancelled_write_bytes
);
2225 static const struct file_operations proc_task_operations
;
2226 static const struct inode_operations proc_task_inode_operations
;
2228 static const struct pid_entry tgid_base_stuff
[] = {
2229 DIR("task", S_IRUGO
|S_IXUGO
, task
),
2230 DIR("fd", S_IRUSR
|S_IXUSR
, fd
),
2231 DIR("fdinfo", S_IRUSR
|S_IXUSR
, fdinfo
),
2232 REG("environ", S_IRUSR
, environ
),
2233 INF("auxv", S_IRUSR
, pid_auxv
),
2234 INF("status", S_IRUGO
, pid_status
),
2235 INF("limits", S_IRUSR
, pid_limits
),
2236 #ifdef CONFIG_SCHED_DEBUG
2237 REG("sched", S_IRUGO
|S_IWUSR
, pid_sched
),
2239 INF("cmdline", S_IRUGO
, pid_cmdline
),
2240 INF("stat", S_IRUGO
, tgid_stat
),
2241 INF("statm", S_IRUGO
, pid_statm
),
2242 REG("maps", S_IRUGO
, maps
),
2244 REG("numa_maps", S_IRUGO
, numa_maps
),
2246 REG("mem", S_IRUSR
|S_IWUSR
, mem
),
2250 REG("mounts", S_IRUGO
, mounts
),
2251 REG("mountstats", S_IRUSR
, mountstats
),
2253 REG("clear_refs", S_IWUSR
, clear_refs
),
2254 REG("smaps", S_IRUGO
, smaps
),
2256 #ifdef CONFIG_SECURITY
2257 DIR("attr", S_IRUGO
|S_IXUGO
, attr_dir
),
2259 #ifdef CONFIG_KALLSYMS
2260 INF("wchan", S_IRUGO
, pid_wchan
),
2262 #ifdef CONFIG_SCHEDSTATS
2263 INF("schedstat", S_IRUGO
, pid_schedstat
),
2265 #ifdef CONFIG_LATENCYTOP
2266 REG("latency", S_IRUGO
, lstats
),
2268 #ifdef CONFIG_PROC_PID_CPUSET
2269 REG("cpuset", S_IRUGO
, cpuset
),
2271 #ifdef CONFIG_CGROUPS
2272 REG("cgroup", S_IRUGO
, cgroup
),
2274 INF("oom_score", S_IRUGO
, oom_score
),
2275 REG("oom_adj", S_IRUGO
|S_IWUSR
, oom_adjust
),
2276 #ifdef CONFIG_AUDITSYSCALL
2277 REG("loginuid", S_IWUSR
|S_IRUGO
, loginuid
),
2279 #ifdef CONFIG_FAULT_INJECTION
2280 REG("make-it-fail", S_IRUGO
|S_IWUSR
, fault_inject
),
2282 #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
2283 REG("coredump_filter", S_IRUGO
|S_IWUSR
, coredump_filter
),
2285 #ifdef CONFIG_TASK_IO_ACCOUNTING
2286 INF("io", S_IRUGO
, pid_io_accounting
),
2290 static int proc_tgid_base_readdir(struct file
* filp
,
2291 void * dirent
, filldir_t filldir
)
2293 return proc_pident_readdir(filp
,dirent
,filldir
,
2294 tgid_base_stuff
,ARRAY_SIZE(tgid_base_stuff
));
2297 static const struct file_operations proc_tgid_base_operations
= {
2298 .read
= generic_read_dir
,
2299 .readdir
= proc_tgid_base_readdir
,
2302 static struct dentry
*proc_tgid_base_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
){
2303 return proc_pident_lookup(dir
, dentry
,
2304 tgid_base_stuff
, ARRAY_SIZE(tgid_base_stuff
));
2307 static const struct inode_operations proc_tgid_base_inode_operations
= {
2308 .lookup
= proc_tgid_base_lookup
,
2309 .getattr
= pid_getattr
,
2310 .setattr
= proc_setattr
,
2313 static void proc_flush_task_mnt(struct vfsmount
*mnt
, pid_t pid
, pid_t tgid
)
2315 struct dentry
*dentry
, *leader
, *dir
;
2316 char buf
[PROC_NUMBUF
];
2320 name
.len
= snprintf(buf
, sizeof(buf
), "%d", pid
);
2321 dentry
= d_hash_and_lookup(mnt
->mnt_root
, &name
);
2323 shrink_dcache_parent(dentry
);
2332 name
.len
= snprintf(buf
, sizeof(buf
), "%d", tgid
);
2333 leader
= d_hash_and_lookup(mnt
->mnt_root
, &name
);
2338 name
.len
= strlen(name
.name
);
2339 dir
= d_hash_and_lookup(leader
, &name
);
2341 goto out_put_leader
;
2344 name
.len
= snprintf(buf
, sizeof(buf
), "%d", pid
);
2345 dentry
= d_hash_and_lookup(dir
, &name
);
2347 shrink_dcache_parent(dentry
);
2360 * proc_flush_task - Remove dcache entries for @task from the /proc dcache.
2361 * @task: task that should be flushed.
2363 * When flushing dentries from proc, one needs to flush them from global
2364 * proc (proc_mnt) and from all the namespaces' procs this task was seen
2365 * in. This call is supposed to do all of this job.
2367 * Looks in the dcache for
2369 * /proc/@tgid/task/@pid
2370 * if either directory is present flushes it and all of it'ts children
2373 * It is safe and reasonable to cache /proc entries for a task until
2374 * that task exits. After that they just clog up the dcache with
2375 * useless entries, possibly causing useful dcache entries to be
2376 * flushed instead. This routine is proved to flush those useless
2377 * dcache entries at process exit time.
2379 * NOTE: This routine is just an optimization so it does not guarantee
2380 * that no dcache entries will exist at process exit time it
2381 * just makes it very unlikely that any will persist.
2384 void proc_flush_task(struct task_struct
*task
)
2387 struct pid
*pid
, *tgid
= NULL
;
2390 pid
= task_pid(task
);
2391 if (thread_group_leader(task
))
2392 tgid
= task_tgid(task
);
2394 for (i
= 0; i
<= pid
->level
; i
++) {
2395 upid
= &pid
->numbers
[i
];
2396 proc_flush_task_mnt(upid
->ns
->proc_mnt
, upid
->nr
,
2397 tgid
? tgid
->numbers
[i
].nr
: 0);
2400 upid
= &pid
->numbers
[pid
->level
];
2402 pid_ns_release_proc(upid
->ns
);
2405 static struct dentry
*proc_pid_instantiate(struct inode
*dir
,
2406 struct dentry
* dentry
,
2407 struct task_struct
*task
, const void *ptr
)
2409 struct dentry
*error
= ERR_PTR(-ENOENT
);
2410 struct inode
*inode
;
2412 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
2416 inode
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
2417 inode
->i_op
= &proc_tgid_base_inode_operations
;
2418 inode
->i_fop
= &proc_tgid_base_operations
;
2419 inode
->i_flags
|=S_IMMUTABLE
;
2421 #ifdef CONFIG_SECURITY
2422 inode
->i_nlink
+= 1;
2425 dentry
->d_op
= &pid_dentry_operations
;
2427 d_add(dentry
, inode
);
2428 /* Close the race of the process dying before we return the dentry */
2429 if (pid_revalidate(dentry
, NULL
))
2435 struct dentry
*proc_pid_lookup(struct inode
*dir
, struct dentry
* dentry
, struct nameidata
*nd
)
2437 struct dentry
*result
= ERR_PTR(-ENOENT
);
2438 struct task_struct
*task
;
2440 struct pid_namespace
*ns
;
2442 result
= proc_base_lookup(dir
, dentry
);
2443 if (!IS_ERR(result
) || PTR_ERR(result
) != -ENOENT
)
2446 tgid
= name_to_int(dentry
);
2450 ns
= dentry
->d_sb
->s_fs_info
;
2452 task
= find_task_by_pid_ns(tgid
, ns
);
2454 get_task_struct(task
);
2459 result
= proc_pid_instantiate(dir
, dentry
, task
, NULL
);
2460 put_task_struct(task
);
2466 * Find the first task with tgid >= tgid
2471 struct task_struct
*task
;
2473 static struct tgid_iter
next_tgid(struct pid_namespace
*ns
, struct tgid_iter iter
)
2478 put_task_struct(iter
.task
);
2482 pid
= find_ge_pid(iter
.tgid
, ns
);
2484 iter
.tgid
= pid_nr_ns(pid
, ns
);
2485 iter
.task
= pid_task(pid
, PIDTYPE_PID
);
2486 /* What we to know is if the pid we have find is the
2487 * pid of a thread_group_leader. Testing for task
2488 * being a thread_group_leader is the obvious thing
2489 * todo but there is a window when it fails, due to
2490 * the pid transfer logic in de_thread.
2492 * So we perform the straight forward test of seeing
2493 * if the pid we have found is the pid of a thread
2494 * group leader, and don't worry if the task we have
2495 * found doesn't happen to be a thread group leader.
2496 * As we don't care in the case of readdir.
2498 if (!iter
.task
|| !has_group_leader_pid(iter
.task
)) {
2502 get_task_struct(iter
.task
);
2508 #define TGID_OFFSET (FIRST_PROCESS_ENTRY + ARRAY_SIZE(proc_base_stuff))
2510 static int proc_pid_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
2511 struct tgid_iter iter
)
2513 char name
[PROC_NUMBUF
];
2514 int len
= snprintf(name
, sizeof(name
), "%d", iter
.tgid
);
2515 return proc_fill_cache(filp
, dirent
, filldir
, name
, len
,
2516 proc_pid_instantiate
, iter
.task
, NULL
);
2519 /* for the /proc/ directory itself, after non-process stuff has been done */
2520 int proc_pid_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
2522 unsigned int nr
= filp
->f_pos
- FIRST_PROCESS_ENTRY
;
2523 struct task_struct
*reaper
= get_proc_task(filp
->f_path
.dentry
->d_inode
);
2524 struct tgid_iter iter
;
2525 struct pid_namespace
*ns
;
2530 for (; nr
< ARRAY_SIZE(proc_base_stuff
); filp
->f_pos
++, nr
++) {
2531 const struct pid_entry
*p
= &proc_base_stuff
[nr
];
2532 if (proc_base_fill_cache(filp
, dirent
, filldir
, reaper
, p
) < 0)
2536 ns
= filp
->f_dentry
->d_sb
->s_fs_info
;
2538 iter
.tgid
= filp
->f_pos
- TGID_OFFSET
;
2539 for (iter
= next_tgid(ns
, iter
);
2541 iter
.tgid
+= 1, iter
= next_tgid(ns
, iter
)) {
2542 filp
->f_pos
= iter
.tgid
+ TGID_OFFSET
;
2543 if (proc_pid_fill_cache(filp
, dirent
, filldir
, iter
) < 0) {
2544 put_task_struct(iter
.task
);
2548 filp
->f_pos
= PID_MAX_LIMIT
+ TGID_OFFSET
;
2550 put_task_struct(reaper
);
2558 static const struct pid_entry tid_base_stuff
[] = {
2559 DIR("fd", S_IRUSR
|S_IXUSR
, fd
),
2560 DIR("fdinfo", S_IRUSR
|S_IXUSR
, fdinfo
),
2561 REG("environ", S_IRUSR
, environ
),
2562 INF("auxv", S_IRUSR
, pid_auxv
),
2563 INF("status", S_IRUGO
, pid_status
),
2564 INF("limits", S_IRUSR
, pid_limits
),
2565 #ifdef CONFIG_SCHED_DEBUG
2566 REG("sched", S_IRUGO
|S_IWUSR
, pid_sched
),
2568 INF("cmdline", S_IRUGO
, pid_cmdline
),
2569 INF("stat", S_IRUGO
, tid_stat
),
2570 INF("statm", S_IRUGO
, pid_statm
),
2571 REG("maps", S_IRUGO
, maps
),
2573 REG("numa_maps", S_IRUGO
, numa_maps
),
2575 REG("mem", S_IRUSR
|S_IWUSR
, mem
),
2579 REG("mounts", S_IRUGO
, mounts
),
2581 REG("clear_refs", S_IWUSR
, clear_refs
),
2582 REG("smaps", S_IRUGO
, smaps
),
2584 #ifdef CONFIG_SECURITY
2585 DIR("attr", S_IRUGO
|S_IXUGO
, attr_dir
),
2587 #ifdef CONFIG_KALLSYMS
2588 INF("wchan", S_IRUGO
, pid_wchan
),
2590 #ifdef CONFIG_SCHEDSTATS
2591 INF("schedstat", S_IRUGO
, pid_schedstat
),
2593 #ifdef CONFIG_LATENCYTOP
2594 REG("latency", S_IRUGO
, lstats
),
2596 #ifdef CONFIG_PROC_PID_CPUSET
2597 REG("cpuset", S_IRUGO
, cpuset
),
2599 #ifdef CONFIG_CGROUPS
2600 REG("cgroup", S_IRUGO
, cgroup
),
2602 INF("oom_score", S_IRUGO
, oom_score
),
2603 REG("oom_adj", S_IRUGO
|S_IWUSR
, oom_adjust
),
2604 #ifdef CONFIG_AUDITSYSCALL
2605 REG("loginuid", S_IWUSR
|S_IRUGO
, loginuid
),
2607 #ifdef CONFIG_FAULT_INJECTION
2608 REG("make-it-fail", S_IRUGO
|S_IWUSR
, fault_inject
),
2612 static int proc_tid_base_readdir(struct file
* filp
,
2613 void * dirent
, filldir_t filldir
)
2615 return proc_pident_readdir(filp
,dirent
,filldir
,
2616 tid_base_stuff
,ARRAY_SIZE(tid_base_stuff
));
2619 static struct dentry
*proc_tid_base_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
){
2620 return proc_pident_lookup(dir
, dentry
,
2621 tid_base_stuff
, ARRAY_SIZE(tid_base_stuff
));
2624 static const struct file_operations proc_tid_base_operations
= {
2625 .read
= generic_read_dir
,
2626 .readdir
= proc_tid_base_readdir
,
2629 static const struct inode_operations proc_tid_base_inode_operations
= {
2630 .lookup
= proc_tid_base_lookup
,
2631 .getattr
= pid_getattr
,
2632 .setattr
= proc_setattr
,
2635 static struct dentry
*proc_task_instantiate(struct inode
*dir
,
2636 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
2638 struct dentry
*error
= ERR_PTR(-ENOENT
);
2639 struct inode
*inode
;
2640 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
2644 inode
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
2645 inode
->i_op
= &proc_tid_base_inode_operations
;
2646 inode
->i_fop
= &proc_tid_base_operations
;
2647 inode
->i_flags
|=S_IMMUTABLE
;
2649 #ifdef CONFIG_SECURITY
2650 inode
->i_nlink
+= 1;
2653 dentry
->d_op
= &pid_dentry_operations
;
2655 d_add(dentry
, inode
);
2656 /* Close the race of the process dying before we return the dentry */
2657 if (pid_revalidate(dentry
, NULL
))
2663 static struct dentry
*proc_task_lookup(struct inode
*dir
, struct dentry
* dentry
, struct nameidata
*nd
)
2665 struct dentry
*result
= ERR_PTR(-ENOENT
);
2666 struct task_struct
*task
;
2667 struct task_struct
*leader
= get_proc_task(dir
);
2669 struct pid_namespace
*ns
;
2674 tid
= name_to_int(dentry
);
2678 ns
= dentry
->d_sb
->s_fs_info
;
2680 task
= find_task_by_pid_ns(tid
, ns
);
2682 get_task_struct(task
);
2686 if (!same_thread_group(leader
, task
))
2689 result
= proc_task_instantiate(dir
, dentry
, task
, NULL
);
2691 put_task_struct(task
);
2693 put_task_struct(leader
);
2699 * Find the first tid of a thread group to return to user space.
2701 * Usually this is just the thread group leader, but if the users
2702 * buffer was too small or there was a seek into the middle of the
2703 * directory we have more work todo.
2705 * In the case of a short read we start with find_task_by_pid.
2707 * In the case of a seek we start with the leader and walk nr
2710 static struct task_struct
*first_tid(struct task_struct
*leader
,
2711 int tid
, int nr
, struct pid_namespace
*ns
)
2713 struct task_struct
*pos
;
2716 /* Attempt to start with the pid of a thread */
2717 if (tid
&& (nr
> 0)) {
2718 pos
= find_task_by_pid_ns(tid
, ns
);
2719 if (pos
&& (pos
->group_leader
== leader
))
2723 /* If nr exceeds the number of threads there is nothing todo */
2725 if (nr
&& nr
>= get_nr_threads(leader
))
2728 /* If we haven't found our starting place yet start
2729 * with the leader and walk nr threads forward.
2731 for (pos
= leader
; nr
> 0; --nr
) {
2732 pos
= next_thread(pos
);
2733 if (pos
== leader
) {
2739 get_task_struct(pos
);
2746 * Find the next thread in the thread list.
2747 * Return NULL if there is an error or no next thread.
2749 * The reference to the input task_struct is released.
2751 static struct task_struct
*next_tid(struct task_struct
*start
)
2753 struct task_struct
*pos
= NULL
;
2755 if (pid_alive(start
)) {
2756 pos
= next_thread(start
);
2757 if (thread_group_leader(pos
))
2760 get_task_struct(pos
);
2763 put_task_struct(start
);
2767 static int proc_task_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
2768 struct task_struct
*task
, int tid
)
2770 char name
[PROC_NUMBUF
];
2771 int len
= snprintf(name
, sizeof(name
), "%d", tid
);
2772 return proc_fill_cache(filp
, dirent
, filldir
, name
, len
,
2773 proc_task_instantiate
, task
, NULL
);
2776 /* for the /proc/TGID/task/ directories */
2777 static int proc_task_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
2779 struct dentry
*dentry
= filp
->f_path
.dentry
;
2780 struct inode
*inode
= dentry
->d_inode
;
2781 struct task_struct
*leader
= NULL
;
2782 struct task_struct
*task
;
2783 int retval
= -ENOENT
;
2786 unsigned long pos
= filp
->f_pos
; /* avoiding "long long" filp->f_pos */
2787 struct pid_namespace
*ns
;
2789 task
= get_proc_task(inode
);
2793 if (pid_alive(task
)) {
2794 leader
= task
->group_leader
;
2795 get_task_struct(leader
);
2798 put_task_struct(task
);
2806 if (filldir(dirent
, ".", 1, pos
, ino
, DT_DIR
) < 0)
2811 ino
= parent_ino(dentry
);
2812 if (filldir(dirent
, "..", 2, pos
, ino
, DT_DIR
) < 0)
2818 /* f_version caches the tgid value that the last readdir call couldn't
2819 * return. lseek aka telldir automagically resets f_version to 0.
2821 ns
= filp
->f_dentry
->d_sb
->s_fs_info
;
2822 tid
= (int)filp
->f_version
;
2823 filp
->f_version
= 0;
2824 for (task
= first_tid(leader
, tid
, pos
- 2, ns
);
2826 task
= next_tid(task
), pos
++) {
2827 tid
= task_pid_nr_ns(task
, ns
);
2828 if (proc_task_fill_cache(filp
, dirent
, filldir
, task
, tid
) < 0) {
2829 /* returning this tgid failed, save it as the first
2830 * pid for the next readir call */
2831 filp
->f_version
= (u64
)tid
;
2832 put_task_struct(task
);
2838 put_task_struct(leader
);
2843 static int proc_task_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
, struct kstat
*stat
)
2845 struct inode
*inode
= dentry
->d_inode
;
2846 struct task_struct
*p
= get_proc_task(inode
);
2847 generic_fillattr(inode
, stat
);
2851 stat
->nlink
+= get_nr_threads(p
);
2859 static const struct inode_operations proc_task_inode_operations
= {
2860 .lookup
= proc_task_lookup
,
2861 .getattr
= proc_task_getattr
,
2862 .setattr
= proc_setattr
,
2865 static const struct file_operations proc_task_operations
= {
2866 .read
= generic_read_dir
,
2867 .readdir
= proc_task_readdir
,