• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 200, comments - 8, trackbacks - 0, articles - 0
            Linux通過slab分配器動態分配task_struct結構,該結構定義在了<include/linux/sched.h>文件中,進程描述符中包含一個具體進程的所有信息,各個進程的task_struct存放在它們內核棧的尾端。在棧底(對于向下增長的棧)或棧頂(對于向上增長的棧)創建一個新的結構struct thread_info。利用這個新的機構來迅速的找到task_struct的位置。
              下面是kernel2.6.32.10里task_struct的定義(對于x86類型的CPU來說文件位于:arch/x86/include/asm /include/asm/thread_info.h):
            1. struct thread_info {
            2.         struct task_struct        *task;                /* main task structure */
            3.         struct exec_domain        *exec_domain;        /* execution domain */
            4.         __u32                        flags;                /* low level flags */
            5.         __u32                        status;                /* thread synchronous flags */
            6.         __u32                        cpu;                /* current CPU */
            7.         int                        preempt_count;        /* 0 => preemptable, <0 => BUG */
            8.         mm_segment_t                addr_limit;
            9.         struct restart_block    restart_block;
            10.         void __user                *sysenter_return;
            11. #ifdef CONFIG_X86_32
            12.         unsigned long           previous_esp;   /* ESP of the previous stack in   case of nested (IRQ) stacks*/
            13.         __u8                        supervisor_stack[0];
            14. #endif
            15.         int                        uaccess_err;
            16. };
            其中的task的值就為task_struct的位置。
            kernel利用current宏尋找task_struct的位置,假設棧的大小為8k(13個二進制位),我們可以將進程棧的地址的后13位屏蔽掉,這樣得到的剛好就是進程棧的起始地址,而thread_info剛好就是位于進程棧的底部,所以進程棧的起始地址就是struct thread_info的地址,得到了thread_info的地址,我們就很容易找到task_struct的地址了。
            匯編實現過程為
            movl  %-8192 ,%eax
            andl   %esp ,%eax
            寄存器esp存放進程棧的當前地址,eax最后存放的就是進程棧的起始地址。current使用current_thread_info來實現這個過程。
            kernel源碼(對于x86類型的CPU來說文件位于arch/x86/include/asm //include/asm/thread_info.h)
            1. /* how to get the current stack pointer from C */
            2. register unsigned long current_stack_pointer asm("esp") __used;

            3. /* how to get the thread information struct from C */
            4. static inline struct thread_info *current_thread_info(void)
            5. {
            6.         return (struct thread_info *)
            7.                 (current_stack_pointer & ~(THREAD_SIZE - 1));
            8. };
            其中current_stack_pointer為進程棧的當前地址,THREAD_SIZE為進程棧的大小。
            所以current_thread_info()->task即為task_struct()的地址。 
            国产精品伊人久久伊人电影| 国产成人精品免费久久久久| 久久精品国产欧美日韩| 午夜视频久久久久一区| 精品蜜臀久久久久99网站| 久久99精品国产麻豆蜜芽| 亚洲国产精品无码成人片久久| 精品久久久久中文字幕日本 | 久久久久国产精品嫩草影院| 久久亚洲精品中文字幕| 久久国产视屏| 国产成人久久AV免费| 久久午夜福利无码1000合集| 久久综合丝袜日本网| 国产偷久久久精品专区| 国产成人99久久亚洲综合精品| 久久精品人人做人人爽电影| 国产精品欧美亚洲韩国日本久久| 久久婷婷激情综合色综合俺也去| 久久精品中文字幕有码| 青青青国产成人久久111网站| 亚洲精品午夜国产VA久久成人| 久久伊人精品青青草原日本| 国产精品gz久久久| 99久久精品免费看国产一区二区三区| 久久成人国产精品免费软件| 久久天天躁狠狠躁夜夜2020| 久久国产精品国语对白| 99久久99久久精品国产| 伊人色综合久久天天| 国产日产久久高清欧美一区| 国产99精品久久| 久久久久综合网久久| 青青青国产成人久久111网站| 久久精品国产只有精品2020| 久久久久久亚洲精品成人| 亚洲午夜久久久久妓女影院| 亚洲精品高清国产一线久久 | 国内精品伊人久久久久网站| 久久亚洲国产精品一区二区| 国产99久久久国产精免费|