Linux Kernel code "current" macro


 
Thread Tools Search this Thread
Top Forums Programming Linux Kernel code "current" macro
# 1  
Old 06-29-2011
Linux Kernel code "current" macro

I was going through the Linux code, i stuck with few inline assembly language code,

I have tried online but in vain. Any help is much appreciated. Thanks.

Code:
/* how to get the thread information struct from C */
static inline struct thread_info *current_thread_info(void)
{
    struct thread_info *ti;
    __asm__("andl %%esp,%0; ":"=r" (ti) : "0" (~(THREAD_SIZE - 1)));
    return ti;
}

I have understood the point that it is being taken from kernel mode stack of size 8192 bytes. But couldn't understand the assembly langauage instruction.

Last edited by kumaran_5555; 06-29-2011 at 09:44 AM..
# 2  
Old 06-29-2011
I believe you find the answer here:
Extended Asm - Using the GNU Compiler Collection (GCC)
# 3  
Old 06-29-2011
Quote:
Originally Posted by kumaran_5555
I was going through the Linux code, i stuck with few inline assembly language code,

I have tried online but in vain. Any help is much appreciated. Thanks.
esp would be the x86 stack pointer. And %0 is a variable parameter which in this case means ~(THREAD_SIZE-1) The stack is the context which thread-local variables, among other things, reside inside. Each thread gets their own little independent chunk.

I believe they're doing something similar to aligning a pointer along page boundaries. If the stack pointer was, say 0xfeff7352 and THREAD_SIZE was 0x00010000, they'd be doing 0xfeff7352 & 0xffff0000, you'd get 0xfeff0000 out of it. I suppose doing this would get you the very top of the thread's stack instance, where (I think) things like the thread ID are kept handy.

THREAD_SIZE may not be the system page size but is probably at least a power-of-two multiple of it.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 06-30-2011
Thanks for your explanation Corona.

I would like add few things about the context where the code is found. This acutaly found inside the marco current, which will hold the process descriptor being accessed by the process running on a particular CPU.

the process desccriptor pointer is stored in one end of the kernel stack which usually of 8192 bytes.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

2. Linux

Supermicro(dual core) server getting rebooted after "decompressing the kernel;booting the kernel" me

supermicro(dual core) server getting rebooted after "decompressing the kernel;booting the kernel" message comes. I tried giving acpi=off to the kernel command line but same problem.It shows everything ok and no problem with memory and processors and power supplies.Wt could be the reason? It has... (1 Reply)
Discussion started by: pankajd
1 Replies

3. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

4. Solaris

Compliation Error in solaris - macro "min" requires 2 arguments, but only 1 given

Hi, I am trying to compile our linux code base in solaris and came across the following issues. Am I suppose to do something special ? Can anyone help me to fix this issue. System : uname -a SunOS aspen 5.10 Generic_125100-08 sun4u sparc SUNW,Sun-Fire-280R The complier that I am using is... (0 Replies)
Discussion started by: learningkid
0 Replies
Login or Register to Ask a Question