init_task.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef _LINUX__INIT_TASK_H
  2. #define _LINUX__INIT_TASK_H
  3. #include <linux/rcupdate.h>
  4. #include <linux/irqflags.h>
  5. #include <linux/utsname.h>
  6. #include <linux/lockdep.h>
  7. #include <linux/ftrace.h>
  8. #include <linux/ipc.h>
  9. #include <linux/pid_namespace.h>
  10. #include <linux/user_namespace.h>
  11. #include <linux/securebits.h>
  12. #include <net/net_namespace.h>
  13. extern struct files_struct init_files;
  14. extern struct fs_struct init_fs;
  15. #define INIT_SIGNALS(sig) { \
  16. .count = ATOMIC_INIT(1), \
  17. .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
  18. .shared_pending = { \
  19. .list = LIST_HEAD_INIT(sig.shared_pending.list), \
  20. .signal = {{0}}}, \
  21. .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \
  22. .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
  23. .rlim = INIT_RLIMITS, \
  24. .cputimer = { \
  25. .cputime = INIT_CPUTIME, \
  26. .running = 0, \
  27. .lock = __SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \
  28. }, \
  29. }
  30. extern struct nsproxy init_nsproxy;
  31. #define INIT_NSPROXY(nsproxy) { \
  32. .pid_ns = &init_pid_ns, \
  33. .count = ATOMIC_INIT(1), \
  34. .uts_ns = &init_uts_ns, \
  35. .mnt_ns = NULL, \
  36. INIT_NET_NS(net_ns) \
  37. INIT_IPC_NS(ipc_ns) \
  38. }
  39. #define INIT_SIGHAND(sighand) { \
  40. .count = ATOMIC_INIT(1), \
  41. .action = { { { .sa_handler = NULL, } }, }, \
  42. .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
  43. .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
  44. }
  45. extern struct group_info init_groups;
  46. #define INIT_STRUCT_PID { \
  47. .count = ATOMIC_INIT(1), \
  48. .tasks = { \
  49. { .first = &init_task.pids[PIDTYPE_PID].node }, \
  50. { .first = &init_task.pids[PIDTYPE_PGID].node }, \
  51. { .first = &init_task.pids[PIDTYPE_SID].node }, \
  52. }, \
  53. .rcu = RCU_HEAD_INIT, \
  54. .level = 0, \
  55. .numbers = { { \
  56. .nr = 0, \
  57. .ns = &init_pid_ns, \
  58. .pid_chain = { .next = NULL, .pprev = NULL }, \
  59. }, } \
  60. }
  61. #define INIT_PID_LINK(type) \
  62. { \
  63. .node = { \
  64. .next = NULL, \
  65. .pprev = &init_struct_pid.tasks[type].first, \
  66. }, \
  67. .pid = &init_struct_pid, \
  68. }
  69. #ifdef CONFIG_AUDITSYSCALL
  70. #define INIT_IDS \
  71. .loginuid = -1, \
  72. .sessionid = -1,
  73. #else
  74. #define INIT_IDS
  75. #endif
  76. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  77. /*
  78. * Because of the reduced scope of CAP_SETPCAP when filesystem
  79. * capabilities are in effect, it is safe to allow CAP_SETPCAP to
  80. * be available in the default configuration.
  81. */
  82. # define CAP_INIT_BSET CAP_FULL_SET
  83. #else
  84. # define CAP_INIT_BSET CAP_INIT_EFF_SET
  85. #endif
  86. #ifdef CONFIG_PREEMPT_RCU
  87. #define INIT_TASK_RCU_PREEMPT(tsk) \
  88. .rcu_read_lock_nesting = 0, \
  89. .rcu_flipctr_idx = 0,
  90. #elif defined(CONFIG_TREE_PREEMPT_RCU)
  91. #define INIT_TASK_RCU_PREEMPT(tsk) \
  92. .rcu_read_lock_nesting = 0, \
  93. .rcu_read_unlock_special = 0, \
  94. .rcu_blocked_cpu = -1, \
  95. .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry),
  96. #else
  97. #define INIT_TASK_RCU_PREEMPT(tsk)
  98. #endif
  99. extern struct cred init_cred;
  100. #ifdef CONFIG_PERF_COUNTERS
  101. # define INIT_PERF_COUNTERS(tsk) \
  102. .perf_counter_mutex = \
  103. __MUTEX_INITIALIZER(tsk.perf_counter_mutex), \
  104. .perf_counter_list = LIST_HEAD_INIT(tsk.perf_counter_list),
  105. #else
  106. # define INIT_PERF_COUNTERS(tsk)
  107. #endif
  108. /*
  109. * INIT_TASK is used to set up the first task table, touch at
  110. * your own risk!. Base=0, limit=0x1fffff (=2MB)
  111. */
  112. #define INIT_TASK(tsk) \
  113. { \
  114. .state = 0, \
  115. .stack = &init_thread_info, \
  116. .usage = ATOMIC_INIT(2), \
  117. .flags = PF_KTHREAD, \
  118. .lock_depth = -1, \
  119. .prio = MAX_PRIO-20, \
  120. .static_prio = MAX_PRIO-20, \
  121. .normal_prio = MAX_PRIO-20, \
  122. .policy = SCHED_NORMAL, \
  123. .cpus_allowed = CPU_MASK_ALL, \
  124. .mm = NULL, \
  125. .active_mm = &init_mm, \
  126. .se = { \
  127. .group_node = LIST_HEAD_INIT(tsk.se.group_node), \
  128. }, \
  129. .rt = { \
  130. .run_list = LIST_HEAD_INIT(tsk.rt.run_list), \
  131. .time_slice = HZ, \
  132. .nr_cpus_allowed = NR_CPUS, \
  133. }, \
  134. .tasks = LIST_HEAD_INIT(tsk.tasks), \
  135. .pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO), \
  136. .ptraced = LIST_HEAD_INIT(tsk.ptraced), \
  137. .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
  138. .real_parent = &tsk, \
  139. .parent = &tsk, \
  140. .children = LIST_HEAD_INIT(tsk.children), \
  141. .sibling = LIST_HEAD_INIT(tsk.sibling), \
  142. .group_leader = &tsk, \
  143. .real_cred = &init_cred, \
  144. .cred = &init_cred, \
  145. .cred_guard_mutex = \
  146. __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
  147. .comm = "swapper", \
  148. .thread = INIT_THREAD, \
  149. .fs = &init_fs, \
  150. .files = &init_files, \
  151. .signal = &init_signals, \
  152. .sighand = &init_sighand, \
  153. .nsproxy = &init_nsproxy, \
  154. .pending = { \
  155. .list = LIST_HEAD_INIT(tsk.pending.list), \
  156. .signal = {{0}}}, \
  157. .blocked = {{0}}, \
  158. .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
  159. .journal_info = NULL, \
  160. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  161. .fs_excl = ATOMIC_INIT(0), \
  162. .pi_lock = __SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  163. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  164. .pids = { \
  165. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  166. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  167. [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \
  168. }, \
  169. .dirties = INIT_PROP_LOCAL_SINGLE(dirties), \
  170. INIT_IDS \
  171. INIT_PERF_COUNTERS(tsk) \
  172. INIT_TRACE_IRQFLAGS \
  173. INIT_LOCKDEP \
  174. INIT_FTRACE_GRAPH \
  175. INIT_TRACE_RECURSION \
  176. INIT_TASK_RCU_PREEMPT(tsk) \
  177. }
  178. #define INIT_CPU_TIMERS(cpu_timers) \
  179. { \
  180. LIST_HEAD_INIT(cpu_timers[0]), \
  181. LIST_HEAD_INIT(cpu_timers[1]), \
  182. LIST_HEAD_INIT(cpu_timers[2]), \
  183. }
  184. /* Attach to the init_task data structure for proper alignment */
  185. #define __init_task_data __attribute__((__section__(".data.init_task")))
  186. #endif