CoreCLR系列随笔 之ClrJit项目之alloc.cpp文件分析(1)
2017-06-03 22:13
429 查看
首先声明,自己对CLR了解得不多,只是个人爱好,可能有错误,请指出,文件源码如下(可能不是最新的)
View Code
下面的代码就是做一些基本的赋值和检查。
下面就是把新的page追加到list的后端。
最后重新设置一下next和last指针,总之这个是个公共方法,只是nraInit里面只用到了为0的情况: pThis->nraAllocNewPage(0);
回到init函数然后执行如下,结束nraInit方法
写完了,知道写得不太好,请指出错误,轻喷。晚安。
inline LPVOID ClrAllocInProcessHeap(DWORD dwFlags, S_SIZE_T dwBytes) { STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; if (dwBytes.IsOverflow()) { return NULL; } #ifndef SELF_NO_HOST return __ClrAllocInProcessHeap(dwFlags, dwBytes.Value()); #else #undef HeapAlloc #undef GetProcessHeap static HANDLE ProcessHeap = NULL; if (ProcessHeap == NULL) ProcessHeap = GetProcessHeap(); return ::HeapAlloc(ProcessHeap,dwFlags,dwBytes.Value()); #define HeapAlloc(hHeap, dwFlags, dwBytes) Dont_Use_HeapAlloc(hHeap, dwFlags, dwBytes) #define GetProcessHeap() Dont_Use_GetProcessHeap() #endif }
View Code
LPVOID nraVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) { #if defined(DEBUG) assert(lpAddress == 0 && flAllocationType == MEM_COMMIT && flProtect == PAGE_READWRITE); if (nraDirectAlloc()) { #undef GetProcessHeap #undef HeapAlloc return ::HeapAlloc(GetProcessHeap(), 0, dwSize); } else return DbgNew(dwSize); #else return nraMemoryManager->ClrVirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect); #endif }
下面的代码就是做一些基本的赋值和检查。
if (!newPage) NOMEM(); #ifdef DEBUG newPage->nrpSelfPtr = newPage; #endif
下面就是把新的page追加到list的后端。
/* Append the new page to the end of the list */ newPage->nrpNextPage = 0; newPage->nrpPageSize = sizPage; newPage->nrpPrevPage = nraPageLast; newPage->nrpUsedSize = 0; // nrpUsedSize is meaningless until a new page is allocated. // Instead of letting it contain garbage (so to confuse us), // set it to zero. if (nraPageLast) nraPageLast->nrpNextPage = newPage; else nraPageList = newPage; nraPageLast = newPage;
最后重新设置一下next和last指针,总之这个是个公共方法,只是nraInit里面只用到了为0的情况: pThis->nraAllocNewPage(0);
/* Set up the 'next' and 'last' pointers */ nraFreeNext = newPage->nrpContents + sz; nraFreeLast = newPage->nrpPageSize + (BYTE *)newPage; assert(nraFreeNext <= nraFreeLast); return newPage->nrpContents;
回到init函数然后执行如下,结束nraInit方法
impJitErrorTrap() // ERROR TRAP: The following block handles errors { result = true; } endErrorTrap() // ERROR TRAP: End
写完了,知道写得不太好,请指出错误,轻喷。晚安。
相关文章推荐
- 鸡啄米vc++2010系列2(项目文件分析)
- 鸡啄米vc++2010系列2(项目文件分析)
- vs2005集成qt后产生的qt项目文件结构分析
- 关于编码、开发、分析、设计、项目管理的一些随笔
- ffmpeg分析系列之五(打开输入的文件)
- 开源项目案例分析-随笔主题说明
- Android之项目文件结构分析
- 语法分析表产生器的代码之三:自定义类的实现函数文件implement_syntax.cpp
- MTD系列 - android平台上linux启动时init进程解析init.rc文件分析
- keil MDK启动文件分析---基于LPC2100系列(其实都是相通的)
- LIB/PE/COFF文件分析开源项目
- vs2010无法打开项目文件的原因分析及解决方法
- 统计一个项目的代码行数,只统计cpp文件
- MTD系列 - android平台上linux启动时init进程解析init.rc文件分析
- keil MDK启动文件分析---基于LPC2100系列(其实都是相通的)
- IEP项目对Word文件的操作分析
- OllyDBG分析报告系列(7)---文件加载调试原理
- 如何由.c或.cpp文件建立 与Qt相关的不同IDE平台的项目文件(.pro 和 .vcproj)和 中间文件夹 放置Generated Files
- 我的WCF项目系列之三----WCF配置文件和返回值
- PE文件格式分析系列(文章2)----一个PE文件rdata段的分析(Win32工程Release版)(一)