免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2205 | 回复: 4
打印 上一主题 下一主题

关于进程的thread_info [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-18 19:56 |只看该作者 |倒序浏览
ULK 第三章中:(为了不被翻译误解,特找了原文)

For each
process, Linux packs two different data structures in a single per-process memory area: a small data
structure linked to the process descriptor, namely the thread_info structure, and the Kernel Mode
process stack. The length of this memory area is usually 8,192 bytes (two page frames). For reasons
of efficiency the kernel stores the 8-KB memory area in two consecutive page frames with the first
page frame aligned to a multiple of 213;

第一次看的时候没觉得这里有什么问题,后来觉得这里还是不太理解。
问题如下:
1.这里说的内核堆栈和thread_info结构放在连续的两个页框中,那么即是处在内核态专用的存储区域了。为什么例子上给出
   的地址是0x015fa000~0x015fbfff,难道是物理地址,不是线性地址?

2.内存寻址一章好像有说:进程的页目录项前3/4是用户态空间,后1/4的页目录项所有进程都应该相同,那么内核态的1G空
  间应该是所有进程共享的。 但是这里又说进程自己的内核栈和thread_info相邻,那就是每个进程一个内核栈。

  究竟每个进程(非内核线程)是否都有自己独立的内核栈,内核数据段?

  这段话如下:

  The content of the first entries of the Page Global Directory that map linear addresses lower than
  0xc0000000 (the first 768 entries with PAE disabled, or the first 3 entries with PAE enabled) depends
  on the specific process. Conversely, the remaining entries should be the same for all processes and
  equal to the corresponding entries of the master kernel Page Global Directory (see the following
section)

3.内核线程一直工作在内核态,都有自己独立的堆栈,数据段吗?

4.我们自己写的中断服务程序,以及设备驱动程序又是工作在用户态还是内核态呢?

[ 本帖最后由 wliang511 于 2009-12-18 20:58 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-12-18 20:47 |只看该作者
有点误解了,所谓代码段应该没有独立不独立一说,只不过是一个只读的IP指针,指哪里运行哪里罢了。我吧代码段的问题删掉了

论坛徽章:
0
3 [报告]
发表于 2009-12-19 01:49 |只看该作者
1,你说的那个地址在原书中哪里?怎么写的?
看上去应该是物理地址.

2. 所有进程共享1G 内核空间 和每个进程一个内核栈并不矛盾. 在某一个时刻,只有一个当前进程在执行. 其他的都在休息或等待. 在这个时刻,这个运行的进程有自己的内核栈. 当KERNEL切换到另外一个进程的时候,内核栈也会发生切换.

3. 栈和数据段是完全不同的2个观念. 数据段是静态的,栈是动态的. 我觉得每个内核线程应该有自己的内核栈 .但是不确定.

4.一般都是在内核态. 不过LINUX支持用户态的驱动,但是他们有限制.

论坛徽章:
0
4 [报告]
发表于 2009-12-19 12:51 |只看该作者
原帖由 accessory 于 2009-12-19 01:49 发表
1,你说的那个地址在原书中哪里?怎么写的?
看上去应该是物理地址.

2. 所有进程共享1G 内核空间 和每个进程一个内核栈并不矛盾. 在某一个时刻,只有一个当前进程在执行. 其他的都在休息或等待. 在这个时刻,这个 ...



1.那个地址在3.2.2.1节
2.是不是这样理解的?
  页目录中属于用户态空间的映射方式是不固定的,所以不同进程中的同一个线性地址(页目录前3/4目录项所覆盖区域)指向的物理内存地址不一定相同。
  但是页目录中属于内核态空间的映射方式是固定的,不同进程的同一个线性地址(页目录最后1/4目录项所覆盖区域)指向的必然是相同的物理地址,
  所以内核态的1G空间是共享的。
  
   这个内核态堆栈的SP是不是这个结构体中的esp0,因为有自己内核态堆栈的话,我觉得从内核态切换到用户态的时候必须保存相应的SP:


  1.   struct thread_struct {
  2. /* cached TLS descriptors. */
  3.         struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
  4.         unsigned long        esp0;
  5.         unsigned long        sysenter_cs;
  6.         unsigned long        eip;
  7.         unsigned long        esp;
  8.         unsigned long        fs;
  9.         unsigned long        gs;
  10. /* Hardware debugging registers */
  11.         unsigned long        debugreg[8];  /* %%db0-7 debug registers */
  12. /* fault info */
  13.         unsigned long        cr2, trap_no, error_code;
  14. /* floating point info */
  15.         union i387_union        i387;
  16. /* virtual 86 mode info */
  17.         struct vm86_struct __user * vm86_info;
  18.         unsigned long                screen_bitmap;
  19.         unsigned long                v86flags, v86mask, saved_esp0;
  20.         unsigned int                saved_fs, saved_gs;
  21. /* IO permissions */
  22.         unsigned long        *io_bitmap_ptr;
  23. /* max allowed port in the bitmap, in bytes: */
  24.         unsigned long        io_bitmap_max;
  25. };
复制代码

[ 本帖最后由 wliang511 于 2009-12-19 13:02 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-12-19 13:22 |只看该作者
关于2。 我觉得你说得对。
至于其中ESP0是否指向内核栈就不太清楚了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP