当前位置:主页   - 电脑 - 程序设计 - C/C++
xp下用户程序空间分配(9):还剩下什么?
来源:网络   作者:快乐虾   更新时间:2011-08-11
收藏此页】    【字号    】    【打印】    【关闭

  在去除前面的部分后,看看内存里还剩下什么:

  基址

  分配基址

  分配保护

  大小

  状态

  保护

  类型

  00010000

  00010000

  00000004

  PAGE_READWRITE

  00002000

  00001000

  MEM_COMMIT

  00000004

  PAGE_READWRITE

  00020000

  MEM_PRIVATE

  7ffdd000

  7ffdd000

  00000004

  PAGE_READWRITE

  00001000

  00001000

  MEM_COMMIT

  00000004

  PAGE_READWRITE

  00020000

  MEM_PRIVATE

  7ffde000

  7ffde000

  00000004

  PAGE_READWRITE

  00001000

  00001000

  MEM_COMMIT

  00000004

  PAGE_READWRITE

  00020000

  MEM_PRIVATE

  7ffdf000

  7ffdf000

  00000004

  PAGE_READWRITE

  00001000

  00001000

  MEM_COMMIT

  00000004

  PAGE_READWRITE

  00020000

  MEM_PRIVATE

  7ffe0000

  7ffe0000

  00000002

  PAGE_READONLY

  00001000

  00001000

  MEM_COMMIT

  00000002

  PAGE_READONLY

  00020000

  MEM_PRIVATE

  这些块都比较小,究竟是什么东西?

  1.1    环境块

  在毛德操的《windows内核情境分析》里提及一个叫环境块(好像是这个名字)的东西,且是在内存的最低的位置,咱看看它的内容:

0x00010000  3d 00 3a 00 3a 00 3d 00 3a 00 3a 00 5c 00 00 00 3d 00 45 00  =::=::.=E
0x00010014  3a 00 3d 00 45 00 3a 00 5c 00 50 00 72 00 6f 00 67 00 72 00  :=E:Progr
0x00010028  61 00 6d 00 20 00 46 00 69 00 6c 00 65 00 73 00 5c 00 4d 00  am FilesM
0x0001003C  69 00 63 00 72 00 6f 00 73 00 6f 00 66 00 74 00 20 00 56 00  icrosoft V
0x00010050  69 00 73 00 75 00 61 00 6c 00 20 00 53 00 74 00 75 00 64 00  isual Stud
0x00010064  69 00 6f 00 20 00 39 00 2e 00 30 00 5c 00 56 00 43 00 5c 00  io 9.0VC
0x00010078  76 00 63 00 70 00 61 00 63 00 6b 00 61 00 67 00 65 00 73 00  vcpackages
0x0001008C  00 00 3d 00 46 00 3a 00 3d 00 46 00 3a 00 5c 00 65 00 6d 00  .=F:=F:em
0x000100A0  62 00 65 00 64 00 5c 00 65 00 74 00 6f 00 6f 00 6c 00 73 00  bedetools
0x000100B4  00 00 41 00 4c 00 4c 00 55 00 53 00 45 00 52 00 53 00 50 00  .ALLUSERSP
0x000100C8  52 00 4f 00 46 00 49 00 4c 00 45 00 3d 00 45 00 3a 00 5c 00  ROFILE=E:
0x000100DC  44 00 6f 00 63 00 75 00 6d 00 65 00 6e 00 74 00 73 00 20 00  Documents
0x000100F0  61 00 6e 00 64 00 20 00 53 00 65 00 74 00 74 00 69 00 6e 00  and Settin
0x00010104  67 00 73 00 5c 00 41 00 6c 00 6c 00 20 00 55 00 73 00 65 00  gsAll Use
0x00010118  72 00 73 00 00 00 41 00 50 00 50 00 44 00 41 00 54 00 41 00  rs.APPDATA
0x0001012C  3d 00 45 00 3a 00 5c 00 44 00 6f 00 63 00 75 00 6d 00 65 00  =E:Docume
0x00010140  6e 00 74 00 73 00 20 00 61 00 6e 00 64 00 20 00 53 00 65 00  nts and Se
0x00010154  74 00 74 00 69 00 6e 00 67 00 73 00 5c 00 00 5f d1 53 05 80  ttings开发者
0x00010168  5c 00 41 00 70 00 70 00 6c 00 69 00 63 00 61 00 74 00 69 00  Applicati
0x0001017C  6f 00 6e 00 20 00 44 00 61 00 74 00 61 00 00 00 42 00 58 00  on Data.BX
0x00010190  53 00 48 00 41 00 52 00 45 00 3d 00 2e 00 00 00 43 00 44 00  SHARE=..CD
0x000101A4  53 00 52 00 4f 00 4f 00 54 00 3d 00 65 00 3a 00 5c 00 65 00  SROOT=e:e

  都是些unicode文本,把它的内容和系统环境变量进行比较,差别还是比较明显的,但是系统环境变量和用户环境变量在这块内存区里都可以找到相应的定义。尝试在用户环境变量里添加一个定义,再重新运行程序,果然在这块区域里找到了这个新的环境变量。

  1.2    NT_TIB

  每个线程都有一块地方记录线程的基本信息,在程序里有三个线程,想必应该有三块空间,读出fs的内容,可以发现主线程的这个信息存放在0x7ffd f000,看下它的原始数据:

