• <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()的地址。 
            久久福利青草精品资源站| 久久WWW免费人成—看片| 久久精品免费全国观看国产| 久久国产精品免费一区| 国产精品中文久久久久久久| 无码国产69精品久久久久网站| 久久久久波多野结衣高潮| 伊人久久无码中文字幕| 久久精品aⅴ无码中文字字幕不卡| 一极黄色视频久久网站| 亚洲狠狠婷婷综合久久久久| AV色综合久久天堂AV色综合在| jizzjizz国产精品久久| 国产精品青草久久久久婷婷| 国产免费福利体检区久久| 亚洲欧美国产精品专区久久| 国产成人久久AV免费| 亚洲AⅤ优女AV综合久久久| 久久天天躁狠狠躁夜夜网站| 久久久久亚洲AV综合波多野结衣 | av无码久久久久不卡免费网站 | 久久国产影院| 久久久久亚洲av无码专区导航| 精品久久久久久久久午夜福利| 91精品观看91久久久久久| 久久久高清免费视频| 久久精品亚洲欧美日韩久久| 久久综合九色综合网站| 久久久精品久久久久影院| 国产精品久久久久久久午夜片| 香蕉久久av一区二区三区| 久久久久99精品成人片牛牛影视| 国产美女久久久| 久久久精品人妻一区二区三区四| 亚洲欧洲精品成人久久奇米网 | 久久精品国产精品亚洲人人| 日韩久久久久久中文人妻| 夜夜亚洲天天久久| 久久精品亚洲AV久久久无码 | 国产国产成人久久精品| 77777亚洲午夜久久多人|