array.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /*
  2. * linux/fs/proc/array.c
  3. *
  4. * Copyright (C) 1992 by Linus Torvalds
  5. * based on ideas by Darren Senn
  6. *
  7. * Fixes:
  8. * Michael. K. Johnson: stat,statm extensions.
  9. * <johnsonm@stolaf.edu>
  10. *
  11. * Pauline Middelink : Made cmdline,envline only break at '\0's, to
  12. * make sure SET_PROCTITLE works. Also removed
  13. * bad '!' which forced address recalculation for
  14. * EVERY character on the current page.
  15. * <middelin@polyware.iaf.nl>
  16. *
  17. * Danny ter Haar : added cpuinfo
  18. * <dth@cistron.nl>
  19. *
  20. * Alessandro Rubini : profile extension.
  21. * <rubini@ipvvis.unipv.it>
  22. *
  23. * Jeff Tranter : added BogoMips field to cpuinfo
  24. * <Jeff_Tranter@Mitel.COM>
  25. *
  26. * Bruno Haible : remove 4K limit for the maps file
  27. * <haible@ma2s2.mathematik.uni-karlsruhe.de>
  28. *
  29. * Yves Arrouye : remove removal of trailing spaces in get_array.
  30. * <Yves.Arrouye@marin.fdn.fr>
  31. *
  32. * Jerome Forissier : added per-CPU time information to /proc/stat
  33. * and /proc/<pid>/cpu extension
  34. * <forissier@isia.cma.fr>
  35. * - Incorporation and non-SMP safe operation
  36. * of forissier patch in 2.1.78 by
  37. * Hans Marcus <crowbar@concepts.nl>
  38. *
  39. * aeb@cwi.nl : /proc/partitions
  40. *
  41. *
  42. * Alan Cox : security fixes.
  43. * <alan@lxorguk.ukuu.org.uk>
  44. *
  45. * Al Viro : safe handling of mm_struct
  46. *
  47. * Gerhard Wichert : added BIGMEM support
  48. * Siemens AG <Gerhard.Wichert@pdb.siemens.de>
  49. *
  50. * Al Viro & Jeff Garzik : moved most of the thing into base.c and
  51. * : proc_misc.c. The rest may eventually go into
  52. * : base.c too.
  53. */
  54. #include <linux/types.h>
  55. #include <linux/errno.h>
  56. #include <linux/time.h>
  57. #include <linux/kernel.h>
  58. #include <linux/kernel_stat.h>
  59. #include <linux/tty.h>
  60. #include <linux/string.h>
  61. #include <linux/mman.h>
  62. #include <linux/sched.h>
  63. #include <linux/proc_fs.h>
  64. #include <linux/ioport.h>
  65. #include <linux/uaccess.h>
  66. #include <linux/io.h>
  67. #include <linux/mm.h>
  68. #include <linux/hugetlb.h>
  69. #include <linux/pagemap.h>
  70. #include <linux/swap.h>
  71. #include <linux/smp.h>
  72. #include <linux/signal.h>
  73. #include <linux/highmem.h>
  74. #include <linux/file.h>
  75. #include <linux/fdtable.h>
  76. #include <linux/times.h>
  77. #include <linux/cpuset.h>
  78. #include <linux/rcupdate.h>
  79. #include <linux/delayacct.h>
  80. #include <linux/seq_file.h>
  81. #include <linux/pid_namespace.h>
  82. #include <linux/prctl.h>
  83. #include <linux/ptrace.h>
  84. #include <linux/tracehook.h>
  85. #include <linux/string_helpers.h>
  86. #include <linux/user_namespace.h>
  87. #include <linux/fs_struct.h>
  88. #include <asm/pgtable.h>
  89. #include <asm/processor.h>
  90. #include "internal.h"
  91. static inline void task_name(struct seq_file *m, struct task_struct *p)
  92. {
  93. char *buf;
  94. size_t size;
  95. char tcomm[sizeof(p->comm)];
  96. int ret;
  97. get_task_comm(tcomm, p);
  98. seq_puts(m, "Name:\t");
  99. size = seq_get_buf(m, &buf);
  100. ret = string_escape_str(tcomm, buf, size, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
  101. seq_commit(m, ret < size ? ret : -1);
  102. seq_putc(m, '\n');
  103. }
  104. /*
  105. * The task state array is a strange "bitmap" of
  106. * reasons to sleep. Thus "running" is zero, and
  107. * you can test for combinations of others with
  108. * simple bit tests.
  109. */
  110. static const char * const task_state_array[] = {
  111. "R (running)", /* 0 */
  112. "S (sleeping)", /* 1 */
  113. "D (disk sleep)", /* 2 */
  114. "T (stopped)", /* 4 */
  115. "t (tracing stop)", /* 8 */
  116. "X (dead)", /* 16 */
  117. "Z (zombie)", /* 32 */
  118. };
  119. static inline const char *get_task_state(struct task_struct *tsk)
  120. {
  121. unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT;
  122. /*
  123. * Parked tasks do not run; they sit in __kthread_parkme().
  124. * Without this check, we would report them as running, which is
  125. * clearly wrong, so we report them as sleeping instead.
  126. */
  127. if (tsk->state == TASK_PARKED)
  128. state = TASK_INTERRUPTIBLE;
  129. BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);
  130. return task_state_array[fls(state)];
  131. }
  132. static inline int get_task_umask(struct task_struct *tsk)
  133. {
  134. struct fs_struct *fs;
  135. int umask = -ENOENT;
  136. task_lock(tsk);
  137. fs = tsk->fs;
  138. if (fs)
  139. umask = fs->umask;
  140. task_unlock(tsk);
  141. return umask;
  142. }
  143. static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
  144. struct pid *pid, struct task_struct *p)
  145. {
  146. struct user_namespace *user_ns = seq_user_ns(m);
  147. struct group_info *group_info;
  148. int g, umask;
  149. struct task_struct *tracer;
  150. const struct cred *cred;
  151. pid_t ppid, tpid = 0, tgid, ngid;
  152. unsigned int max_fds = 0;
  153. rcu_read_lock();
  154. ppid = pid_alive(p) ?
  155. task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
  156. tracer = ptrace_parent(p);
  157. if (tracer)
  158. tpid = task_pid_nr_ns(tracer, ns);
  159. tgid = task_tgid_nr_ns(p, ns);
  160. ngid = task_numa_group_id(p);
  161. cred = get_task_cred(p);
  162. umask = get_task_umask(p);
  163. if (umask >= 0)
  164. seq_printf(m, "Umask:\t%#04o\n", umask);
  165. task_lock(p);
  166. if (p->files)
  167. max_fds = files_fdtable(p->files)->max_fds;
  168. task_unlock(p);
  169. rcu_read_unlock();
  170. seq_printf(m, "State:\t%s", get_task_state(p));
  171. seq_put_decimal_ull(m, "\nTgid:\t", tgid);
  172. seq_put_decimal_ull(m, "\nNgid:\t", ngid);
  173. seq_put_decimal_ull(m, "\nPid:\t", pid_nr_ns(pid, ns));
  174. seq_put_decimal_ull(m, "\nPPid:\t", ppid);
  175. seq_put_decimal_ull(m, "\nTracerPid:\t", tpid);
  176. seq_put_decimal_ull(m, "\nUid:\t", from_kuid_munged(user_ns, cred->uid));
  177. seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->euid));
  178. seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->suid));
  179. seq_put_decimal_ull(m, "\t", from_kuid_munged(user_ns, cred->fsuid));
  180. seq_put_decimal_ull(m, "\nGid:\t", from_kgid_munged(user_ns, cred->gid));
  181. seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->egid));
  182. seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->sgid));
  183. seq_put_decimal_ull(m, "\t", from_kgid_munged(user_ns, cred->fsgid));
  184. seq_put_decimal_ull(m, "\nFDSize:\t", max_fds);
  185. seq_puts(m, "\nGroups:\t");
  186. group_info = cred->group_info;
  187. for (g = 0; g < group_info->ngroups; g++)
  188. seq_put_decimal_ull(m, g ? " " : "",
  189. from_kgid_munged(user_ns, group_info->gid[g]));
  190. put_cred(cred);
  191. /* Trailing space shouldn't have been added in the first place. */
  192. seq_putc(m, ' ');
  193. #ifdef CONFIG_PID_NS
  194. seq_puts(m, "\nNStgid:");
  195. for (g = ns->level; g <= pid->level; g++)
  196. seq_put_decimal_ull(m, "\t", task_tgid_nr_ns(p, pid->numbers[g].ns));
  197. seq_puts(m, "\nNSpid:");
  198. for (g = ns->level; g <= pid->level; g++)
  199. seq_put_decimal_ull(m, "\t", task_pid_nr_ns(p, pid->numbers[g].ns));
  200. seq_puts(m, "\nNSpgid:");
  201. for (g = ns->level; g <= pid->level; g++)
  202. seq_put_decimal_ull(m, "\t", task_pgrp_nr_ns(p, pid->numbers[g].ns));
  203. seq_puts(m, "\nNSsid:");
  204. for (g = ns->level; g <= pid->level; g++)
  205. seq_put_decimal_ull(m, "\t", task_session_nr_ns(p, pid->numbers[g].ns));
  206. #endif
  207. seq_putc(m, '\n');
  208. }
  209. void render_sigset_t(struct seq_file *m, const char *header,
  210. sigset_t *set)
  211. {
  212. int i;
  213. seq_puts(m, header);
  214. i = _NSIG;
  215. do {
  216. int x = 0;
  217. i -= 4;
  218. if (sigismember(set, i+1)) x |= 1;
  219. if (sigismember(set, i+2)) x |= 2;
  220. if (sigismember(set, i+3)) x |= 4;
  221. if (sigismember(set, i+4)) x |= 8;
  222. seq_printf(m, "%x", x);
  223. } while (i >= 4);
  224. seq_putc(m, '\n');
  225. }
  226. static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
  227. sigset_t *catch)
  228. {
  229. struct k_sigaction *k;
  230. int i;
  231. k = p->sighand->action;
  232. for (i = 1; i <= _NSIG; ++i, ++k) {
  233. if (k->sa.sa_handler == SIG_IGN)
  234. sigaddset(ign, i);
  235. else if (k->sa.sa_handler != SIG_DFL)
  236. sigaddset(catch, i);
  237. }
  238. }
  239. static inline void task_sig(struct seq_file *m, struct task_struct *p)
  240. {
  241. unsigned long flags;
  242. sigset_t pending, shpending, blocked, ignored, caught;
  243. int num_threads = 0;
  244. unsigned long qsize = 0;
  245. unsigned long qlim = 0;
  246. sigemptyset(&pending);
  247. sigemptyset(&shpending);
  248. sigemptyset(&blocked);
  249. sigemptyset(&ignored);
  250. sigemptyset(&caught);
  251. if (lock_task_sighand(p, &flags)) {
  252. pending = p->pending.signal;
  253. shpending = p->signal->shared_pending.signal;
  254. blocked = p->blocked;
  255. collect_sigign_sigcatch(p, &ignored, &caught);
  256. num_threads = get_nr_threads(p);
  257. rcu_read_lock(); /* FIXME: is this correct? */
  258. qsize = atomic_read(&__task_cred(p)->user->sigpending);
  259. rcu_read_unlock();
  260. qlim = task_rlimit(p, RLIMIT_SIGPENDING);
  261. unlock_task_sighand(p, &flags);
  262. }
  263. seq_put_decimal_ull(m, "Threads:\t", num_threads);
  264. seq_put_decimal_ull(m, "\nSigQ:\t", qsize);
  265. seq_put_decimal_ull(m, "/", qlim);
  266. /* render them all */
  267. render_sigset_t(m, "\nSigPnd:\t", &pending);
  268. render_sigset_t(m, "ShdPnd:\t", &shpending);
  269. render_sigset_t(m, "SigBlk:\t", &blocked);
  270. render_sigset_t(m, "SigIgn:\t", &ignored);
  271. render_sigset_t(m, "SigCgt:\t", &caught);
  272. }
  273. static void render_cap_t(struct seq_file *m, const char *header,
  274. kernel_cap_t *a)
  275. {
  276. unsigned __capi;
  277. seq_puts(m, header);
  278. CAP_FOR_EACH_U32(__capi) {
  279. seq_printf(m, "%08x",
  280. a->cap[CAP_LAST_U32 - __capi]);
  281. }
  282. seq_putc(m, '\n');
  283. }
  284. static inline void task_cap(struct seq_file *m, struct task_struct *p)
  285. {
  286. const struct cred *cred;
  287. kernel_cap_t cap_inheritable, cap_permitted, cap_effective,
  288. cap_bset, cap_ambient;
  289. rcu_read_lock();
  290. cred = __task_cred(p);
  291. cap_inheritable = cred->cap_inheritable;
  292. cap_permitted = cred->cap_permitted;
  293. cap_effective = cred->cap_effective;
  294. cap_bset = cred->cap_bset;
  295. cap_ambient = cred->cap_ambient;
  296. rcu_read_unlock();
  297. render_cap_t(m, "CapInh:\t", &cap_inheritable);
  298. render_cap_t(m, "CapPrm:\t", &cap_permitted);
  299. render_cap_t(m, "CapEff:\t", &cap_effective);
  300. render_cap_t(m, "CapBnd:\t", &cap_bset);
  301. render_cap_t(m, "CapAmb:\t", &cap_ambient);
  302. }
  303. static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
  304. {
  305. #ifdef CONFIG_SECCOMP
  306. seq_put_decimal_ull(m, "Seccomp:\t", p->seccomp.mode);
  307. #endif
  308. seq_printf(m, "\nSpeculation_Store_Bypass:\t");
  309. switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_STORE_BYPASS)) {
  310. case -EINVAL:
  311. seq_printf(m, "unknown");
  312. break;
  313. case PR_SPEC_NOT_AFFECTED:
  314. seq_printf(m, "not vulnerable");
  315. break;
  316. case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE:
  317. seq_printf(m, "thread force mitigated");
  318. break;
  319. case PR_SPEC_PRCTL | PR_SPEC_DISABLE:
  320. seq_printf(m, "thread mitigated");
  321. break;
  322. case PR_SPEC_PRCTL | PR_SPEC_ENABLE:
  323. seq_printf(m, "thread vulnerable");
  324. break;
  325. case PR_SPEC_DISABLE:
  326. seq_printf(m, "globally mitigated");
  327. break;
  328. default:
  329. seq_printf(m, "vulnerable");
  330. break;
  331. }
  332. seq_putc(m, '\n');
  333. }
  334. static inline void task_context_switch_counts(struct seq_file *m,
  335. struct task_struct *p)
  336. {
  337. seq_put_decimal_ull(m, "voluntary_ctxt_switches:\t", p->nvcsw);
  338. seq_put_decimal_ull(m, "\nnonvoluntary_ctxt_switches:\t", p->nivcsw);
  339. seq_putc(m, '\n');
  340. }
  341. static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
  342. {
  343. seq_printf(m, "Cpus_allowed:\t%*pb\n",
  344. cpumask_pr_args(&task->cpus_allowed));
  345. seq_printf(m, "Cpus_allowed_list:\t%*pbl\n",
  346. cpumask_pr_args(&task->cpus_allowed));
  347. }
  348. int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
  349. struct pid *pid, struct task_struct *task)
  350. {
  351. struct mm_struct *mm = get_task_mm(task);
  352. task_name(m, task);
  353. task_state(m, ns, pid, task);
  354. if (mm) {
  355. task_mem(m, mm);
  356. mmput(mm);
  357. }
  358. task_sig(m, task);
  359. task_cap(m, task);
  360. task_seccomp(m, task);
  361. task_cpus_allowed(m, task);
  362. cpuset_task_status_allowed(m, task);
  363. task_context_switch_counts(m, task);
  364. return 0;
  365. }
  366. static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  367. struct pid *pid, struct task_struct *task, int whole)
  368. {
  369. unsigned long vsize, eip, esp, wchan = 0;
  370. int priority, nice;
  371. int tty_pgrp = -1, tty_nr = 0;
  372. sigset_t sigign, sigcatch;
  373. char state;
  374. pid_t ppid = 0, pgid = -1, sid = -1;
  375. int num_threads = 0;
  376. int permitted;
  377. struct mm_struct *mm;
  378. unsigned long long start_time;
  379. unsigned long cmin_flt = 0, cmaj_flt = 0;
  380. unsigned long min_flt = 0, maj_flt = 0;
  381. cputime_t cutime, cstime, utime, stime;
  382. cputime_t cgtime, gtime;
  383. unsigned long rsslim = 0;
  384. char tcomm[sizeof(task->comm)];
  385. unsigned long flags;
  386. state = *get_task_state(task);
  387. vsize = eip = esp = 0;
  388. permitted = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT);
  389. mm = get_task_mm(task);
  390. if (mm) {
  391. vsize = task_vsize(mm);
  392. /*
  393. * esp and eip are intentionally zeroed out. There is no
  394. * non-racy way to read them without freezing the task.
  395. * Programs that need reliable values can use ptrace(2).
  396. *
  397. * The only exception is if the task is core dumping because
  398. * a program is not able to use ptrace(2) in that case. It is
  399. * safe because the task has stopped executing permanently.
  400. */
  401. if (permitted && (task->flags & PF_DUMPCORE)) {
  402. if (try_get_task_stack(task)) {
  403. eip = KSTK_EIP(task);
  404. esp = KSTK_ESP(task);
  405. put_task_stack(task);
  406. }
  407. }
  408. }
  409. get_task_comm(tcomm, task);
  410. sigemptyset(&sigign);
  411. sigemptyset(&sigcatch);
  412. cutime = cstime = utime = stime = 0;
  413. cgtime = gtime = 0;
  414. if (lock_task_sighand(task, &flags)) {
  415. struct signal_struct *sig = task->signal;
  416. if (sig->tty) {
  417. struct pid *pgrp = tty_get_pgrp(sig->tty);
  418. tty_pgrp = pid_nr_ns(pgrp, ns);
  419. put_pid(pgrp);
  420. tty_nr = new_encode_dev(tty_devnum(sig->tty));
  421. }
  422. num_threads = get_nr_threads(task);
  423. collect_sigign_sigcatch(task, &sigign, &sigcatch);
  424. cmin_flt = sig->cmin_flt;
  425. cmaj_flt = sig->cmaj_flt;
  426. cutime = sig->cutime;
  427. cstime = sig->cstime;
  428. cgtime = sig->cgtime;
  429. rsslim = ACCESS_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur);
  430. /* add up live thread stats at the group level */
  431. if (whole) {
  432. struct task_struct *t = task;
  433. do {
  434. min_flt += t->min_flt;
  435. maj_flt += t->maj_flt;
  436. gtime += task_gtime(t);
  437. } while_each_thread(task, t);
  438. min_flt += sig->min_flt;
  439. maj_flt += sig->maj_flt;
  440. thread_group_cputime_adjusted(task, &utime, &stime);
  441. gtime += sig->gtime;
  442. }
  443. sid = task_session_nr_ns(task, ns);
  444. ppid = task_tgid_nr_ns(task->real_parent, ns);
  445. pgid = task_pgrp_nr_ns(task, ns);
  446. unlock_task_sighand(task, &flags);
  447. }
  448. if (permitted && (!whole || num_threads < 2))
  449. wchan = get_wchan(task);
  450. if (!whole) {
  451. min_flt = task->min_flt;
  452. maj_flt = task->maj_flt;
  453. task_cputime_adjusted(task, &utime, &stime);
  454. gtime = task_gtime(task);
  455. }
  456. /* scale priority and nice values from timeslices to -20..20 */
  457. /* to make it look like a "normal" Unix priority/nice value */
  458. priority = task_prio(task);
  459. nice = task_nice(task);
  460. /* convert nsec -> ticks */
  461. start_time = nsec_to_clock_t(task->real_start_time);
  462. seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
  463. seq_put_decimal_ll(m, " ", ppid);
  464. seq_put_decimal_ll(m, " ", pgid);
  465. seq_put_decimal_ll(m, " ", sid);
  466. seq_put_decimal_ll(m, " ", tty_nr);
  467. seq_put_decimal_ll(m, " ", tty_pgrp);
  468. seq_put_decimal_ull(m, " ", task->flags);
  469. seq_put_decimal_ull(m, " ", min_flt);
  470. seq_put_decimal_ull(m, " ", cmin_flt);
  471. seq_put_decimal_ull(m, " ", maj_flt);
  472. seq_put_decimal_ull(m, " ", cmaj_flt);
  473. seq_put_decimal_ull(m, " ", cputime_to_clock_t(utime));
  474. seq_put_decimal_ull(m, " ", cputime_to_clock_t(stime));
  475. seq_put_decimal_ll(m, " ", cputime_to_clock_t(cutime));
  476. seq_put_decimal_ll(m, " ", cputime_to_clock_t(cstime));
  477. seq_put_decimal_ll(m, " ", priority);
  478. seq_put_decimal_ll(m, " ", nice);
  479. seq_put_decimal_ll(m, " ", num_threads);
  480. seq_put_decimal_ull(m, " ", 0);
  481. seq_put_decimal_ull(m, " ", start_time);
  482. seq_put_decimal_ull(m, " ", vsize);
  483. seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);
  484. seq_put_decimal_ull(m, " ", rsslim);
  485. seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);
  486. seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);
  487. seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);
  488. seq_put_decimal_ull(m, " ", esp);
  489. seq_put_decimal_ull(m, " ", eip);
  490. /* The signal information here is obsolete.
  491. * It must be decimal for Linux 2.0 compatibility.
  492. * Use /proc/#/status for real-time signals.
  493. */
  494. seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);
  495. seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);
  496. seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);
  497. seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL);
  498. /*
  499. * We used to output the absolute kernel address, but that's an
  500. * information leak - so instead we show a 0/1 flag here, to signal
  501. * to user-space whether there's a wchan field in /proc/PID/wchan.
  502. *
  503. * This works with older implementations of procps as well.
  504. */
  505. if (wchan)
  506. seq_puts(m, " 1");
  507. else
  508. seq_puts(m, " 0");
  509. seq_put_decimal_ull(m, " ", 0);
  510. seq_put_decimal_ull(m, " ", 0);
  511. seq_put_decimal_ll(m, " ", task->exit_signal);
  512. seq_put_decimal_ll(m, " ", task_cpu(task));
  513. seq_put_decimal_ull(m, " ", task->rt_priority);
  514. seq_put_decimal_ull(m, " ", task->policy);
  515. seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));
  516. seq_put_decimal_ull(m, " ", cputime_to_clock_t(gtime));
  517. seq_put_decimal_ll(m, " ", cputime_to_clock_t(cgtime));
  518. if (mm && permitted) {
  519. seq_put_decimal_ull(m, " ", mm->start_data);
  520. seq_put_decimal_ull(m, " ", mm->end_data);
  521. seq_put_decimal_ull(m, " ", mm->start_brk);
  522. seq_put_decimal_ull(m, " ", mm->arg_start);
  523. seq_put_decimal_ull(m, " ", mm->arg_end);
  524. seq_put_decimal_ull(m, " ", mm->env_start);
  525. seq_put_decimal_ull(m, " ", mm->env_end);
  526. } else
  527. seq_puts(m, " 0 0 0 0 0 0 0");
  528. if (permitted)
  529. seq_put_decimal_ll(m, " ", task->exit_code);
  530. else
  531. seq_puts(m, " 0");
  532. seq_putc(m, '\n');
  533. if (mm)
  534. mmput(mm);
  535. return 0;
  536. }
  537. int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
  538. struct pid *pid, struct task_struct *task)
  539. {
  540. return do_task_stat(m, ns, pid, task, 0);
  541. }
  542. int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
  543. struct pid *pid, struct task_struct *task)
  544. {
  545. return do_task_stat(m, ns, pid, task, 1);
  546. }
  547. int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
  548. struct pid *pid, struct task_struct *task)
  549. {
  550. unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
  551. struct mm_struct *mm = get_task_mm(task);
  552. if (mm) {
  553. size = task_statm(mm, &shared, &text, &data, &resident);
  554. mmput(mm);
  555. }
  556. /*
  557. * For quick read, open code by putting numbers directly
  558. * expected format is
  559. * seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",
  560. * size, resident, shared, text, data);
  561. */
  562. seq_put_decimal_ull(m, "", size);
  563. seq_put_decimal_ull(m, " ", resident);
  564. seq_put_decimal_ull(m, " ", shared);
  565. seq_put_decimal_ull(m, " ", text);
  566. seq_put_decimal_ull(m, " ", 0);
  567. seq_put_decimal_ull(m, " ", data);
  568. seq_put_decimal_ull(m, " ", 0);
  569. seq_putc(m, '\n');
  570. return 0;
  571. }
  572. #ifdef CONFIG_PROC_CHILDREN
  573. static struct pid *
  574. get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
  575. {
  576. struct task_struct *start, *task;
  577. struct pid *pid = NULL;
  578. read_lock(&tasklist_lock);
  579. start = pid_task(proc_pid(inode), PIDTYPE_PID);
  580. if (!start)
  581. goto out;
  582. /*
  583. * Lets try to continue searching first, this gives
  584. * us significant speedup on children-rich processes.
  585. */
  586. if (pid_prev) {
  587. task = pid_task(pid_prev, PIDTYPE_PID);
  588. if (task && task->real_parent == start &&
  589. !(list_empty(&task->sibling))) {
  590. if (list_is_last(&task->sibling, &start->children))
  591. goto out;
  592. task = list_first_entry(&task->sibling,
  593. struct task_struct, sibling);
  594. pid = get_pid(task_pid(task));
  595. goto out;
  596. }
  597. }
  598. /*
  599. * Slow search case.
  600. *
  601. * We might miss some children here if children
  602. * are exited while we were not holding the lock,
  603. * but it was never promised to be accurate that
  604. * much.
  605. *
  606. * "Just suppose that the parent sleeps, but N children
  607. * exit after we printed their tids. Now the slow paths
  608. * skips N extra children, we miss N tasks." (c)
  609. *
  610. * So one need to stop or freeze the leader and all
  611. * its children to get a precise result.
  612. */
  613. list_for_each_entry(task, &start->children, sibling) {
  614. if (pos-- == 0) {
  615. pid = get_pid(task_pid(task));
  616. break;
  617. }
  618. }
  619. out:
  620. read_unlock(&tasklist_lock);
  621. return pid;
  622. }
  623. static int children_seq_show(struct seq_file *seq, void *v)
  624. {
  625. struct inode *inode = seq->private;
  626. pid_t pid;
  627. pid = pid_nr_ns(v, inode->i_sb->s_fs_info);
  628. seq_printf(seq, "%d ", pid);
  629. return 0;
  630. }
  631. static void *children_seq_start(struct seq_file *seq, loff_t *pos)
  632. {
  633. return get_children_pid(seq->private, NULL, *pos);
  634. }
  635. static void *children_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  636. {
  637. struct pid *pid;
  638. pid = get_children_pid(seq->private, v, *pos + 1);
  639. put_pid(v);
  640. ++*pos;
  641. return pid;
  642. }
  643. static void children_seq_stop(struct seq_file *seq, void *v)
  644. {
  645. put_pid(v);
  646. }
  647. static const struct seq_operations children_seq_ops = {
  648. .start = children_seq_start,
  649. .next = children_seq_next,
  650. .stop = children_seq_stop,
  651. .show = children_seq_show,
  652. };
  653. static int children_seq_open(struct inode *inode, struct file *file)
  654. {
  655. struct seq_file *m;
  656. int ret;
  657. ret = seq_open(file, &children_seq_ops);
  658. if (ret)
  659. return ret;
  660. m = file->private_data;
  661. m->private = inode;
  662. return ret;
  663. }
  664. int children_seq_release(struct inode *inode, struct file *file)
  665. {
  666. seq_release(inode, file);
  667. return 0;
  668. }
  669. const struct file_operations proc_tid_children_operations = {
  670. .open = children_seq_open,
  671. .read = seq_read,
  672. .llseek = seq_lseek,
  673. .release = children_seq_release,
  674. };
  675. #endif /* CONFIG_PROC_CHILDREN */