Paging in PAE-mode – Virtual to Physical Address Translation

本文介绍了PAE(Physical Address Extension)模式下32位操作系统如何利用超过4GB的内存。通过增加页目录指针表(PDPT)和扩展表项大小到64位,实现了对更大物理内存的访问。

转自:http://blog.nandaka.io/paging-in-pae-mode-virtual-to-physical-address-translation/

Please go through the Paging in non-PAE mode before continuing to PAE mode. Also, the address translation explained here is in the context of 4K page size which is used by default in Windows.

PAE(Physical Address Extension) Mode was introduced in processor aiming to allow 32 bit OS to make use of more than 4GB memory.  Following are the changes in Paging Mechanism when we put the CPU in PAE mode.

  1. Each Table Entry(Page Directory Entry & Page Table Entry) is expanded to 64 bits. This is the reason a running process have access to the memory above 4GB. However, at a given time it can only access 4GB only.
  2. A new level of translation is added called ‘Page Directory Pointer Table(PDPT).
  3. Base physical address of each table entry is extended to 24 bits. Add this to 12 bits of byte index from virtual address, you get 36 bits to address the physical memory. Total addressable memory may be as big as 64GB with 36 bits.

 

CR3 CPU register is 4 byte in size on x86 machine and contains the physical address of PDPT so PDPT should be located below 4GB physical memory .

PAE Mode can be enabled by setting up the bit 5 of CR4 CPU register in x86. You can check the content of the CR4 CPU register via ‘r’ command of WinDbg.

0: kd> r cr4
cr4=000406f9  >>>00000000 00000100 00000110 11111001
Before you enable PAE Mode you need to make sure that all the tables( PDPT, PDT, PT) are setup. Load CR3 CPU register with PDPT and Enable Paging.

When PAE mode is enabled on processor, MMU divides the  virtual address in the following fields:

  1. Page Directory Pointer Table(PDPT) Pointer – 2 bits
  2. Page Directory Index – 9 bits (can address 2^9 = 512 entries)
  3. Page Table Index – 9 bits (can address 2^9 = 512 entries)
  4. Byte Index – 12 bits (can address 2^12(4096) entries. i.e. all the bytes in a 4K page)

Keep in mind that it is not the additional level of translation that helps addressing above 4GB. It is the 64 bit size of the Table Entry which allows us to address greater then 4GB of physical memory.

 

clip_image001


clip_image002

Image taken from the book Windows Internals by M Russinovich, D A Solomon, A Ionescu.

 

Fig above explains how the address translation works when PAE mode is enabled.

Here is the layout for the 64 bit PTE when PAE mode is enabled. Access fields of PDE and PTE are mostly similar. Table below explains the meaning and usage of bits. NX bit is available in 64 bit PTE only(PAE Mode on x86 or x64 bit machine) and WSI is available in 64 bit PTE in 64 bit system. I will discuss these in upcoming blogs.

clip_image003



`Uncaught (in promise) z-paging-complete-error` 是一种在使用 `z-paging` 组件时可能出现的错误,通常与分页加载数据的过程中发生异常有关。此错误提示表明某个 Promise 被拒绝(rejected),并且未进行适当的错误处理。 ### 错误原因分析 1. **分页请求失败**:当使用 `z-paging` 进行数据请求时,如果网络请求失败或返回的数据格式不符合预期,可能导致 Promise 被拒绝[^1]。 2. **未捕获的 Promise rejection**:JavaScript 中如果一个 Promise 被拒绝且没有通过 `.catch()` 或 `try/catch`(在 async/await 中)进行处理,则会抛出 `Uncaught (in promise)` 错误[^1]。 3. **插件配置问题**:`z-paging` 插件可能因为配置不当导致内部逻辑错误,例如回调函数未定义、接口地址错误等。 4. **自定义错误触发**:某些情况下,开发者可能会在分页逻辑中手动抛出错误,如使用 `Promise.reject(new Error('z-paging-complete-error'))` 来中断流程,但未正确捕获该错误[^1]。 ### 解决方案 #### 1. 添加 `.catch()` 处理 确保所有异步请求都包含 `.catch()` 方法以处理潜在的错误: ```javascript fetchData().catch(error => { console.error('分页数据获取失败:', error); }); ``` #### 2. 使用 `try/catch` 捕获 async/await 错误 如果使用的是 `async/await` 语法,请使用 `try/catch` 结构来捕获异常: ```javascript async function loadPage() { try { const data = await fetchData(); // 处理数据 } catch (error) { console.error('加载分页数据时出错:', error); } } ``` #### 3. 检查接口响应格式 确认后端返回的数据结构是否符合 `z-paging` 的预期要求,特别是字段名和状态码是否一致。例如: ```json { "data": [], "hasMore": false } ``` #### 4. 自定义错误处理 如果错误是由于业务逻辑主动抛出,可以在适当的位置拦截并处理这些错误,避免其传播到全局上下文。 #### 5. 调试与日志记录 启用详细的日志记录机制,帮助定位具体哪一步骤引发了错误。可以通过浏览器开发者工具查看完整的堆栈跟踪信息。 #### 6. 更新依赖库 检查 `z-paging` 及其相关依赖是否为最新版本,有时官方会修复已知的问题和 bug。 ### 示例代码:封装分页请求 以下是一个使用 `axios` 和 `z-paging` 的简单示例,展示如何安全地执行分页请求并处理错误: ```javascript import axios from 'axios'; const fetchPageData = async (pageNum) => { try { const response = await axios.get(`/api/data?page=${pageNum}`); return response.data; } catch (error) { console.error(`第 ${pageNum} 页请求失败`, error); throw new Error('z-paging-complete-error'); } }; // 在 z-paging 组件中调用 const pagingInstance = new ZPaging({ request: fetchPageData, container: '#paging-container' }); ``` ### 总结 `Uncaught (in promise) z-paging-complete-error` 主要源于未处理的 Promise 拒绝,常见于分页请求失败或插件配置不当。通过添加错误处理逻辑、验证接口响应、调试日志以及保持依赖更新,可以有效避免此类问题的发生。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值