0x7FFDF000  a8 ff 12 00 00 00 13 00 00 10 0e 00 00 00 00 00  ................
0x7FFDF010  00 1e 00 00 00 00 00 00 00 f0 fd 7f 00 00 00 00  ................
0x7FFDF020  30 0e 00 00 d4 07 00 00 00 00 00 00 00 00 00 00  0...............
0x7FFDF030  00 d0 fd 7f b7 00 00 00 00 00 00 00 00 00 00 00  ................
0x7FFDF040  00 b3 6e e3 00 00 00 00 00 00 00 00 00 00 00 00  ..n.............

  将之转换为NT_TIB结构体:

  ExceptionList

  0x0012ffa8

  _EXCEPTION_REGISTRATION_RECORD *

  StackBase

  0x00130000

  void *

  StackLimit

  0x000e1000

  void *

  SubSystemTib

  0x00000000

  void *

  FiberData

  0x00001e00

  void *

  Version

  0x00000000

  unsigned long

  ArbitraryUserPointer

  0x7ffdf000

  void *

  使用同样的方法,可以得到另一个线程的NT_TIB存放在0x7ffd e0000。

0x7FFDE000  dc ff cd 00 00 00 ce 00 00 a0 cd 00 00 00 00 00  ................
0x7FFDE010  00 1e 00 00 00 00 00 00 00 e0 fd 7f 00 00 00 00  ................
0x7FFDE020  30 0e 00 00 c4 09 00 00 00 00 00 00 00 00 00 00  0...............
0x7FFDE030  00 d0 fd 7f 00 00 00 00 00 00 00 00 00 00 00 00  ................
0x7FFDE040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

  将之转换为NT_TIB结构体:

  ExceptionList

  0x00cdffdc {Next=0xffffffff Handler=0x7c839ac0 }

  _EXCEPTION_REGISTRATION_RECORD *

  StackBase

  0x00ce0000

  void *

  StackLimit

  0x00cda000

  void *

  SubSystemTib

  0x00000000

  void *

  FiberData

  0x00001e00

  void *

  Version

  0x00001e00

  unsigned long

  ArbitraryUserPointer

  0x00000000

  void *

  猜想应该是每建一个线程,其空间将往下增长一块。

  1.3    其它

  还有0x7ffe0000,这一块用途不明,做个记号。

编缉推荐阅读以下文章

  • xp下用户程序空间分配(8):MEM_MAPPED
  • xp下用户程序空间分配(7):Heap
  • xp下用户程序空间分配(6):加载用户DLL
  • xp下用户程序空3分配(5):加载系统DLL
  • xp下用户程序空间分配(4):加载主程序
  • xp下用户程序空间分配(3):加载文件
  • xp下用户程序空间分配(2):栈
  • xp下用户程序空间分配(1):大致框架
其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明