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