Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/proc/array.c
0004  *
0005  *  Copyright (C) 1992  by Linus Torvalds
0006  *  based on ideas by Darren Senn
0007  *
0008  * Fixes:
0009  * Michael. K. Johnson: stat,statm extensions.
0010  *                      <johnsonm@stolaf.edu>
0011  *
0012  * Pauline Middelink :  Made cmdline,envline only break at '\0's, to
0013  *                      make sure SET_PROCTITLE works. Also removed
0014  *                      bad '!' which forced address recalculation for
0015  *                      EVERY character on the current page.
0016  *                      <middelin@polyware.iaf.nl>
0017  *
0018  * Danny ter Haar    :  added cpuinfo
0019  *          <dth@cistron.nl>
0020  *
0021  * Alessandro Rubini :  profile extension.
0022  *                      <rubini@ipvvis.unipv.it>
0023  *
0024  * Jeff Tranter      :  added BogoMips field to cpuinfo
0025  *                      <Jeff_Tranter@Mitel.COM>
0026  *
0027  * Bruno Haible      :  remove 4K limit for the maps file
0028  *          <haible@ma2s2.mathematik.uni-karlsruhe.de>
0029  *
0030  * Yves Arrouye      :  remove removal of trailing spaces in get_array.
0031  *          <Yves.Arrouye@marin.fdn.fr>
0032  *
0033  * Jerome Forissier  :  added per-CPU time information to /proc/stat
0034  *                      and /proc/<pid>/cpu extension
0035  *                      <forissier@isia.cma.fr>
0036  *          - Incorporation and non-SMP safe operation
0037  *          of forissier patch in 2.1.78 by
0038  *          Hans Marcus <crowbar@concepts.nl>
0039  *
0040  * aeb@cwi.nl        :  /proc/partitions
0041  *
0042  *
0043  * Alan Cox      :  security fixes.
0044  *          <alan@lxorguk.ukuu.org.uk>
0045  *
0046  * Al Viro           :  safe handling of mm_struct
0047  *
0048  * Gerhard Wichert   :  added BIGMEM support
0049  * Siemens AG           <Gerhard.Wichert@pdb.siemens.de>
0050  *
0051  * Al Viro & Jeff Garzik :  moved most of the thing into base.c and
0052  *           :  proc_misc.c. The rest may eventually go into
0053  *           :  base.c too.
0054  */
0055 
0056 #include <linux/types.h>
0057 #include <linux/errno.h>
0058 #include <linux/time.h>
0059 #include <linux/time_namespace.h>
0060 #include <linux/kernel.h>
0061 #include <linux/kernel_stat.h>
0062 #include <linux/tty.h>
0063 #include <linux/string.h>
0064 #include <linux/mman.h>
0065 #include <linux/sched/mm.h>
0066 #include <linux/sched/numa_balancing.h>
0067 #include <linux/sched/task_stack.h>
0068 #include <linux/sched/task.h>
0069 #include <linux/sched/cputime.h>
0070 #include <linux/proc_fs.h>
0071 #include <linux/ioport.h>
0072 #include <linux/io.h>
0073 #include <linux/mm.h>
0074 #include <linux/hugetlb.h>
0075 #include <linux/pagemap.h>
0076 #include <linux/swap.h>
0077 #include <linux/smp.h>
0078 #include <linux/signal.h>
0079 #include <linux/highmem.h>
0080 #include <linux/file.h>
0081 #include <linux/fdtable.h>
0082 #include <linux/times.h>
0083 #include <linux/cpuset.h>
0084 #include <linux/rcupdate.h>
0085 #include <linux/delayacct.h>
0086 #include <linux/seq_file.h>
0087 #include <linux/pid_namespace.h>
0088 #include <linux/prctl.h>
0089 #include <linux/ptrace.h>
0090 #include <linux/string_helpers.h>
0091 #include <linux/user_namespace.h>
0092 #include <linux/fs_struct.h>
0093 #include <linux/kthread.h>
0094 
0095 #include <asm/processor.h>
0096 #include "internal.h"
0097 
0098 void proc_task_name(struct seq_file *m, struct task_struct *p, bool escape)
0099 {
0100     char tcomm[64];
0101 
0102     /*
0103      * Test before PF_KTHREAD because all workqueue worker threads are
0104      * kernel threads.
0105      */
0106     if (p->flags & PF_WQ_WORKER)
0107         wq_worker_comm(tcomm, sizeof(tcomm), p);
0108     else if (p->flags & PF_KTHREAD)
0109         get_kthread_comm(tcomm, sizeof(tcomm), p);
0110     else
0111         __get_task_comm(tcomm, sizeof(tcomm), p);
0112 
0113     if (escape)
0114         seq_escape_str(m, tcomm, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
0115     else
0116         seq_printf(m, "%.64s", tcomm);
0117 }
0118 
0119 /*
0120  * The task state array is a strange "bitmap" of
0121  * reasons to sleep. Thus "running" is zero, and
0122  * you can test for combinations of others with
0123  * simple bit tests.
0124  */
0125 static const char * const task_state_array[] = {
0126 
0127     /* states in TASK_REPORT: */
0128     "R (running)",      /* 0x00 */
0129     "S (sleeping)",     /* 0x01 */
0130     "D (disk sleep)",   /* 0x02 */
0131     "T (stopped)",      /* 0x04 */
0132     "t (tracing stop)", /* 0x08 */
0133     "X (dead)",     /* 0x10 */
0134     "Z (zombie)",       /* 0x20 */
0135     "P (parked)",       /* 0x40 */
0136 
0137     /* states beyond TASK_REPORT: */
0138     "I (idle)",     /* 0x80 */
0139 };
0140 
0141 static inline const char *get_task_state(struct task_struct *tsk)
0142 {
0143     BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != ARRAY_SIZE(task_state_array));
0144     return task_state_array[task_state_index(tsk)];
0145 }
0146 
0147 static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
0148                 struct pid *pid, struct task_struct *p)
0149 {
0150     struct user_namespace *user_ns = seq_user_ns(m);
0151     struct group_info *group_info;
0152     int g, umask = -1;
0153     struct task_struct *tracer;
0154     const struct cred *cred;
0155     pid_t ppid, tpid = 0, tgid, ngid;
0156     unsigned int max_fds = 0;
0157 
0158     rcu_read_lock();
0159     ppid = pid_alive(p) ?
0160         task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
0161 
0162     tracer = ptrace_parent(p);
0163     if (tracer)
0164         tpid = task_pid_nr_ns(tracer, ns);
0165 
0166     tgid = task_tgid_nr_ns(p, ns);
0167     ngid = task_numa_group_id(p);
0168     cred = get_task_cred(p);
0169 
0170     task_lock(p);
0171     if (p->fs)
0172         umask = p->fs->umask;
0173     if (p->files)
0174         max_fds = files_fdtable(p->files)->max_fds;
0175     task_unlock(p);
0176     rcu_read_unlock();
0177 
0178     if (umask >= 0)
0179         seq_printf(m, "Umask:\t%#04o\n", umask);
0180     seq_puts(m, "State:\t");
0181     seq_puts(m, get_task_state(p));
0182 
0183     seq_put_decimal_ull(m, "\nTgid:\t", tgid);
0184     seq_put_decimal_ull(m, "\nNgid:\t", ngid);
0185     seq_put_decimal_ull(m, "\nPid:\t", pid_nr_ns(pid, ns));
0186     seq_put_decimal_ull(m, "\nPPid:\t", ppid);
0187     seq_put_decimal_ull(m, "\nTracerPid:\t", tpid);
0188     seq_put_decimal_ull(m, "\nUid:\t", from_kuid_munged(user_ns, cred->uid));
0189     seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->euid));
0190     seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->suid));
0191     seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->fsuid));
0192     seq_put_decimal_ull(m, "\nGid:\t", from_kgid_munged(user_ns, cred->gid));
0193     seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->egid));
0194     seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->sgid));
0195     seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->fsgid));
0196     seq_put_decimal_ull(m, "\nFDSize:\t", max_fds);
0197 
0198     seq_puts(m, "\nGroups:\t");
0199     group_info = cred->group_info;
0200     for (g = 0; g < group_info->ngroups; g++)
0201         seq_put_decimal_ull(m, g ? " " : "",
0202                 from_kgid_munged(user_ns, group_info->gid[g]));
0203     put_cred(cred);
0204     /* Trailing space shouldn't have been added in the first place. */
0205     seq_putc(m, ' ');
0206 
0207 #ifdef CONFIG_PID_NS
0208     seq_puts(m, "\nNStgid:");
0209     for (g = ns->level; g <= pid->level; g++)
0210         seq_put_decimal_ull(m, "\t", task_tgid_nr_ns(p, pid->numbers[g].ns));
0211     seq_puts(m, "\nNSpid:");
0212     for (g = ns->level; g <= pid->level; g++)
0213         seq_put_decimal_ull(m, "\t", task_pid_nr_ns(p, pid->numbers[g].ns));
0214     seq_puts(m, "\nNSpgid:");
0215     for (g = ns->level; g <= pid->level; g++)
0216         seq_put_decimal_ull(m, "\t", task_pgrp_nr_ns(p, pid->numbers[g].ns));
0217     seq_puts(m, "\nNSsid:");
0218     for (g = ns->level; g <= pid->level; g++)
0219         seq_put_decimal_ull(m, "\t", task_session_nr_ns(p, pid->numbers[g].ns));
0220 #endif
0221     seq_putc(m, '\n');
0222 }
0223 
0224 void render_sigset_t(struct seq_file *m, const char *header,
0225                 sigset_t *set)
0226 {
0227     int i;
0228 
0229     seq_puts(m, header);
0230 
0231     i = _NSIG;
0232     do {
0233         int x = 0;
0234 
0235         i -= 4;
0236         if (sigismember(set, i+1)) x |= 1;
0237         if (sigismember(set, i+2)) x |= 2;
0238         if (sigismember(set, i+3)) x |= 4;
0239         if (sigismember(set, i+4)) x |= 8;
0240         seq_putc(m, hex_asc[x]);
0241     } while (i >= 4);
0242 
0243     seq_putc(m, '\n');
0244 }
0245 
0246 static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *sigign,
0247                     sigset_t *sigcatch)
0248 {
0249     struct k_sigaction *k;
0250     int i;
0251 
0252     k = p->sighand->action;
0253     for (i = 1; i <= _NSIG; ++i, ++k) {
0254         if (k->sa.sa_handler == SIG_IGN)
0255             sigaddset(sigign, i);
0256         else if (k->sa.sa_handler != SIG_DFL)
0257             sigaddset(sigcatch, i);
0258     }
0259 }
0260 
0261 static inline void task_sig(struct seq_file *m, struct task_struct *p)
0262 {
0263     unsigned long flags;
0264     sigset_t pending, shpending, blocked, ignored, caught;
0265     int num_threads = 0;
0266     unsigned int qsize = 0;
0267     unsigned long qlim = 0;
0268 
0269     sigemptyset(&pending);
0270     sigemptyset(&shpending);
0271     sigemptyset(&blocked);
0272     sigemptyset(&ignored);
0273     sigemptyset(&caught);
0274 
0275     if (lock_task_sighand(p, &flags)) {
0276         pending = p->pending.signal;
0277         shpending = p->signal->shared_pending.signal;
0278         blocked = p->blocked;
0279         collect_sigign_sigcatch(p, &ignored, &caught);
0280         num_threads = get_nr_threads(p);
0281         rcu_read_lock();  /* FIXME: is this correct? */
0282         qsize = get_ucounts_value(task_ucounts(p), UCOUNT_RLIMIT_SIGPENDING);
0283         rcu_read_unlock();
0284         qlim = task_rlimit(p, RLIMIT_SIGPENDING);
0285         unlock_task_sighand(p, &flags);
0286     }
0287 
0288     seq_put_decimal_ull(m, "Threads:\t", num_threads);
0289     seq_put_decimal_ull(m, "\nSigQ:\t", qsize);
0290     seq_put_decimal_ull(m, "/", qlim);
0291 
0292     /* render them all */
0293     render_sigset_t(m, "\nSigPnd:\t", &pending);
0294     render_sigset_t(m, "ShdPnd:\t", &shpending);
0295     render_sigset_t(m, "SigBlk:\t", &blocked);
0296     render_sigset_t(m, "SigIgn:\t", &ignored);
0297     render_sigset_t(m, "SigCgt:\t", &caught);
0298 }
0299 
0300 static void render_cap_t(struct seq_file *m, const char *header,
0301             kernel_cap_t *a)
0302 {
0303     unsigned __capi;
0304 
0305     seq_puts(m, header);
0306     CAP_FOR_EACH_U32(__capi) {
0307         seq_put_hex_ll(m, NULL,
0308                a->cap[CAP_LAST_U32 - __capi], 8);
0309     }
0310     seq_putc(m, '\n');
0311 }
0312 
0313 static inline void task_cap(struct seq_file *m, struct task_struct *p)
0314 {
0315     const struct cred *cred;
0316     kernel_cap_t cap_inheritable, cap_permitted, cap_effective,
0317             cap_bset, cap_ambient;
0318 
0319     rcu_read_lock();
0320     cred = __task_cred(p);
0321     cap_inheritable = cred->cap_inheritable;
0322     cap_permitted   = cred->cap_permitted;
0323     cap_effective   = cred->cap_effective;
0324     cap_bset    = cred->cap_bset;
0325     cap_ambient = cred->cap_ambient;
0326     rcu_read_unlock();
0327 
0328     render_cap_t(m, "CapInh:\t", &cap_inheritable);
0329     render_cap_t(m, "CapPrm:\t", &cap_permitted);
0330     render_cap_t(m, "CapEff:\t", &cap_effective);
0331     render_cap_t(m, "CapBnd:\t", &cap_bset);
0332     render_cap_t(m, "CapAmb:\t", &cap_ambient);
0333 }
0334 
0335 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
0336 {
0337     seq_put_decimal_ull(m, "NoNewPrivs:\t", task_no_new_privs(p));
0338 #ifdef CONFIG_SECCOMP
0339     seq_put_decimal_ull(m, "\nSeccomp:\t", p->seccomp.mode);
0340 #ifdef CONFIG_SECCOMP_FILTER
0341     seq_put_decimal_ull(m, "\nSeccomp_filters:\t",
0342                 atomic_read(&p->seccomp.filter_count));
0343 #endif
0344 #endif
0345     seq_puts(m, "\nSpeculation_Store_Bypass:\t");
0346     switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_STORE_BYPASS)) {
0347     case -EINVAL:
0348         seq_puts(m, "unknown");
0349         break;
0350     case PR_SPEC_NOT_AFFECTED:
0351         seq_puts(m, "not vulnerable");
0352         break;
0353     case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE:
0354         seq_puts(m, "thread force mitigated");
0355         break;
0356     case PR_SPEC_PRCTL | PR_SPEC_DISABLE:
0357         seq_puts(m, "thread mitigated");
0358         break;
0359     case PR_SPEC_PRCTL | PR_SPEC_ENABLE:
0360         seq_puts(m, "thread vulnerable");
0361         break;
0362     case PR_SPEC_DISABLE:
0363         seq_puts(m, "globally mitigated");
0364         break;
0365     default:
0366         seq_puts(m, "vulnerable");
0367         break;
0368     }
0369 
0370     seq_puts(m, "\nSpeculationIndirectBranch:\t");
0371     switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_INDIRECT_BRANCH)) {
0372     case -EINVAL:
0373         seq_puts(m, "unsupported");
0374         break;
0375     case PR_SPEC_NOT_AFFECTED:
0376         seq_puts(m, "not affected");
0377         break;
0378     case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE:
0379         seq_puts(m, "conditional force disabled");
0380         break;
0381     case PR_SPEC_PRCTL | PR_SPEC_DISABLE:
0382         seq_puts(m, "conditional disabled");
0383         break;
0384     case PR_SPEC_PRCTL | PR_SPEC_ENABLE:
0385         seq_puts(m, "conditional enabled");
0386         break;
0387     case PR_SPEC_ENABLE:
0388         seq_puts(m, "always enabled");
0389         break;
0390     case PR_SPEC_DISABLE:
0391         seq_puts(m, "always disabled");
0392         break;
0393     default:
0394         seq_puts(m, "unknown");
0395         break;
0396     }
0397     seq_putc(m, '\n');
0398 }
0399 
0400 static inline void task_context_switch_counts(struct seq_file *m,
0401                         struct task_struct *p)
0402 {
0403     seq_put_decimal_ull(m, "voluntary_ctxt_switches:\t", p->nvcsw);
0404     seq_put_decimal_ull(m, "\nnonvoluntary_ctxt_switches:\t", p->nivcsw);
0405     seq_putc(m, '\n');
0406 }
0407 
0408 static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
0409 {
0410     seq_printf(m, "Cpus_allowed:\t%*pb\n",
0411            cpumask_pr_args(&task->cpus_mask));
0412     seq_printf(m, "Cpus_allowed_list:\t%*pbl\n",
0413            cpumask_pr_args(&task->cpus_mask));
0414 }
0415 
0416 static inline void task_core_dumping(struct seq_file *m, struct task_struct *task)
0417 {
0418     seq_put_decimal_ull(m, "CoreDumping:\t", !!task->signal->core_state);
0419     seq_putc(m, '\n');
0420 }
0421 
0422 static inline void task_thp_status(struct seq_file *m, struct mm_struct *mm)
0423 {
0424     bool thp_enabled = IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE);
0425 
0426     if (thp_enabled)
0427         thp_enabled = !test_bit(MMF_DISABLE_THP, &mm->flags);
0428     seq_printf(m, "THP_enabled:\t%d\n", thp_enabled);
0429 }
0430 
0431 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
0432             struct pid *pid, struct task_struct *task)
0433 {
0434     struct mm_struct *mm = get_task_mm(task);
0435 
0436     seq_puts(m, "Name:\t");
0437     proc_task_name(m, task, true);
0438     seq_putc(m, '\n');
0439 
0440     task_state(m, ns, pid, task);
0441 
0442     if (mm) {
0443         task_mem(m, mm);
0444         task_core_dumping(m, task);
0445         task_thp_status(m, mm);
0446         mmput(mm);
0447     }
0448     task_sig(m, task);
0449     task_cap(m, task);
0450     task_seccomp(m, task);
0451     task_cpus_allowed(m, task);
0452     cpuset_task_status_allowed(m, task);
0453     task_context_switch_counts(m, task);
0454     return 0;
0455 }
0456 
0457 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
0458             struct pid *pid, struct task_struct *task, int whole)
0459 {
0460     unsigned long vsize, eip, esp, wchan = 0;
0461     int priority, nice;
0462     int tty_pgrp = -1, tty_nr = 0;
0463     sigset_t sigign, sigcatch;
0464     char state;
0465     pid_t ppid = 0, pgid = -1, sid = -1;
0466     int num_threads = 0;
0467     int permitted;
0468     struct mm_struct *mm;
0469     unsigned long long start_time;
0470     unsigned long cmin_flt = 0, cmaj_flt = 0;
0471     unsigned long  min_flt = 0,  maj_flt = 0;
0472     u64 cutime, cstime, utime, stime;
0473     u64 cgtime, gtime;
0474     unsigned long rsslim = 0;
0475     unsigned long flags;
0476     int exit_code = task->exit_code;
0477 
0478     state = *get_task_state(task);
0479     vsize = eip = esp = 0;
0480     permitted = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT);
0481     mm = get_task_mm(task);
0482     if (mm) {
0483         vsize = task_vsize(mm);
0484         /*
0485          * esp and eip are intentionally zeroed out.  There is no
0486          * non-racy way to read them without freezing the task.
0487          * Programs that need reliable values can use ptrace(2).
0488          *
0489          * The only exception is if the task is core dumping because
0490          * a program is not able to use ptrace(2) in that case. It is
0491          * safe because the task has stopped executing permanently.
0492          */
0493         if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
0494             if (try_get_task_stack(task)) {
0495                 eip = KSTK_EIP(task);
0496                 esp = KSTK_ESP(task);
0497                 put_task_stack(task);
0498             }
0499         }
0500     }
0501 
0502     sigemptyset(&sigign);
0503     sigemptyset(&sigcatch);
0504     cutime = cstime = utime = stime = 0;
0505     cgtime = gtime = 0;
0506 
0507     if (lock_task_sighand(task, &flags)) {
0508         struct signal_struct *sig = task->signal;
0509 
0510         if (sig->tty) {
0511             struct pid *pgrp = tty_get_pgrp(sig->tty);
0512             tty_pgrp = pid_nr_ns(pgrp, ns);
0513             put_pid(pgrp);
0514             tty_nr = new_encode_dev(tty_devnum(sig->tty));
0515         }
0516 
0517         num_threads = get_nr_threads(task);
0518         collect_sigign_sigcatch(task, &sigign, &sigcatch);
0519 
0520         cmin_flt = sig->cmin_flt;
0521         cmaj_flt = sig->cmaj_flt;
0522         cutime = sig->cutime;
0523         cstime = sig->cstime;
0524         cgtime = sig->cgtime;
0525         rsslim = READ_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur);
0526 
0527         /* add up live thread stats at the group level */
0528         if (whole) {
0529             struct task_struct *t = task;
0530             do {
0531                 min_flt += t->min_flt;
0532                 maj_flt += t->maj_flt;
0533                 gtime += task_gtime(t);
0534             } while_each_thread(task, t);
0535 
0536             min_flt += sig->min_flt;
0537             maj_flt += sig->maj_flt;
0538             thread_group_cputime_adjusted(task, &utime, &stime);
0539             gtime += sig->gtime;
0540 
0541             if (sig->flags & (SIGNAL_GROUP_EXIT | SIGNAL_STOP_STOPPED))
0542                 exit_code = sig->group_exit_code;
0543         }
0544 
0545         sid = task_session_nr_ns(task, ns);
0546         ppid = task_tgid_nr_ns(task->real_parent, ns);
0547         pgid = task_pgrp_nr_ns(task, ns);
0548 
0549         unlock_task_sighand(task, &flags);
0550     }
0551 
0552     if (permitted && (!whole || num_threads < 2))
0553         wchan = !task_is_running(task);
0554     if (!whole) {
0555         min_flt = task->min_flt;
0556         maj_flt = task->maj_flt;
0557         task_cputime_adjusted(task, &utime, &stime);
0558         gtime = task_gtime(task);
0559     }
0560 
0561     /* scale priority and nice values from timeslices to -20..20 */
0562     /* to make it look like a "normal" Unix priority/nice value  */
0563     priority = task_prio(task);
0564     nice = task_nice(task);
0565 
0566     /* apply timens offset for boottime and convert nsec -> ticks */
0567     start_time =
0568         nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
0569 
0570     seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
0571     seq_puts(m, " (");
0572     proc_task_name(m, task, false);
0573     seq_puts(m, ") ");
0574     seq_putc(m, state);
0575     seq_put_decimal_ll(m, " ", ppid);
0576     seq_put_decimal_ll(m, " ", pgid);
0577     seq_put_decimal_ll(m, " ", sid);
0578     seq_put_decimal_ll(m, " ", tty_nr);
0579     seq_put_decimal_ll(m, " ", tty_pgrp);
0580     seq_put_decimal_ull(m, " ", task->flags);
0581     seq_put_decimal_ull(m, " ", min_flt);
0582     seq_put_decimal_ull(m, " ", cmin_flt);
0583     seq_put_decimal_ull(m, " ", maj_flt);
0584     seq_put_decimal_ull(m, " ", cmaj_flt);
0585     seq_put_decimal_ull(m, " ", nsec_to_clock_t(utime));
0586     seq_put_decimal_ull(m, " ", nsec_to_clock_t(stime));
0587     seq_put_decimal_ll(m, " ", nsec_to_clock_t(cutime));
0588     seq_put_decimal_ll(m, " ", nsec_to_clock_t(cstime));
0589     seq_put_decimal_ll(m, " ", priority);
0590     seq_put_decimal_ll(m, " ", nice);
0591     seq_put_decimal_ll(m, " ", num_threads);
0592     seq_put_decimal_ull(m, " ", 0);
0593     seq_put_decimal_ull(m, " ", start_time);
0594     seq_put_decimal_ull(m, " ", vsize);
0595     seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);
0596     seq_put_decimal_ull(m, " ", rsslim);
0597     seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);
0598     seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);
0599     seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);
0600     seq_put_decimal_ull(m, " ", esp);
0601     seq_put_decimal_ull(m, " ", eip);
0602     /* The signal information here is obsolete.
0603      * It must be decimal for Linux 2.0 compatibility.
0604      * Use /proc/#/status for real-time signals.
0605      */
0606     seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);
0607     seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);
0608     seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);
0609     seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL);
0610 
0611     /*
0612      * We used to output the absolute kernel address, but that's an
0613      * information leak - so instead we show a 0/1 flag here, to signal
0614      * to user-space whether there's a wchan field in /proc/PID/wchan.
0615      *
0616      * This works with older implementations of procps as well.
0617      */
0618     seq_put_decimal_ull(m, " ", wchan);
0619 
0620     seq_put_decimal_ull(m, " ", 0);
0621     seq_put_decimal_ull(m, " ", 0);
0622     seq_put_decimal_ll(m, " ", task->exit_signal);
0623     seq_put_decimal_ll(m, " ", task_cpu(task));
0624     seq_put_decimal_ull(m, " ", task->rt_priority);
0625     seq_put_decimal_ull(m, " ", task->policy);
0626     seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));
0627     seq_put_decimal_ull(m, " ", nsec_to_clock_t(gtime));
0628     seq_put_decimal_ll(m, " ", nsec_to_clock_t(cgtime));
0629 
0630     if (mm && permitted) {
0631         seq_put_decimal_ull(m, " ", mm->start_data);
0632         seq_put_decimal_ull(m, " ", mm->end_data);
0633         seq_put_decimal_ull(m, " ", mm->start_brk);
0634         seq_put_decimal_ull(m, " ", mm->arg_start);
0635         seq_put_decimal_ull(m, " ", mm->arg_end);
0636         seq_put_decimal_ull(m, " ", mm->env_start);
0637         seq_put_decimal_ull(m, " ", mm->env_end);
0638     } else
0639         seq_puts(m, " 0 0 0 0 0 0 0");
0640 
0641     if (permitted)
0642         seq_put_decimal_ll(m, " ", exit_code);
0643     else
0644         seq_puts(m, " 0");
0645 
0646     seq_putc(m, '\n');
0647     if (mm)
0648         mmput(mm);
0649     return 0;
0650 }
0651 
0652 int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
0653             struct pid *pid, struct task_struct *task)
0654 {
0655     return do_task_stat(m, ns, pid, task, 0);
0656 }
0657 
0658 int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
0659             struct pid *pid, struct task_struct *task)
0660 {
0661     return do_task_stat(m, ns, pid, task, 1);
0662 }
0663 
0664 int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
0665             struct pid *pid, struct task_struct *task)
0666 {
0667     struct mm_struct *mm = get_task_mm(task);
0668 
0669     if (mm) {
0670         unsigned long size;
0671         unsigned long resident = 0;
0672         unsigned long shared = 0;
0673         unsigned long text = 0;
0674         unsigned long data = 0;
0675 
0676         size = task_statm(mm, &shared, &text, &data, &resident);
0677         mmput(mm);
0678 
0679         /*
0680          * For quick read, open code by putting numbers directly
0681          * expected format is
0682          * seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",
0683          *               size, resident, shared, text, data);
0684          */
0685         seq_put_decimal_ull(m, "", size);
0686         seq_put_decimal_ull(m, " ", resident);
0687         seq_put_decimal_ull(m, " ", shared);
0688         seq_put_decimal_ull(m, " ", text);
0689         seq_put_decimal_ull(m, " ", 0);
0690         seq_put_decimal_ull(m, " ", data);
0691         seq_put_decimal_ull(m, " ", 0);
0692         seq_putc(m, '\n');
0693     } else {
0694         seq_write(m, "0 0 0 0 0 0 0\n", 14);
0695     }
0696     return 0;
0697 }
0698 
0699 #ifdef CONFIG_PROC_CHILDREN
0700 static struct pid *
0701 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
0702 {
0703     struct task_struct *start, *task;
0704     struct pid *pid = NULL;
0705 
0706     read_lock(&tasklist_lock);
0707 
0708     start = pid_task(proc_pid(inode), PIDTYPE_PID);
0709     if (!start)
0710         goto out;
0711 
0712     /*
0713      * Lets try to continue searching first, this gives
0714      * us significant speedup on children-rich processes.
0715      */
0716     if (pid_prev) {
0717         task = pid_task(pid_prev, PIDTYPE_PID);
0718         if (task && task->real_parent == start &&
0719             !(list_empty(&task->sibling))) {
0720             if (list_is_last(&task->sibling, &start->children))
0721                 goto out;
0722             task = list_first_entry(&task->sibling,
0723                         struct task_struct, sibling);
0724             pid = get_pid(task_pid(task));
0725             goto out;
0726         }
0727     }
0728 
0729     /*
0730      * Slow search case.
0731      *
0732      * We might miss some children here if children
0733      * are exited while we were not holding the lock,
0734      * but it was never promised to be accurate that
0735      * much.
0736      *
0737      * "Just suppose that the parent sleeps, but N children
0738      *  exit after we printed their tids. Now the slow paths
0739      *  skips N extra children, we miss N tasks." (c)
0740      *
0741      * So one need to stop or freeze the leader and all
0742      * its children to get a precise result.
0743      */
0744     list_for_each_entry(task, &start->children, sibling) {
0745         if (pos-- == 0) {
0746             pid = get_pid(task_pid(task));
0747             break;
0748         }
0749     }
0750 
0751 out:
0752     read_unlock(&tasklist_lock);
0753     return pid;
0754 }
0755 
0756 static int children_seq_show(struct seq_file *seq, void *v)
0757 {
0758     struct inode *inode = file_inode(seq->file);
0759 
0760     seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode->i_sb)));
0761     return 0;
0762 }
0763 
0764 static void *children_seq_start(struct seq_file *seq, loff_t *pos)
0765 {
0766     return get_children_pid(file_inode(seq->file), NULL, *pos);
0767 }
0768 
0769 static void *children_seq_next(struct seq_file *seq, void *v, loff_t *pos)
0770 {
0771     struct pid *pid;
0772 
0773     pid = get_children_pid(file_inode(seq->file), v, *pos + 1);
0774     put_pid(v);
0775 
0776     ++*pos;
0777     return pid;
0778 }
0779 
0780 static void children_seq_stop(struct seq_file *seq, void *v)
0781 {
0782     put_pid(v);
0783 }
0784 
0785 static const struct seq_operations children_seq_ops = {
0786     .start  = children_seq_start,
0787     .next   = children_seq_next,
0788     .stop   = children_seq_stop,
0789     .show   = children_seq_show,
0790 };
0791 
0792 static int children_seq_open(struct inode *inode, struct file *file)
0793 {
0794     return seq_open(file, &children_seq_ops);
0795 }
0796 
0797 const struct file_operations proc_tid_children_operations = {
0798     .open    = children_seq_open,
0799     .read    = seq_read,
0800     .llseek  = seq_lseek,
0801     .release = seq_release,
0802 };
0803 #endif /* CONFIG_PROC_CHILDREN */