news 2026/7/17 1:34:39

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/7/15 22:18:25

揭秘Open-AutoGLM如何实现毫秒级快递轨迹更新:技术架构全解析

第一章:揭秘Open-AutoGLM快递轨迹追踪的核心价值在现代物流体系中,快递轨迹的实时性与准确性直接影响用户体验与运营效率。Open-AutoGLM作为一种基于自动化大语言模型(AutoGLM)的开放架构,为快递轨迹追踪提供了智能化的…

作者头像 李华
网站建设 2026/7/15 22:18:24

换个角度看境外支付系统:警惕金融风险之安全测试实践

支付系统,这个名词相信生活在当下社会的大家应该都不在陌生了吧,他时时刻刻充斥在我们的日常生活中,哪里有交易发生,哪里就有它的身影。 其实直白的来说,支付系统是扮演着连接消费者、商家、银行和其他金融机构之间的…

作者头像 李华
网站建设 2026/7/16 2:50:58

Home-Assistant智能家居平台搭建与远程控制

前言 Home Assistant是目前最强大的开源智能家居平台,支持上千种设备和服务的集成。本文将介绍如何搭建Home Assistant并实现远程控制。 一、为什么选择Home Assistant 1.1 对比其他方案 特性Home Assistant米家HomeKit开源✅❌❌设备支持2000仅小米生态较少自动…

作者头像 李华
网站建设 2026/7/15 2:15:41

盲盒小程序定制案例|轻松打造专属盲盒乐园

盲盒小程序定制案例|轻松打造专属盲盒乐园 盲盒小程序全新页面、功能分享 传统与创新结合的新鲜玩法,玩家可以获得新鲜体验感。 核心功能玩法:一番赏、无限赏、登天阶.... 各种惊喜有趣的功能体验,带来视觉体验感的页面&#xff0…

作者头像 李华
网站建设 2026/7/16 16:25:03

【Open-AutoGLM快递轨迹追踪实战】:掌握AI驱动物流监控的5大核心技术

第一章:Open-AutoGLM快递轨迹追踪实战导论在现代物流系统中,实时、精准的快递轨迹追踪已成为提升用户体验与运营效率的核心能力。Open-AutoGLM 作为一款基于大语言模型与自动化推理引擎的开源框架,能够通过自然语言理解与结构化数据解析&…

作者头像 李华