<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<BR> <BR>
<DIV>
<DIV id=SkyDrivePlaceholder></DIV>
<HR id=stopSpelling>
Date: Tue, 17 Jul 2012 21:15:50 +0200<BR>Subject: setup_thread_stack<BR>From: francesco.scali@gmail.com<BR>To: kernelnewbies@kernelnewbies.org<BR><BR>Hi,
<DIV>I'm totally new to kernel code, just trying to understand the basics of the core subsystems.</DIV>
<DIV>During the do_fork call, there is a call to dup_task_struct, which in turn calls setup_thread_stack. </DIV>
<DIV>What's this call supposed to do? Inside I can see a call to the "task_thread_info" macro, but I don't quite understand it:</DIV>
<DIV><BR></DIV>
<DIV>#define task_thread_info(task)<SPAN style="WHITE-SPACE: pre" class=ecxApple-tab-span> </SPAN>((struct thread_info *)(task)->stack)</DIV>
<DIV><BR></DIV>
<DIV>can a task_struct be cast to a thread_info? perhaps my C knowledge should be improved..I know :(</DIV>
<DIV><BR></DIV>
<DIV>Sorry for the trivial question..just trying to understand :)</DIV>
<DIV> </DIV>
<DIV>it is nothing about C, but architecture of kernel. kernel put thread_info of every process at the bottom of stack.</DIV>
<DIV>please reference thread_info.h for your specific cpu architecture:</DIV>
<DIV>/*<BR> * how to get the thread information struct from C<BR> */<BR>static inline struct thread_info *current_thread_info(void) __attribute_const__;</DIV>
<DIV>static inline struct thread_info *current_thread_info(void)<BR>{<BR> register unsigned long sp asm ("sp");<BR> return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));<BR>}<BR></DIV>
<DIV>because kernel put thread_info at the bottom of stack, so when one process is running, kernel can use above inline</DIV>
<DIV>function to get the thread_info conveniently.</DIV>
<DIV> </DIV>
<DIV><BR>Regards,</DIV>
<DIV><BR></DIV>
<DIV>Francesco</DIV>
<DIV><BR></DIV><BR>_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</DIV>                                            </div></body>
</html>