• <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()的地址。 
            伊人久久大香线蕉综合热线| 亚洲va中文字幕无码久久| 中文字幕人妻色偷偷久久| 久久久久久亚洲AV无码专区| AAA级久久久精品无码片| 久久久国产精华液| 中文字幕乱码人妻无码久久| 99久久无码一区人妻a黑| 午夜精品久久影院蜜桃| 丁香狠狠色婷婷久久综合| 久久综合色老色| 精品久久久久久久久午夜福利| 久久久久久国产精品无码下载| 久久久无码人妻精品无码| 色偷偷88欧美精品久久久| 777久久精品一区二区三区无码| 久久人人爽人人爽人人爽| 中文精品久久久久人妻| 久久精品国产99国产精品| 国内精品人妻无码久久久影院导航| 欧美黑人激情性久久| 99热成人精品热久久669| 狠狠色丁香久久婷婷综合蜜芽五月| 亚洲中文字幕无码久久2017| 免费国产99久久久香蕉| 久久777国产线看观看精品| 无码人妻精品一区二区三区久久久| 一本大道久久a久久精品综合| 精品国产乱码久久久久久呢| 亚洲午夜精品久久久久久浪潮| 久久精品中文字幕久久| 久久久久久亚洲Av无码精品专口 | 日本人妻丰满熟妇久久久久久| 伊人久久大香线蕉AV一区二区| 久久久久国产精品三级网| 品成人欧美大片久久国产欧美...| 国产精品美女久久久| 狠狠88综合久久久久综合网| 99久久精品国内| 国产精品VIDEOSSEX久久发布| 久久成人影院精品777|