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.
16 #include <asm/uaccess.h>
18 #include <linux/config.h>
19 #include <linux/errno.h>
20 #include <linux/time.h>
21 #include <linux/proc_fs.h>
22 #include <linux/stat.h>
23 #include <linux/init.h>
24 #include <linux/file.h>
25 #include <linux/string.h>
26 #include <linux/seq_file.h>
27 #include <linux/namei.h>
28 #include <linux/namespace.h>
30 #include <linux/smp_lock.h>
31 #include <linux/kallsyms.h>
32 #include <linux/mount.h>
33 #include <linux/security.h>
34 #include <linux/ptrace.h>
35 #include <linux/vs_network.h>
39 * For hysterical raisins we keep the same inumbers as in the old procfs.
40 * Feel free to change the macro below - just keep the range distinct from
41 * inumbers of the rest of procfs (currently those are in 0x0000--0xffff).
42 * As soon as we'll get a separate superblock we will be able to forget
43 * about magical ranges too.
46 #define fake_ino(pid,ino) (((pid)<<16)|(ino))
48 enum pid_directory_inos {
65 #ifdef CONFIG_SCHEDSTATS
68 #ifdef CONFIG_SECURITY
70 PROC_TGID_ATTR_CURRENT,
73 PROC_TGID_ATTR_FSCREATE,
77 #ifdef CONFIG_AUDITSYSCALL
98 #ifdef CONFIG_SCHEDSTATS
101 #ifdef CONFIG_SECURITY
103 PROC_TID_ATTR_CURRENT,
106 PROC_TID_ATTR_FSCREATE,
110 #ifdef CONFIG_AUDITSYSCALL
113 PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */
125 #define E(type,name,mode) {(type),sizeof(name)-1,(name),(mode)}
127 static struct pid_entry tgid_base_stuff[] = {
128 E(PROC_TGID_TASK, "task", S_IFDIR|S_IRUGO|S_IXUGO),
129 E(PROC_TGID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR),
130 E(PROC_TGID_ENVIRON, "environ", S_IFREG|S_IRUSR),
131 E(PROC_TGID_AUXV, "auxv", S_IFREG|S_IRUSR),
132 E(PROC_TGID_STATUS, "status", S_IFREG|S_IRUGO),
133 E(PROC_TGID_CMDLINE, "cmdline", S_IFREG|S_IRUGO),
134 E(PROC_TGID_STAT, "stat", S_IFREG|S_IRUGO),
135 E(PROC_TGID_STATM, "statm", S_IFREG|S_IRUGO),
136 E(PROC_TGID_MAPS, "maps", S_IFREG|S_IRUGO),
137 E(PROC_TGID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR),
138 E(PROC_TGID_CWD, "cwd", S_IFLNK|S_IRWXUGO),
139 E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO),
140 E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO),
141 E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO),
142 #ifdef CONFIG_SECURITY
143 E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO),
145 #ifdef CONFIG_KALLSYMS
146 E(PROC_TGID_WCHAN, "wchan", S_IFREG|S_IRUGO),
148 #ifdef CONFIG_SCHEDSTATS
149 E(PROC_TGID_SCHEDSTAT, "schedstat", S_IFREG|S_IRUGO),
151 E(PROC_TGID_VX_INFO, "vinfo", S_IFREG|S_IRUGO),
152 E(PROC_TGID_IP_INFO, "ninfo", S_IFREG|S_IRUGO),
153 E(PROC_TGID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO),
154 E(PROC_TGID_OOM_ADJUST,"oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
155 #ifdef CONFIG_AUDITSYSCALL
156 E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
160 static struct pid_entry tid_base_stuff[] = {
161 E(PROC_TID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR),
162 E(PROC_TID_ENVIRON, "environ", S_IFREG|S_IRUSR),
163 E(PROC_TID_AUXV, "auxv", S_IFREG|S_IRUSR),
164 E(PROC_TID_STATUS, "status", S_IFREG|S_IRUGO),
165 E(PROC_TID_CMDLINE, "cmdline", S_IFREG|S_IRUGO),
166 E(PROC_TID_STAT, "stat", S_IFREG|S_IRUGO),
167 E(PROC_TID_STATM, "statm", S_IFREG|S_IRUGO),
168 E(PROC_TID_MAPS, "maps", S_IFREG|S_IRUGO),
169 E(PROC_TID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR),
170 E(PROC_TID_CWD, "cwd", S_IFLNK|S_IRWXUGO),
171 E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO),
172 E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO),
173 E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO),
174 #ifdef CONFIG_SECURITY
175 E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO),
177 #ifdef CONFIG_KALLSYMS
178 E(PROC_TID_WCHAN, "wchan", S_IFREG|S_IRUGO),
180 #ifdef CONFIG_SCHEDSTATS
181 E(PROC_TID_SCHEDSTAT, "schedstat",S_IFREG|S_IRUGO),
183 E(PROC_TID_VX_INFO, "vinfo", S_IFREG|S_IRUGO),
184 E(PROC_TID_IP_INFO, "ninfo", S_IFREG|S_IRUGO),
185 E(PROC_TID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO),
186 E(PROC_TID_OOM_ADJUST, "oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
187 #ifdef CONFIG_AUDITSYSCALL
188 E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
193 #ifdef CONFIG_SECURITY
194 static struct pid_entry tgid_attr_stuff[] = {
195 E(PROC_TGID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO),
196 E(PROC_TGID_ATTR_PREV, "prev", S_IFREG|S_IRUGO),
197 E(PROC_TGID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO),
198 E(PROC_TGID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO),
201 static struct pid_entry tid_attr_stuff[] = {
202 E(PROC_TID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO),
203 E(PROC_TID_ATTR_PREV, "prev", S_IFREG|S_IRUGO),
204 E(PROC_TID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO),
205 E(PROC_TID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO),
212 static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
214 struct task_struct *task = proc_task(inode);
215 struct files_struct *files;
217 int fd = proc_type(inode) - PROC_TID_FD_DIR;
219 files = get_files_struct(task);
221 spin_lock(&files->file_lock);
222 file = fcheck_files(files, fd);
224 *mnt = mntget(file->f_vfsmnt);
225 *dentry = dget(file->f_dentry);
226 spin_unlock(&files->file_lock);
227 put_files_struct(files);
230 spin_unlock(&files->file_lock);
231 put_files_struct(files);
236 static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
238 struct fs_struct *fs;
239 int result = -ENOENT;
240 task_lock(proc_task(inode));
241 fs = proc_task(inode)->fs;
243 atomic_inc(&fs->count);
244 task_unlock(proc_task(inode));
246 read_lock(&fs->lock);
247 *mnt = mntget(fs->pwdmnt);
248 *dentry = dget(fs->pwd);
249 read_unlock(&fs->lock);
256 static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
258 struct fs_struct *fs;
259 int result = -ENOENT;
260 task_lock(proc_task(inode));
261 fs = proc_task(inode)->fs;
263 atomic_inc(&fs->count);
264 task_unlock(proc_task(inode));
266 read_lock(&fs->lock);
267 *mnt = mntget(fs->rootmnt);
268 *dentry = dget(fs->root);
269 read_unlock(&fs->lock);
276 #define MAY_PTRACE(task) \
277 (task == current || \
278 (task->parent == current && \
279 (task->ptrace & PT_PTRACED) && \
280 (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \
281 security_ptrace(current,task) == 0))
283 static int may_ptrace_attach(struct task_struct *task)
291 if (((current->uid != task->euid) ||
292 (current->uid != task->suid) ||
293 (current->uid != task->uid) ||
294 (current->gid != task->egid) ||
295 (current->gid != task->sgid) ||
296 (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
299 if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
301 if (security_ptrace(current, task))
310 static int proc_pid_environ(struct task_struct *task, char * buffer)
313 struct mm_struct *mm = get_task_mm(task);
315 unsigned int len = mm->env_end - mm->env_start;
318 res = access_process_vm(task, mm->env_start, buffer, len, 0);
319 if (!may_ptrace_attach(task))
326 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
330 struct mm_struct *mm = get_task_mm(task);
334 goto out_mm; /* Shh! No looking before we're done */
336 len = mm->arg_end - mm->arg_start;
341 res = access_process_vm(task, mm->arg_start, buffer, len, 0);
343 // If the nul at the end of args has been overwritten, then
344 // assume application is using setproctitle(3).
345 if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) {
346 len = strnlen(buffer, res);
350 len = mm->env_end - mm->env_start;
351 if (len > PAGE_SIZE - res)
352 len = PAGE_SIZE - res;
353 res += access_process_vm(task, mm->env_start, buffer+res, len, 0);
354 res = strnlen(buffer, res);
363 static int proc_pid_auxv(struct task_struct *task, char *buffer)
366 struct mm_struct *mm = get_task_mm(task);
368 unsigned int nwords = 0;
371 while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
372 res = nwords * sizeof(mm->saved_auxv[0]);
375 memcpy(buffer, mm->saved_auxv, res);
382 #ifdef CONFIG_KALLSYMS
384 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
385 * Returns the resolved symbol. If that fails, simply return the address.
387 static int proc_pid_wchan(struct task_struct *task, char *buffer)
390 const char *sym_name;
391 unsigned long wchan, size, offset;
392 char namebuf[KSYM_NAME_LEN+1];
394 wchan = get_wchan(task);
396 sym_name = kallsyms_lookup(wchan, &size, &offset, &modname, namebuf);
398 return sprintf(buffer, "%s", sym_name);
399 return sprintf(buffer, "%lu", wchan);
401 #endif /* CONFIG_KALLSYMS */
403 #ifdef CONFIG_SCHEDSTATS
405 * Provides /proc/PID/schedstat
407 static int proc_pid_schedstat(struct task_struct *task, char *buffer)
409 return sprintf(buffer, "%lu %lu %lu\n",
410 task->sched_info.cpu_time,
411 task->sched_info.run_delay,
412 task->sched_info.pcnt);
416 /* The badness from the OOM killer */
417 unsigned long badness(struct task_struct *p, unsigned long uptime);
418 static int proc_oom_score(struct task_struct *task, char *buffer)
420 unsigned long points;
421 struct timespec uptime;
423 do_posix_clock_monotonic_gettime(&uptime);
424 points = badness(task, uptime.tv_sec);
425 return sprintf(buffer, "%lu\n", points);
428 /************************************************************************/
429 /* Here the fs part begins */
430 /************************************************************************/
432 /* permission checks */
434 static int proc_check_root(struct inode *inode)
436 struct dentry *de, *base, *root;
437 struct vfsmount *our_vfsmnt, *vfsmnt, *mnt;
440 if (proc_root_link(inode, &root, &vfsmnt)) /* Ewww... */
442 read_lock(¤t->fs->lock);
443 our_vfsmnt = mntget(current->fs->rootmnt);
444 base = dget(current->fs->root);
445 read_unlock(¤t->fs->lock);
447 spin_lock(&vfsmount_lock);
451 while (vfsmnt != our_vfsmnt) {
452 if (vfsmnt == vfsmnt->mnt_parent)
454 de = vfsmnt->mnt_mountpoint;
455 vfsmnt = vfsmnt->mnt_parent;
458 if (!is_subdir(de, base))
460 spin_unlock(&vfsmount_lock);
469 spin_unlock(&vfsmount_lock);
474 static int proc_permission(struct inode *inode, int mask, struct nameidata *nd)
476 if (generic_permission(inode, mask, NULL) != 0)
478 return proc_check_root(inode);
481 extern struct seq_operations proc_pid_maps_op;
482 static int maps_open(struct inode *inode, struct file *file)
484 struct task_struct *task = proc_task(inode);
485 int ret = seq_open(file, &proc_pid_maps_op);
487 struct seq_file *m = file->private_data;
493 static struct file_operations proc_maps_operations = {
497 .release = seq_release,
500 extern struct seq_operations mounts_op;
501 static int mounts_open(struct inode *inode, struct file *file)
503 struct task_struct *task = proc_task(inode);
504 int ret = seq_open(file, &mounts_op);
507 struct seq_file *m = file->private_data;
508 struct namespace *namespace;
510 namespace = task->namespace;
512 get_namespace(namespace);
516 m->private = namespace;
518 seq_release(inode, file);
525 static int mounts_release(struct inode *inode, struct file *file)
527 struct seq_file *m = file->private_data;
528 struct namespace *namespace = m->private;
529 put_namespace(namespace);
530 return seq_release(inode, file);
533 static struct file_operations proc_mounts_operations = {
537 .release = mounts_release,
540 #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
542 static ssize_t proc_info_read(struct file * file, char __user * buf,
543 size_t count, loff_t *ppos)
545 struct inode * inode = file->f_dentry->d_inode;
548 struct task_struct *task = proc_task(inode);
550 if (count > PROC_BLOCK_SIZE)
551 count = PROC_BLOCK_SIZE;
552 if (!(page = __get_free_page(GFP_KERNEL)))
555 length = PROC_I(inode)->op.proc_read(task, (char*)page);
558 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
563 static struct file_operations proc_info_file_operations = {
564 .read = proc_info_read,
567 static int mem_open(struct inode* inode, struct file* file)
569 file->private_data = (void*)((long)current->self_exec_id);
573 static ssize_t mem_read(struct file * file, char __user * buf,
574 size_t count, loff_t *ppos)
576 struct task_struct *task = proc_task(file->f_dentry->d_inode);
578 unsigned long src = *ppos;
580 struct mm_struct *mm;
582 if (!MAY_PTRACE(task) || !may_ptrace_attach(task))
586 page = (char *)__get_free_page(GFP_USER);
592 mm = get_task_mm(task);
598 if (file->private_data != (void*)((long)current->self_exec_id))
604 int this_len, retval;
606 this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
607 retval = access_process_vm(task, src, page, this_len, 0);
608 if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) {
614 if (copy_to_user(buf, page, retval)) {
629 free_page((unsigned long) page);
634 #define mem_write NULL
637 /* This is a security hazard */
638 static ssize_t mem_write(struct file * file, const char * buf,
639 size_t count, loff_t *ppos)
643 struct task_struct *task = proc_task(file->f_dentry->d_inode);
644 unsigned long dst = *ppos;
646 if (!MAY_PTRACE(task) || !may_ptrace_attach(task))
649 page = (char *)__get_free_page(GFP_USER);
654 int this_len, retval;
656 this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
657 if (copy_from_user(page, buf, this_len)) {
661 retval = access_process_vm(task, dst, page, this_len, 1);
673 free_page((unsigned long) page);
678 static loff_t mem_lseek(struct file * file, loff_t offset, int orig)
682 file->f_pos = offset;
685 file->f_pos += offset;
690 force_successful_syscall_return();
694 static struct file_operations proc_mem_operations = {
701 static ssize_t oom_adjust_read(struct file *file, char *buf,
702 size_t count, loff_t *ppos)
704 struct task_struct *task = proc_task(file->f_dentry->d_inode);
707 int oom_adjust = task->oomkilladj;
708 loff_t __ppos = *ppos;
710 len = sprintf(buffer, "%i\n", oom_adjust);
713 if (count > len-__ppos)
715 if (copy_to_user(buf, buffer + __ppos, count))
717 *ppos = __ppos + count;
721 static ssize_t oom_adjust_write(struct file *file, const char *buf,
722 size_t count, loff_t *ppos)
724 struct task_struct *task = proc_task(file->f_dentry->d_inode);
725 char buffer[8], *end;
728 if (!capable(CAP_SYS_RESOURCE))
730 memset(buffer, 0, 8);
733 if (copy_from_user(buffer, buf, count))
735 oom_adjust = simple_strtol(buffer, &end, 0);
736 if (oom_adjust < -16 || oom_adjust > 15)
740 task->oomkilladj = oom_adjust;
741 if (end - buffer == 0)
746 static struct file_operations proc_oom_adjust_operations = {
747 read: oom_adjust_read,
748 write: oom_adjust_write,
751 static struct inode_operations proc_mem_inode_operations = {
752 .permission = proc_permission,
755 #ifdef CONFIG_AUDITSYSCALL
757 static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
758 size_t count, loff_t *ppos)
760 struct inode * inode = file->f_dentry->d_inode;
761 struct task_struct *task = proc_task(inode);
763 char tmpbuf[TMPBUFLEN];
765 length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
766 audit_get_loginuid(task->audit_context));
767 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
770 static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
771 size_t count, loff_t *ppos)
773 struct inode * inode = file->f_dentry->d_inode;
776 struct task_struct *task = proc_task(inode);
779 if (!capable(CAP_AUDIT_CONTROL))
785 if (count > PAGE_SIZE)
789 /* No partial writes. */
792 page = (char*)__get_free_page(GFP_USER);
796 if (copy_from_user(page, buf, count))
799 loginuid = simple_strtoul(page, &tmp, 10);
805 length = audit_set_loginuid(task->audit_context, loginuid);
806 if (likely(length == 0))
810 free_page((unsigned long) page);
814 static struct file_operations proc_loginuid_operations = {
815 .read = proc_loginuid_read,
816 .write = proc_loginuid_write,
820 static int proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
822 struct inode *inode = dentry->d_inode;
825 /* We don't need a base pointer in the /proc filesystem */
828 if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE))
830 error = proc_check_root(inode);
834 error = PROC_I(inode)->op.proc_get_link(inode, &nd->dentry, &nd->mnt);
835 nd->last_type = LAST_BIND;
840 static int do_proc_readlink(struct dentry *dentry, struct vfsmount *mnt,
841 char __user *buffer, int buflen)
843 struct inode * inode;
844 char *tmp = (char*)__get_free_page(GFP_KERNEL), *path;
850 inode = dentry->d_inode;
851 path = d_path(dentry, mnt, tmp, PAGE_SIZE);
855 len = tmp + PAGE_SIZE - 1 - path;
859 if (copy_to_user(buffer, path, len))
862 free_page((unsigned long)tmp);
866 static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen)
869 struct inode *inode = dentry->d_inode;
871 struct vfsmount *mnt = NULL;
875 if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE))
877 error = proc_check_root(inode);
881 error = PROC_I(inode)->op.proc_get_link(inode, &de, &mnt);
885 error = do_proc_readlink(de, mnt, buffer, buflen);
893 static struct inode_operations proc_pid_link_inode_operations = {
894 .readlink = proc_pid_readlink,
895 .follow_link = proc_pid_follow_link
900 static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
902 struct inode *inode = filp->f_dentry->d_inode;
903 struct task_struct *p = proc_task(inode);
904 unsigned int fd, tid, ino;
907 struct files_struct * files;
918 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0)
922 ino = fake_ino(tid, PROC_TID_INO);
923 if (filldir(dirent, "..", 2, 1, ino, DT_DIR) < 0)
927 files = get_files_struct(p);
930 spin_lock(&files->file_lock);
931 for (fd = filp->f_pos-2;
933 fd++, filp->f_pos++) {
936 if (!fcheck_files(files, fd))
938 spin_unlock(&files->file_lock);
944 buf[j] = '0' + (i % 10);
948 ino = fake_ino(tid, PROC_TID_FD_DIR + fd);
949 if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) {
950 spin_lock(&files->file_lock);
953 spin_lock(&files->file_lock);
955 spin_unlock(&files->file_lock);
956 put_files_struct(files);
962 static int proc_pident_readdir(struct file *filp,
963 void *dirent, filldir_t filldir,
964 struct pid_entry *ents, unsigned int nents)
968 struct dentry *dentry = filp->f_dentry;
969 struct inode *inode = dentry->d_inode;
975 if (!pid_alive(proc_task(inode)))
979 pid = proc_task(inode)->pid;
984 if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
990 ino = parent_ino(dentry);
991 if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
1003 hide = vx_flags(VXF_INFO_HIDE, 0);
1007 case PROC_TGID_VX_INFO:
1008 case PROC_TGID_IP_INFO:
1012 if (filldir(dirent, p->name, p->len, filp->f_pos,
1013 fake_ino(pid, p->type), p->mode >> 12) < 0)
1026 static int proc_tgid_base_readdir(struct file * filp,
1027 void * dirent, filldir_t filldir)
1029 return proc_pident_readdir(filp,dirent,filldir,
1030 tgid_base_stuff,ARRAY_SIZE(tgid_base_stuff));
1033 static int proc_tid_base_readdir(struct file * filp,
1034 void * dirent, filldir_t filldir)
1036 return proc_pident_readdir(filp,dirent,filldir,
1037 tid_base_stuff,ARRAY_SIZE(tid_base_stuff));
1040 /* building an inode */
1042 static int task_dumpable(struct task_struct *task)
1045 struct mm_struct *mm;
1050 dumpable = mm->dumpable;
1056 static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task, int ino)
1058 struct inode * inode;
1059 struct proc_inode *ei;
1061 /* We need a new inode */
1063 inode = new_inode(sb);
1070 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
1071 inode->i_ino = fake_ino(task->pid, ino);
1073 if (!pid_alive(task))
1077 * grab the reference to task.
1079 get_task_struct(task);
1084 if (ino == PROC_TGID_INO || ino == PROC_TID_INO || task_dumpable(task)) {
1085 inode->i_uid = task->euid;
1086 inode->i_gid = task->egid;
1088 inode->i_xid = vx_task_xid(task);
1089 security_task_to_inode(task, inode);
1103 * Exceptional case: normally we are not allowed to unhash a busy
1104 * directory. In this case, however, we can do it - no aliasing problems
1105 * due to the way we treat inodes.
1107 * Rewrite the inode's ownerships here because the owning task may have
1108 * performed a setuid(), etc.
1110 static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
1112 struct inode *inode = dentry->d_inode;
1113 struct task_struct *task = proc_task(inode);
1115 if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
1117 /* discard wrong fakeinit */
1119 if (pid_alive(task)) {
1120 if (proc_type(inode) == PROC_TGID_INO || proc_type(inode) == PROC_TID_INO || task_dumpable(task)) {
1121 inode->i_uid = task->euid;
1122 inode->i_gid = task->egid;
1127 security_task_to_inode(task, inode);
1135 static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
1137 struct inode *inode = dentry->d_inode;
1138 struct task_struct *task = proc_task(inode);
1139 int fd = proc_type(inode) - PROC_TID_FD_DIR;
1140 struct files_struct *files;
1142 files = get_files_struct(task);
1144 spin_lock(&files->file_lock);
1145 if (fcheck_files(files, fd)) {
1146 spin_unlock(&files->file_lock);
1147 put_files_struct(files);
1148 if (task_dumpable(task)) {
1149 inode->i_uid = task->euid;
1150 inode->i_gid = task->egid;
1155 security_task_to_inode(task, inode);
1158 spin_unlock(&files->file_lock);
1159 put_files_struct(files);
1165 static void pid_base_iput(struct dentry *dentry, struct inode *inode)
1167 struct task_struct *task = proc_task(inode);
1168 spin_lock(&task->proc_lock);
1169 if (task->proc_dentry == dentry)
1170 task->proc_dentry = NULL;
1171 spin_unlock(&task->proc_lock);
1175 static int pid_delete_dentry(struct dentry * dentry)
1177 /* Is the task we represent dead?
1178 * If so, then don't put the dentry on the lru list,
1179 * kill it immediately.
1181 return !pid_alive(proc_task(dentry->d_inode));
1184 static struct dentry_operations tid_fd_dentry_operations =
1186 .d_revalidate = tid_fd_revalidate,
1187 .d_delete = pid_delete_dentry,
1190 static struct dentry_operations pid_dentry_operations =
1192 .d_revalidate = pid_revalidate,
1193 .d_delete = pid_delete_dentry,
1196 static struct dentry_operations pid_base_dentry_operations =
1198 .d_revalidate = pid_revalidate,
1199 .d_iput = pid_base_iput,
1200 .d_delete = pid_delete_dentry,
1205 static unsigned name_to_int(struct dentry *dentry)
1207 const char *name = dentry->d_name.name;
1208 int len = dentry->d_name.len;
1211 if (len > 1 && *name == '0')
1214 unsigned c = *name++ - '0';
1217 if (n >= (~0U-9)/10)
1228 static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry, struct nameidata *nd)
1230 struct task_struct *task = proc_task(dir);
1231 unsigned fd = name_to_int(dentry);
1233 struct files_struct * files;
1234 struct inode *inode;
1235 struct proc_inode *ei;
1239 if (!pid_alive(task))
1242 inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_FD_DIR+fd);
1246 files = get_files_struct(task);
1249 inode->i_mode = S_IFLNK;
1250 spin_lock(&files->file_lock);
1251 file = fcheck_files(files, fd);
1254 if (file->f_mode & 1)
1255 inode->i_mode |= S_IRUSR | S_IXUSR;
1256 if (file->f_mode & 2)
1257 inode->i_mode |= S_IWUSR | S_IXUSR;
1258 spin_unlock(&files->file_lock);
1259 put_files_struct(files);
1260 inode->i_op = &proc_pid_link_inode_operations;
1262 ei->op.proc_get_link = proc_fd_link;
1263 dentry->d_op = &tid_fd_dentry_operations;
1264 d_add(dentry, inode);
1268 spin_unlock(&files->file_lock);
1269 put_files_struct(files);
1273 return ERR_PTR(-ENOENT);
1276 static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir);
1277 static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd);
1279 static struct file_operations proc_fd_operations = {
1280 .read = generic_read_dir,
1281 .readdir = proc_readfd,
1284 static struct file_operations proc_task_operations = {
1285 .read = generic_read_dir,
1286 .readdir = proc_task_readdir,
1290 * proc directories can do almost nothing..
1292 static struct inode_operations proc_fd_inode_operations = {
1293 .lookup = proc_lookupfd,
1294 .permission = proc_permission,
1297 static struct inode_operations proc_task_inode_operations = {
1298 .lookup = proc_task_lookup,
1299 .permission = proc_permission,
1302 #ifdef CONFIG_SECURITY
1303 static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
1304 size_t count, loff_t *ppos)
1306 struct inode * inode = file->f_dentry->d_inode;
1309 struct task_struct *task = proc_task(inode);
1311 if (count > PAGE_SIZE)
1313 if (!(page = __get_free_page(GFP_KERNEL)))
1316 length = security_getprocattr(task,
1317 (char*)file->f_dentry->d_name.name,
1318 (void*)page, count);
1320 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
1325 static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
1326 size_t count, loff_t *ppos)
1328 struct inode * inode = file->f_dentry->d_inode;
1331 struct task_struct *task = proc_task(inode);
1333 if (count > PAGE_SIZE)
1336 /* No partial writes. */
1339 page = (char*)__get_free_page(GFP_USER);
1343 if (copy_from_user(page, buf, count))
1346 length = security_setprocattr(task,
1347 (char*)file->f_dentry->d_name.name,
1348 (void*)page, count);
1350 free_page((unsigned long) page);
1354 static struct file_operations proc_pid_attr_operations = {
1355 .read = proc_pid_attr_read,
1356 .write = proc_pid_attr_write,
1359 static struct file_operations proc_tid_attr_operations;
1360 static struct inode_operations proc_tid_attr_inode_operations;
1361 static struct file_operations proc_tgid_attr_operations;
1362 static struct inode_operations proc_tgid_attr_inode_operations;
1365 extern int proc_pid_vx_info(struct task_struct *, char *);
1366 extern int proc_pid_nx_info(struct task_struct *, char *);
1369 static struct dentry *proc_pident_lookup(struct inode *dir,
1370 struct dentry *dentry,
1371 struct pid_entry *ents)
1373 struct inode *inode;
1375 struct task_struct *task = proc_task(dir);
1376 struct pid_entry *p;
1377 struct proc_inode *ei;
1382 if (!pid_alive(task))
1385 for (p = ents; p->name; p++) {
1386 if (p->len != dentry->d_name.len)
1388 if (!memcmp(dentry->d_name.name, p->name, p->len))
1395 inode = proc_pid_make_inode(dir->i_sb, task, p->type);
1400 inode->i_mode = p->mode;
1402 * Yes, it does not scale. And it should not. Don't add
1403 * new entries into /proc/<tgid>/ without very good reasons.
1406 case PROC_TGID_TASK:
1408 inode->i_op = &proc_task_inode_operations;
1409 inode->i_fop = &proc_task_operations;
1414 inode->i_op = &proc_fd_inode_operations;
1415 inode->i_fop = &proc_fd_operations;
1419 inode->i_op = &proc_pid_link_inode_operations;
1420 ei->op.proc_get_link = proc_exe_link;
1424 inode->i_op = &proc_pid_link_inode_operations;
1425 ei->op.proc_get_link = proc_cwd_link;
1428 case PROC_TGID_ROOT:
1429 inode->i_op = &proc_pid_link_inode_operations;
1430 ei->op.proc_get_link = proc_root_link;
1432 case PROC_TID_ENVIRON:
1433 case PROC_TGID_ENVIRON:
1434 inode->i_fop = &proc_info_file_operations;
1435 ei->op.proc_read = proc_pid_environ;
1438 case PROC_TGID_AUXV:
1439 inode->i_fop = &proc_info_file_operations;
1440 ei->op.proc_read = proc_pid_auxv;
1442 case PROC_TID_STATUS:
1443 case PROC_TGID_STATUS:
1444 inode->i_fop = &proc_info_file_operations;
1445 ei->op.proc_read = proc_pid_status;
1448 inode->i_fop = &proc_info_file_operations;
1449 ei->op.proc_read = proc_tid_stat;
1451 case PROC_TGID_STAT:
1452 inode->i_fop = &proc_info_file_operations;
1453 ei->op.proc_read = proc_tgid_stat;
1455 case PROC_TID_CMDLINE:
1456 case PROC_TGID_CMDLINE:
1457 inode->i_fop = &proc_info_file_operations;
1458 ei->op.proc_read = proc_pid_cmdline;
1460 case PROC_TID_STATM:
1461 case PROC_TGID_STATM:
1462 inode->i_fop = &proc_info_file_operations;
1463 ei->op.proc_read = proc_pid_statm;
1466 case PROC_TGID_MAPS:
1467 inode->i_fop = &proc_maps_operations;
1471 inode->i_op = &proc_mem_inode_operations;
1472 inode->i_fop = &proc_mem_operations;
1474 case PROC_TID_MOUNTS:
1475 case PROC_TGID_MOUNTS:
1476 inode->i_fop = &proc_mounts_operations;
1478 #ifdef CONFIG_SECURITY
1481 inode->i_op = &proc_tid_attr_inode_operations;
1482 inode->i_fop = &proc_tid_attr_operations;
1484 case PROC_TGID_ATTR:
1486 inode->i_op = &proc_tgid_attr_inode_operations;
1487 inode->i_fop = &proc_tgid_attr_operations;
1489 case PROC_TID_ATTR_CURRENT:
1490 case PROC_TGID_ATTR_CURRENT:
1491 case PROC_TID_ATTR_PREV:
1492 case PROC_TGID_ATTR_PREV:
1493 case PROC_TID_ATTR_EXEC:
1494 case PROC_TGID_ATTR_EXEC:
1495 case PROC_TID_ATTR_FSCREATE:
1496 case PROC_TGID_ATTR_FSCREATE:
1497 inode->i_fop = &proc_pid_attr_operations;
1500 #ifdef CONFIG_KALLSYMS
1501 case PROC_TID_WCHAN:
1502 case PROC_TGID_WCHAN:
1503 inode->i_fop = &proc_info_file_operations;
1504 ei->op.proc_read = proc_pid_wchan;
1507 #ifdef CONFIG_SCHEDSTATS
1508 case PROC_TID_SCHEDSTAT:
1509 case PROC_TGID_SCHEDSTAT:
1510 inode->i_fop = &proc_info_file_operations;
1511 ei->op.proc_read = proc_pid_schedstat;
1514 case PROC_TID_OOM_SCORE:
1515 case PROC_TGID_OOM_SCORE:
1516 inode->i_fop = &proc_info_file_operations;
1517 ei->op.proc_read = proc_oom_score;
1519 case PROC_TID_OOM_ADJUST:
1520 case PROC_TGID_OOM_ADJUST:
1521 inode->i_fop = &proc_oom_adjust_operations;
1523 #ifdef CONFIG_AUDITSYSCALL
1524 case PROC_TID_LOGINUID:
1525 case PROC_TGID_LOGINUID:
1526 inode->i_fop = &proc_loginuid_operations;
1529 case PROC_TID_VX_INFO:
1530 case PROC_TGID_VX_INFO:
1531 if (task_vx_flags(task, VXF_INFO_HIDE, 0))
1533 inode->i_fop = &proc_info_file_operations;
1534 ei->op.proc_read = proc_pid_vx_info;
1536 case PROC_TID_IP_INFO:
1537 case PROC_TGID_IP_INFO:
1538 if (task_vx_flags(task, VXF_INFO_HIDE, 0))
1540 inode->i_fop = &proc_info_file_operations;
1541 ei->op.proc_read = proc_pid_nx_info;
1544 printk("procfs: impossible type (%d)",p->type);
1548 dentry->d_op = &pid_dentry_operations;
1549 d_add(dentry, inode);
1557 return ERR_PTR(error);
1560 static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){
1561 return proc_pident_lookup(dir, dentry, tgid_base_stuff);
1564 static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){
1565 return proc_pident_lookup(dir, dentry, tid_base_stuff);
1568 static struct file_operations proc_tgid_base_operations = {
1569 .read = generic_read_dir,
1570 .readdir = proc_tgid_base_readdir,
1573 static struct file_operations proc_tid_base_operations = {
1574 .read = generic_read_dir,
1575 .readdir = proc_tid_base_readdir,
1578 static struct inode_operations proc_tgid_base_inode_operations = {
1579 .lookup = proc_tgid_base_lookup,
1582 static struct inode_operations proc_tid_base_inode_operations = {
1583 .lookup = proc_tid_base_lookup,
1586 #ifdef CONFIG_SECURITY
1587 static int proc_tgid_attr_readdir(struct file * filp,
1588 void * dirent, filldir_t filldir)
1590 return proc_pident_readdir(filp,dirent,filldir,
1591 tgid_attr_stuff,ARRAY_SIZE(tgid_attr_stuff));
1594 static int proc_tid_attr_readdir(struct file * filp,
1595 void * dirent, filldir_t filldir)
1597 return proc_pident_readdir(filp,dirent,filldir,
1598 tid_attr_stuff,ARRAY_SIZE(tid_attr_stuff));
1601 static struct file_operations proc_tgid_attr_operations = {
1602 .read = generic_read_dir,
1603 .readdir = proc_tgid_attr_readdir,
1606 static struct file_operations proc_tid_attr_operations = {
1607 .read = generic_read_dir,
1608 .readdir = proc_tid_attr_readdir,
1611 static struct dentry *proc_tgid_attr_lookup(struct inode *dir,
1612 struct dentry *dentry, struct nameidata *nd)
1614 return proc_pident_lookup(dir, dentry, tgid_attr_stuff);
1617 static struct dentry *proc_tid_attr_lookup(struct inode *dir,
1618 struct dentry *dentry, struct nameidata *nd)
1620 return proc_pident_lookup(dir, dentry, tid_attr_stuff);
1623 static struct inode_operations proc_tgid_attr_inode_operations = {
1624 .lookup = proc_tgid_attr_lookup,
1627 static struct inode_operations proc_tid_attr_inode_operations = {
1628 .lookup = proc_tid_attr_lookup,
1635 static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
1639 sprintf(tmp, "%d", vx_map_tgid(current->tgid));
1640 return vfs_readlink(dentry,buffer,buflen,tmp);
1643 static int proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
1646 sprintf(tmp, "%d", vx_map_tgid(current->tgid));
1647 return vfs_follow_link(nd,tmp);
1650 static struct inode_operations proc_self_inode_operations = {
1651 .readlink = proc_self_readlink,
1652 .follow_link = proc_self_follow_link,
1656 * proc_pid_unhash - Unhash /proc/<pid> entry from the dcache.
1657 * @p: task that should be flushed.
1659 * Drops the /proc/<pid> dcache entry from the hash chains.
1661 * Dropping /proc/<pid> entries and detach_pid must be synchroneous,
1662 * otherwise e.g. /proc/<pid>/exe might point to the wrong executable,
1663 * if the pid value is immediately reused. This is enforced by
1664 * - caller must acquire spin_lock(p->proc_lock)
1665 * - must be called before detach_pid()
1666 * - proc_pid_lookup acquires proc_lock, and checks that
1667 * the target is not dead by looking at the attach count
1671 struct dentry *proc_pid_unhash(struct task_struct *p)
1673 struct dentry *proc_dentry;
1675 proc_dentry = p->proc_dentry;
1676 if (proc_dentry != NULL) {
1678 spin_lock(&dcache_lock);
1679 if (!d_unhashed(proc_dentry)) {
1680 dget_locked(proc_dentry);
1681 __d_drop(proc_dentry);
1684 spin_unlock(&dcache_lock);
1690 * proc_pid_flush - recover memory used by stale /proc/<pid>/x entries
1691 * @proc_entry: directoy to prune.
1693 * Shrink the /proc directory that was used by the just killed thread.
1696 void proc_pid_flush(struct dentry *proc_dentry)
1699 if(proc_dentry != NULL) {
1700 shrink_dcache_parent(proc_dentry);
1705 #define VXF_FAKE_INIT (VXF_INFO_INIT|VXF_STATE_INIT)
1707 static inline int proc_pid_visible(struct task_struct *task, int pid)
1710 !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
1712 if (vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
1720 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
1722 struct task_struct *task;
1723 struct inode *inode;
1724 struct proc_inode *ei;
1728 if (dentry->d_name.len == 4 && !memcmp(dentry->d_name.name,"self",4)) {
1729 inode = new_inode(dir->i_sb);
1731 return ERR_PTR(-ENOMEM);
1733 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
1734 inode->i_ino = fake_ino(0, PROC_TGID_INO);
1736 inode->i_mode = S_IFLNK|S_IRWXUGO;
1737 inode->i_uid = inode->i_gid = 0;
1739 inode->i_op = &proc_self_inode_operations;
1740 d_add(dentry, inode);
1743 tgid = name_to_int(dentry);
1747 read_lock(&tasklist_lock);
1748 task = find_task_by_pid(tgid);
1750 get_task_struct(task);
1751 read_unlock(&tasklist_lock);
1755 /* check for context visibility */
1756 if (!proc_pid_visible(task, tgid))
1759 inode = proc_pid_make_inode(dir->i_sb, task, PROC_TGID_INO);
1763 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
1764 inode->i_op = &proc_tgid_base_inode_operations;
1765 inode->i_fop = &proc_tgid_base_operations;
1767 inode->i_flags|=S_IMMUTABLE;
1769 dentry->d_op = &pid_base_dentry_operations;
1772 d_add(dentry, inode);
1773 spin_lock(&task->proc_lock);
1774 task->proc_dentry = dentry;
1775 if (!pid_alive(task)) {
1776 dentry = proc_pid_unhash(task);
1779 spin_unlock(&task->proc_lock);
1781 put_task_struct(task);
1783 proc_pid_flush(dentry);
1788 put_task_struct(task);
1790 return ERR_PTR(-ENOENT);
1794 static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
1796 struct task_struct *task;
1797 struct task_struct *leader = proc_task(dir);
1798 struct inode *inode;
1801 tid = name_to_int(dentry);
1804 if (vx_current_initpid(tid))
1807 read_lock(&tasklist_lock);
1808 task = find_task_by_pid(tid);
1810 get_task_struct(task);
1811 read_unlock(&tasklist_lock);
1814 if (leader->tgid != task->tgid)
1817 /* check for context visibility */
1818 if (!proc_pid_visible(task, tid))
1821 inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_INO);
1825 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
1826 inode->i_op = &proc_tid_base_inode_operations;
1827 inode->i_fop = &proc_tid_base_operations;
1829 inode->i_flags|=S_IMMUTABLE;
1831 dentry->d_op = &pid_base_dentry_operations;
1833 d_add(dentry, inode);
1835 put_task_struct(task);
1838 put_task_struct(task);
1840 return ERR_PTR(-ENOENT);
1843 #define PROC_NUMBUF 10
1844 #define PROC_MAXPIDS 20
1847 * Get a few tgid's to return for filldir - we need to hold the
1848 * tasklist lock while doing this, and we must release it before
1849 * we actually do the filldir itself, so we use a temp buffer..
1851 static int get_tgid_list(int index, unsigned long version, unsigned int *tgids)
1853 struct task_struct *p;
1857 read_lock(&tasklist_lock);
1860 p = find_task_by_real_pid(version);
1861 if (p && !thread_group_leader(p))
1868 p = next_task(&init_task);
1870 for ( ; p != &init_task; p = next_task(p)) {
1875 /* check for context visibility */
1876 if (!proc_pid_visible(p, tgid))
1880 tgids[nr_tgids] = vx_map_tgid(tgid);
1882 if (nr_tgids >= PROC_MAXPIDS)
1885 read_unlock(&tasklist_lock);
1890 * Get a few tid's to return for filldir - we need to hold the
1891 * tasklist lock while doing this, and we must release it before
1892 * we actually do the filldir itself, so we use a temp buffer..
1894 static int get_tid_list(int index, unsigned int *tids, struct inode *dir)
1896 struct task_struct *leader_task = proc_task(dir);
1897 struct task_struct *task = leader_task;
1901 read_lock(&tasklist_lock);
1903 * The starting point task (leader_task) might be an already
1904 * unlinked task, which cannot be used to access the task-list
1905 * via next_thread().
1907 if (pid_alive(task)) do {
1908 int tid = task->pid;
1910 /* check for context visibility */
1911 if (!proc_pid_visible(task, tid))
1915 tids[nr_tids] = vx_map_pid(tid);
1917 if (nr_tids >= PROC_MAXPIDS)
1919 } while ((task = next_thread(task)) != leader_task);
1920 read_unlock(&tasklist_lock);
1924 /* for the /proc/ directory itself, after non-process stuff has been done */
1925 int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
1927 unsigned int tgid_array[PROC_MAXPIDS];
1928 char buf[PROC_NUMBUF];
1929 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
1930 unsigned int nr_tgids, i;
1934 ino_t ino = fake_ino(0,PROC_TGID_INO);
1935 if (filldir(dirent, "self", 4, filp->f_pos, ino, DT_LNK) < 0)
1941 /* f_version caches the tgid value that the last readdir call couldn't
1942 * return. lseek aka telldir automagically resets f_version to 0.
1944 next_tgid = filp->f_version;
1945 filp->f_version = 0;
1947 nr_tgids = get_tgid_list(nr, next_tgid, tgid_array);
1949 /* no more entries ! */
1954 /* do not use the last found pid, reserve it for next_tgid */
1955 if (nr_tgids == PROC_MAXPIDS) {
1957 next_tgid = tgid_array[nr_tgids];
1960 for (i=0;i<nr_tgids;i++) {
1961 int tgid = tgid_array[i];
1962 ino_t ino = fake_ino(tgid,PROC_TGID_INO);
1963 unsigned long j = PROC_NUMBUF;
1966 buf[--j] = '0' + (tgid % 10);
1967 while ((tgid /= 10) != 0);
1969 if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino, DT_DIR) < 0) {
1970 /* returning this tgid failed, save it as the first
1971 * pid for the next readir call */
1972 filp->f_version = tgid_array[i];
1983 /* for the /proc/TGID/task/ directories */
1984 static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir)
1986 unsigned int tid_array[PROC_MAXPIDS];
1987 char buf[PROC_NUMBUF];
1988 unsigned int nr_tids, i;
1989 struct dentry *dentry = filp->f_dentry;
1990 struct inode *inode = dentry->d_inode;
1991 struct task_struct *task = proc_task(inode);
1992 int retval = -ENOENT;
1994 unsigned long pos = filp->f_pos; /* avoiding "long long" filp->f_pos */
1996 if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
1998 if (!pid_alive(task))
2005 if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
2010 ino = parent_ino(dentry);
2011 if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
2017 nr_tids = get_tid_list(pos, tid_array, inode);
2019 for (i = 0; i < nr_tids; i++) {
2020 unsigned long j = PROC_NUMBUF;
2021 int tid = tid_array[i];
2023 ino = fake_ino(tid,PROC_TID_INO);
2026 buf[--j] = '0' + (tid % 10);
2027 while ((tid /= 10) != 0);
2029 if (filldir(dirent, buf+j, PROC_NUMBUF-j, pos, ino, DT_DIR) < 0)