Re: Getting "current" task's pointer in 2.6

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 30 Dec 2004 12:03:24 +0530, Mandeep Sandhu
<Mandeep_Sandhu@xxxxxxxxxxx> wrote:

> I was going through RML's book (ch. 2). There he mentions that
> having the new structure "thread_info" helps in calculating the
> offsets using assembly code rather easily. How does having a struct
> (which has a pointer to task_struct) stored on the top a process
> kernel stack be more advantageous than storing a pointer to
> task_struct itself on the same location!?

He's referring to the fact that thread_info contains a few very useful
elements that we might want to access quickly - for other stuf we need
to resort to the task_struct itself. As rml also notes, the current
task is often available for indirection access via a specific register
when in kernel mode - r2 on PowerPC (sorry rml, for once thinking that
was incorrect).

> Furthermore the assembly code used to get a pointer to thread_info
> masks the lower 13 bits to obtain the pointer.

It masks out the kernel mode stack to get at the thread_info at the bottom.

> I was trying to
> do a "sizeof" of struct thread_info from a sample prog. but was
> getting errors when i tried to include linux/thread_info.h.....so
> i thought i'll ask here! :)

Don't include that directly in userspace, copy the struct define and
use that if needed. Perhaps also just write a very simple LKM to do it
for you:

/*
 * threadinfo_test.c - A simple test LKM.
 *
 */

#include <linux/module.h>        /* module macros */
#include <linux/init.h>          /* init macros */

#include <linux/config.h>
#include <linux/errno.h>
#include <linux/kernel.h>

int __init threadinfo_init(void)
{

        printk("The size of thread_info is %d bytes.\n",
                sizeof(struct thread_info));

        return 0;
}

void __exit threadinfo_exit(void)
{
}

module_init(threadinfo_init);
module_exit(threadinfo_exit);

MODULE_AUTHOR("Jon Masters <jcm@xxxxxxxxxxxxxx>");
MODULE_LICENSE("GPL");

Cheers,

Jon.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux