Use a variable before it's declaration

Rock Lee rocklee_104 at outlook.com
Thu Sep 10 04:44:23 EDT 2015


On 2015/9/10 15:55, Valdis.Kletnieks at vt.edu wrote:
> On Thu, 10 Sep 2015 15:09:42 +0800, Rock Lee said:
>
>> union thread_union init_thread_union __init_task_data =
>>
>>       { INIT_THREAD_INFO(init_task) };
>
> 'gcc -E' to see what this expands to.  All may not be as it seems. :)
>

Thanks, I used "make arch/arm/kernel/init_task.i" instead to see what 
that code expands to. It's exactly what confused me still. 
init_thread_union uses init_task before init_task's initialization.

union thread_union init_thread_union 
__attribute__((__section__(".data..init_task"))) =
  { { .task = &init_task, .exec_domain = &default_exec_domain, .flags = 
0, .preempt_count = (1 + 0x40000000), .addr_limit = 0x00000000, 
.cpu_domain = ((3) << (2*(1))) | ((3) << (2*(0))) | ((1) << (2*(2))), 
.restart_block = { .fn = do_no_restart_syscall, }, } };


struct task_struct init_task = { .state = 0, .stack = 
&(init_thread_union.thread_info), .usage = { (2) }, .flags = 0x00200000, 
.prio = (100 + 40)-20, .static_prio = (100 + 40)-20, .normal_prio = (100 
+ 40)-20, .policy = 0, .cpus_allowed = (cpumask_t) { { [(((1) + (8 * 
sizeof(long)) - 1) / (8 * sizeof(long)))-1] = ( ((1) % 32) ? (1UL<<((1) 
% 32))-1 : ~0UL ) } }, .mm = ((void *)0), .active_mm = &init_mm, .se = { 
.group_node = { &(init_task.se.group_node), &(init_task.se.group_node) 
}, }, .rt = { .run_list = { &(init_task.rt.run_list), 
&(init_task.rt.run_list) }, .time_slice = (100 * 100 / 1000), 
.nr_cpus_allowed = 1, }, .tasks = { &(init_task.tasks), 
&(init_task.tasks) }, .ptraced = { &(init_task.ptraced), 
&(init_task.ptraced) }, .ptrace_entry = { &(init_task.ptrace_entry), 
&(init_task.ptrace_entry) }, .real_parent = &init_task, .parent = 
&init_task, .children = { &(init_task.children), &(init_task.children) 
}, .sibling = { &(init_task.sibling), &(init_task.sibling) }, 
.group_leader = &init_task, .real_cred = (typeof(*&init_cred) 
*)(&init_cred), .cred = (typeof(*&init_cred) *)(&init_cred), .comm = 
"swapper", .thread = { }, .fs = &init_fs, .files = &init_files, .signal 
= &init_signals, .sighand = &init_sighand, .nsproxy = &init_nsproxy, 
.pending = { .list = { &(init_task.pending.list), 
&(init_task.pending.list) }, .signal = {{0}}}, .blocked = {{0}}, 
.alloc_lock = (spinlock_t ) { { .rlock = { .raw_lock = { 1 }, .magic = 
0xdead4ead, .owner_cpu = -1, .owner = ((void *)-1L), } } }, 
.journal_info = ((void *)0), .cpu_timers = { { 
&(init_task.cpu_timers[0]), &(init_task.cpu_timers[0]) }, { 
&(init_task.cpu_timers[1]), &(init_task.cpu_timers[1]) }, { 
&(init_task.cpu_timers[2]), &(init_task.cpu_timers[2]) }, }, .pi_lock = 
(raw_spinlock_t) { .raw_lock = { 1 }, .magic = 0xdead4ead, .owner_cpu = 
-1, .owner = ((void *)-1L), }, .timer_slack_ns = 50000, .pids = { 
[PIDTYPE_PID] = { .node = { .next = ((void *)0), .pprev = ((void *)0), 
}, .pid = &init_struct_pid, }, [PIDTYPE_PGID] = { .node = { .next = 
((void *)0), .pprev = ((void *)0), }, .pid = &init_struct_pid, }, 
[PIDTYPE_SID] = { .node = { .next = ((void *)0), .pprev = ((void *)0), 
}, .pid = &init_struct_pid, }, }, .thread_group = { 
&(init_task.thread_group), &(init_task.thread_group) }, };

-- 
Rock Lee



More information about the Kernelnewbies mailing list