Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8412559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:42:04+00:00 2026-06-10T00:42:04+00:00

Right now I’m reading the book "Linux Kernel Development 3d Edition" by Robert Love.

  • 0

Right now I’m reading the book "Linux Kernel Development 3d Edition" by Robert Love. There he write about the thread_info struct which contains the pointer to task_struct struct and, as I understood, located at the bottom or at the top of kernel stack of process (depends on architecture). I wasn’t familiar with Linux kernel API until recently and I wasn’t known of current() method existence. There is an excerpt from the book related to how current() method actually works:

On x86, current is calculated by masking out the 13 least-significant bits of the stack
pointer to obtain the thread_info structure.This is done by the
current_thread_info() function.The assembly is shown here:
movl $-8192, %eax
andl %esp, %eax
This assumes that the stack size is 8KB.When 4KB stacks are enabled, 4096 is used in
lieu of 8192.

My questions are:

  1. As far as I know if we have a decimal value represented as a set of bits, then there is only one least-significant bit in the set, isn’t it?
  2. What is the magical number 13?

For thous who will read this topic, the questions I have voiced can lead to conclusion that the author don’t understand properly the process of memory allocation and administration. Ok, that’s may be right due to the fact that in my mind I can represent the memory allocated for the stack as the ribbon full of bits (or bytes). All of this bytes accessible by a specific memory address represented as some decimal value. The origin of the stack is the lowest memory address and the fin of the stack is the highest value of memory address. But HOW, HOW can we get the pointer to the thread_info struct located at the, say, end of the stack only by masking out 13 least-significant bits of ARBITRARY located stack pointer (If I understood correctly, we masking out bits of the stack pointer ADDRESS represented as decimal value).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:42:06+00:00Added an answer on June 10, 2026 at 12:42 am

    The kernel stack contains a special struct at the top — thread_info:

     26 struct thread_info {
     27         struct task_struct      *task;          /* main task structure */
     28         struct exec_domain      *exec_domain;   /* execution domain */
     29         __u32                   flags;          /* low level flags */
     30         __u32                   status;         /* thread synchronous flags */
     31         __u32                   cpu;            /* current CPU */
     32         int                     preempt_count;  /* 0 => preemptable,
     33                                                    <0 => BUG */
     34         mm_segment_t            addr_limit;
     35         struct restart_block    restart_block;
     36         void __user             *sysenter_return;
     37 #ifdef CONFIG_X86_32
     38         unsigned long           previous_esp;   /* ESP of the previous stack in
     39                                                    case of nested (IRQ) stacks
     40                                                 */
     41         __u8                    supervisor_stack[0];
     42 #endif
     43         unsigned int            sig_on_uaccess_error:1;
     44         unsigned int            uaccess_err:1;  /* uaccess failed */
     45 };
    

    So, to get the task_struct you’ll need to get a thread_info pointer with GET_THREAD_INFO from the ASM-code:

    183 /* how to get the thread information struct from ASM */
    184 #define GET_THREAD_INFO(reg)     \
    185         movl $-THREAD_SIZE, reg; \
    186         andl %esp, reg
    

    … or with current_thread_info from the C-code:

    174 /* how to get the thread information struct from C */
    175 static inline struct thread_info *current_thread_info(void)
    176 {
    177         return (struct thread_info *)
    178                 (current_stack_pointer & ~(THREAD_SIZE - 1));
    179 }
    

    Note that THREAD_SIZE defined as (PAGE_SIZE << THREAD_SIZE_ORDER) and THREAD_SIZE_ORDER equals 1 for both x86_32 and x86_64 so THREAD_SIZE results to 8192 (2^13 or 1<<13).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I'm making an extremely simple website- about 5 pages. Question is if
Right now, I am closing all the opened windows. I want to write a
Right now i am using the ArrayList for My ListView and there is a
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
Right now I have a script that will get the last five files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.