All of lore.kernel.org
 help / color / mirror / Atom feed
* setup_thread_stack
@ 2012-07-17 19:15 Francesco Scali
  2012-07-18  2:28 ` setup_thread_stack 卜弋天
  2012-07-18  2:31 ` setup_thread_stack Mulyadi Santosa
  0 siblings, 2 replies; 3+ messages in thread
From: Francesco Scali @ 2012-07-17 19:15 UTC (permalink / raw)
  To: kernelnewbies

Hi,
I'm totally new to kernel code, just trying to understand the basics of the
core subsystems.
During the do_fork call, there is a call to dup_task_struct, which in turn
calls setup_thread_stack.
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:

#define task_thread_info(task) ((struct thread_info *)(task)->stack)

can a task_struct be cast to a thread_info? perhaps my C knowledge should
be improved..I know :(

Sorry for the trivial question..just trying to understand :)

Regards,

Francesco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120717/bce920a3/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* setup_thread_stack
  2012-07-17 19:15 setup_thread_stack Francesco Scali
@ 2012-07-18  2:28 ` 卜弋天
  2012-07-18  2:31 ` setup_thread_stack Mulyadi Santosa
  1 sibling, 0 replies; 3+ messages in thread
From: 卜弋天 @ 2012-07-18  2:28 UTC (permalink / raw)
  To: kernelnewbies



 



Date: Tue, 17 Jul 2012 21:15:50 +0200
Subject: setup_thread_stack
From: francesco.scali@gmail.com
To: kernelnewbies at kernelnewbies.org

Hi, 
I'm totally new to kernel code, just trying to understand the basics of the core subsystems.
During the do_fork call, there is a call to dup_task_struct, which in turn calls setup_thread_stack. 
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:


#define task_thread_info(task) ((struct thread_info *)(task)->stack)


can a task_struct be cast to a thread_info? perhaps my C knowledge should be improved..I know :(


Sorry for the trivial question..just trying to understand :)
 
it is nothing about C, but architecture of kernel. kernel put thread_info of every process at the bottom of stack.
please reference thread_info.h for your specific cpu architecture:
/*
 * how to get the thread information struct from C
 */
static inline struct thread_info *current_thread_info(void) __attribute_const__;
static inline struct thread_info *current_thread_info(void)
{
 register unsigned long sp asm ("sp");
 return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}

because kernel put thread_info at the bottom of stack, so when one process is running, kernel can use above inline
function to get the thread_info conveniently.
 

Regards,


Francesco


_______________________________________________ Kernelnewbies mailing list Kernelnewbies at kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120718/baed985c/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* setup_thread_stack
  2012-07-17 19:15 setup_thread_stack Francesco Scali
  2012-07-18  2:28 ` setup_thread_stack 卜弋天
@ 2012-07-18  2:31 ` Mulyadi Santosa
  1 sibling, 0 replies; 3+ messages in thread
From: Mulyadi Santosa @ 2012-07-18  2:31 UTC (permalink / raw)
  To: kernelnewbies

Hi :)

On Wed, Jul 18, 2012 at 2:15 AM, Francesco Scali
<francesco.scali@gmail.com> wrote:
> 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:
>
> #define task_thread_info(task) ((struct thread_info *)(task)->stack)

IMHO, it means that (in the following order):
1. get the task_struct ( you probably already know this)
2. get its stack property (you probably already know this too :) )

And that's it. That's the function of  task_thread_info() macro: to
return the stack area of that task. IIRC too, stack area is where
thread_info belongs to.


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-18  2:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17 19:15 setup_thread_stack Francesco Scali
2012-07-18  2:28 ` setup_thread_stack 卜弋天
2012-07-18  2:31 ` setup_thread_stack Mulyadi Santosa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.