news 2026/5/1 10:21:41

KiRequestDispatchInterrupt宏定义和nt!KiIpiServiceRoutine函数到hal!HalRequestSoftwareInterrupt

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
KiRequestDispatchInterrupt宏定义和nt!KiIpiServiceRoutine函数到hal!HalRequestSoftwareInterrupt

KiRequestDispatchInterrupt宏定义和nt!KiIpiServiceRoutine函数到hal!HalRequestSoftwareInterrupt


#define KiRequestDispatchInterrupt(Processor) \
if (KeGetCurrentProcessorNumber() != Processor) { \
KiIpiSend(AFFINITY_MASK(Processor), IPI_DPC); \
}


相应的:
#define KiRequestApcInterrupt(Processor) \
if (KeGetCurrentProcessorNumber() == Processor) { \
KiRequestSoftwareInterrupt(APC_LEVEL); \
} else { \
KiIpiSend(AFFINITY_MASK(Processor), IPI_APC); \
}
相应的:

VOID
KiIpiSend (
IN KAFFINITY TargetSet,
IN KIPI_REQUEST Request
)
{

#if !defined(NT_UP)

PKPRCB NextPrcb;
ULONG Processor;
KAFFINITY SummarySet;

ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL);

//
// Loop through the target set of processors and merge the request into
// the request summary of the target processors.
//
// N.B. It is guaranteed that there is at least one bit set in the target
// set.
//

ASSERT(TargetSet != 0);

SummarySet = TargetSet;
BitScanForward64(&Processor, SummarySet);
do {
NextPrcb = KiProcessorBlock[Processor];
InterlockedOr64((LONG64 volatile *)&NextPrcb->RequestSummary, Request);
SummarySet ^= AFFINITY_MASK(Processor);
} while (BitScanForward64(&Processor, SummarySet) != FALSE);

//
// Request interprocessor interrupts on the target set of processors.
//

HalRequestIpi(TargetSet);

#else

UNREFERENCED_PARAMETER(TargetSet);
UNREFERENCED_PARAMETER(Request);

#endif

return;
}


VOID
HalRequestIpi (
IN KAFFINITY Affinity
)
{

ULONG flags;
KAFFINITY Self;

//
// If the target set of processors is the complete set of processors,
// then use the broadcast capability of the APIC. Otherwise, send the
// IPI to the individual processors.
//

Self = KeGetCurrentPrcb()->SetMember;
if ((Affinity | Self) == HalpActiveProcessors) {
flags = HalpDisableInterrupts();
HalpStallWhileApicBusy();
if ((Affinity & Self) != 0) {
LOCAL_APIC(LU_INT_CMD_LOW) = APIC_BROADCAST_INCL;

} else {
LOCAL_APIC(LU_INT_CMD_LOW) = APIC_BROADCAST_EXCL;
}

HalpStallWhileApicBusy();
HalpRestoreInterrupts(flags);

} else {
HalpSendIpi(Affinity, APIC_IPI);
}

return;
}

VOID
FASTCALL
HalpSendIpi (
IN KAFFINITY Affinity,
IN ULONG Command
)
{
ULONG flags;

//
// Disable interrupts and call the appropriate routine.
//
// BUGBUG the compiler generates terrible code for this,
// most likely because of the inline _asm{} block generated
// by HalpDisableInterrupts().
//
// Ideally we could talk the x86 compiler team into giving
// us an intrinsic like the AMD64 compiler's __getcallerseflags()
//

flags = HalpDisableInterrupts();
HalpIpiRoutine(Affinity,Command);
HalpRestoreInterrupts(flags);
}

0: kd> g
Breakpoint 16 hit
eax=00000001 ebx=00000102 ecx=00000002 edx=00000000 esi=f7737120 edi=00000000
eip=804ee4f8 esp=f78e6ca0 ebp=f78e6cc4 iopl=0 nv up ei pl nz na po nc
cs=0008 ss=0010 ds=0023 es=0023 fs=0030 gs=0000 efl=00000202
hal!HalRequestSoftwareInterrupt:
804ee4f8 643a0d95000000 cmp cl,byte ptr fs:[95h] fs:0030:00000095=00
1: kd> kc 2
#
00 hal!HalRequestSoftwareInterrupt
01 nt!KiIpiServiceRoutine


cPublicProc _KiIpiServiceRoutine, 2

ifndef NT_UP

cPublicFpo 2, 3
push ebx ; save nonvolatile registers
push esi ;
push edi ;

xor ebx, ebx ; set exchange value
xor edi, edi
mov esi, PCR[PcPrcb] ; get current processor block address

xchg dword ptr [esi].PbRequestSummary, ebx
xchg dword ptr [esi].PbSignalDone, edi
;
; Check for freeze request or synchronous request.
;

