gpt4 book ai didi

windows - 为什么我们可以在 DISPATCH LEVEL 或更高级别从非分页池访问内存

转载 作者:可可西里 更新时间:2023-11-01 11:13:04 24 4
gpt4 key购买 nike

据我所知,如果 IRQL 级别是分派(dispatch)的,那么您可以从非分页池访问内存。如果我们将尝试从分页池访问内存。只是想知道为什么?

最佳答案

"why we can access memory from non paged pool at or above DISPATCH LEVEL"是一个陈述,问题是为什么我们不能从分页池 IRQL >= DISPATCH_LEVEL 访问内存?

嗯...

"Any routine that is running at greater than IRQL APC_LEVEL can neither allocate memory from paged pool nor access memory in paged pool safely. If a routine running at IRQL greater than APC_LEVEL causes a page fault, it is a fatal error."

-- http://msdn.microsoft.com/en-us/library/windows/hardware/ff554368(v=vs.85).aspx

这是为什么:

假设您的驱动程序正在为一个中断服务,并且在此期间,它持有一个自旋锁。现在,您想要访问驻留在页面缓冲池中的某些数据结构,但不幸的是,该数据位于已被内存管理器调出的页面上。

现在,您的驱动程序必须等到内存管理器调入您的数据。你在阻塞/等待/ sleep ,实际上你的司机是。

现在,另一个中断发生了,但由于您仍在等待数据调入,您认为现在会发生什么?

知道这一点,

" Holding a spin lock for an unnecessarily long duration can hurt system-wide performance."

当您的驱动程序等待某事发生的时间变长时,您的内核将卡住。

此外,

"Note that a thread may not block while holding a spinlock, because that could cause deadlock. Further, preemption is disabled on a given processor while a spinlock is held."

-- https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.html

无论如何,进一步阅读:

"Driver code that runs at IRQL > PASSIVE_LEVEL should execute as quickly as possible. The higher the IRQL at which a routine runs, the more important it is for good overall performance to tune that routine to execute as quickly as possible. For example, any driver that calls KeRaiseIrql should make the reciprocal call to KeLowerIrql as soon as it can."

-- http://msdn.microsoft.com/en-us/library/windows/hardware/ff554368(v=vs.85).aspx

页面错误是一种需要由内存管理器快速处理的异常。当您的驱动程序持有自旋锁并劫持该处理器时,该处理器现在就像死了一样好。

MSDN 说:

"While a driver routine holds a spin lock, it cannot cause a hardware exception or raise a software exception without bringing down the system. In other words, a driver's ISR and any SynchCritSection routine that the driver supplies in a call to KeSynchronizeExecution must not cause a fault or trap, such as a page fault or an arithmetic exception, and cannot raise a software exception. A routine that calls KeAcquireSpinLock or KeAcquireInStackQueuedSpinLock also cannot cause a hardware exception or raise a software exception until it has released its executive spin lock and is no longer running at IRQL = DISPATCH_LEVEL."

-- http://msdn.microsoft.com/en-us/library/windows/hardware/ff559854(v=vs.85).aspx

所有这些都回答了将会发生什么,或者可能发生什么。至于回答为什么我们不能在 DISPATCH_LEVEL 以上或 DISPATCH_LEVEL 使用分页内存:

  1. 它在大多数情况下会导致死锁,在内核世界中就是内核崩溃。
  2. 它会在内核中引起延迟,这是不好的。
  3. 引用 1,这很重要。

我已尝试尽可能多地获取相关信息,如果您仍然不相信,请尝试阅读自旋锁、可重入函数、中断处理、分页。尝试阅读 Linux、Windows 和 Apple 操作系统的内核。他们都说同样的话,但细节不同。

关于windows - 为什么我们可以在 DISPATCH LEVEL 或更高级别从非分页池访问内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18764211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com