test bl, IPI_FREEZE + IPI_SYNCH_REQUEST ; test for freeze or packet
jnz short isr50 ; if nz, freeze or synch request

;
; For RequestSummary's other then IPI_FREEZE set return to TRUE
;

mov bh, 1 ; set return value

;
; Check for Packet ready.
;
; If a packet is ready, then get the address of the requested function
; and call the function passing the address of the packet address as a
; parameter.
;

isr10: mov edx, edi ; copy request pack address
and edx, NOT 1 ; Clear point to point bit
jz short isr20 ; if z set, no packet ready
push [edx].PbCurrentPacket + 8 ; push parameters on stack
push [edx].PbCurrentPacket + 4 ;
push [edx].PbCurrentPacket + 0 ;
push edi ; push source processor block address
mov eax, [edx].PbWorkerRoutine ; get worker routine address
mov edx, [esp + 16 + 4*4] ; get current trap frame address
mov [esi].PbIpiFrame, edx ; save current trap frame address
call eax ; call worker routine
mov bh, 1 ; set return value

;
; Check for APC interrupt request.
;

isr20: test bl, IPI_APC ; check if APC interrupt requested
jz short isr30 ; if z, APC interrupt not requested

mov ecx, APC_LEVEL ; request APC interrupt
fstCall HalRequestSoftwareInterrupt ;

;
; Check for DPC interrupt request.
;

isr30: test bl, IPI_DPC ; check if DPC interrupt requested
jz short isr40 ; if z, DPC interrupt not requested

mov ecx, DISPATCH_LEVEL ; request DPC interrupt
fstCall HalRequestSoftwareInterrupt ;

isr40: mov al, bh ; return status
pop edi ; restore nonvolatile registers
pop esi ;
pop ebx ;

stdRET _KiIpiServiceRoutine

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/1 5:51:24

括号匹配问题

括号匹配是编程中经典的栈应用场景&#xff0c;核心要求是&#xff1a;给定一个仅包含括号&#xff08;如 ()、[]、{}、<> 等&#xff09;的字符串&#xff0c;判断括号的嵌套 / 排列是否满足「合法规则」&#xff0c;本质是验证左括号与右括号的对应关系。本文为该问题增…

作者头像 李华
网站建设 2026/5/1 6:44:17

还在为物流延迟抓狂?Open-AutoGLM同步优化策略大曝光

第一章&#xff1a;还在为物流延迟抓狂&#xff1f;Open-AutoGLM同步优化策略大曝光在现代供应链系统中&#xff0c;物流延迟已成为制约交付效率的核心瓶颈。传统调度算法难以应对动态环境变化&#xff0c;而基于大语言模型的决策系统又往往存在响应滞后问题。Open-AutoGLM 通过…

作者头像 李华
网站建设 2026/5/1 5:53:45

软件测试环境建设与运维管控体系

1 测试环境架构设计原则 1.1 环境分层策略 研发自测环境&#xff1a;部署最新构建版本&#xff0c;支持开发者快速验证功能 集成测试环境&#xff1a;模拟生产环境拓扑&#xff0c;保障模块间协调性 预发布环境&#xff1a;与生产环境保持硬件、网络、数据三位一体的一致性…

作者头像 李华
网站建设 2026/4/30 19:23:02

轮回修仙传 v1.0.11.27.1 免安装中文版下载及使用方法

轮回修仙传 v1.0.11.27.1 免安装中文版下载及使用方法 游戏下载地址 https://pan.quark.cn/s/5c8a8f81d9d0 游戏介绍 本作是一款轻度化快节奏的修仙游戏&#xff0c;没有自由开放的修仙大世界&#xff0c;更多是在一次又一次轮回的选择中&#xff0c;寻觅更多的仙缘奇遇&…

作者头像 李华
网站建设 2026/5/1 7:00:19

AI自动化新突破:Open-AutoGLM赋能外卖自动下单(全链路解析)

第一章&#xff1a;AI自动化新突破&#xff1a;Open-AutoGLM赋能外卖自动下单随着大语言模型与自动化技术的深度融合&#xff0c;AI在真实生活场景中的应用正迎来关键突破。Open-AutoGLM 作为新一代开源自动化智能体框架&#xff0c;首次实现了基于自然语言指令的端到端外卖下单…

作者头像 李华
网站建设 2026/5/1 6:58:09

【Open-AutoGLM物流同步实战指南】:掌握高效信息同步的5大核心技术

第一章&#xff1a;Open-AutoGLM物流信息同步的核心价值在现代物流系统中&#xff0c;信息同步的实时性与准确性直接影响供应链效率。Open-AutoGLM 作为一种基于生成式语言模型的自动化数据协同框架&#xff0c;能够实现跨平台、多节点的物流信息智能同步&#xff0c;显著提升数…

作者头像 李华