news 2026/6/10 13:40:34

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/6/9 8:18:47

直接上干货。这次咱们聊聊怎么用Simulink搞个能打的单相逆变器双环控制模型。重点说几个实操细节,保准你照着做就能出波形

基于双环PI控制器的单相逆变器闭环控制模型,采用电压电流双闭环。 输出波形良好,输出跟随给定220v交流输出。 matlab/simulink环境。先说整体架构,电压外环负责稳幅值,电流内环管动态响应。这个结构有点像骑自行车——电压环把控方…

作者头像 李华
网站建设 2026/6/9 21:22:40

Caddy服务器入门自动HTTPS的现代Web服务器

前言 Caddy是一款用Go编写的现代Web服务器,最大特点是自动HTTPS——只需配置域名,Caddy会自动申请和续期Let’s Encrypt证书。本文将带你快速上手Caddy。 一、Caddy vs Nginx 特性CaddyNginx配置语法简洁易读相对复杂自动HTTPS✅ 开箱即用❌ 需certbo…

作者头像 李华
网站建设 2026/6/10 12:31:33

ELK日志分析平台从零搭建到生产实践

前言 在分布式系统中,日志是排查问题的重要依据。当服务器数量增多时,传统的登录服务器查看日志方式效率低下。ELK(Elasticsearch Logstash Kibana)是目前最流行的日志集中管理方案。 一、ELK Stack介绍 1.1 组件说明 日志源 →…

作者头像 李华
网站建设 2026/6/7 23:28:09

SSM校外实习管理平台6tu82(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面

系统程序文件列表 系统项目功能:学生,教师,企业实习,实习申请,实习汇报,实习报告,实习成绩 SSM校外实习管理平台开题报告 一、课题研究背景与意义 (一)研究背景 校外实习是连接理论教学与社会实践的关键环节,是提升学生实践能力…

作者头像 李华
网站建设 2026/6/9 21:08:18

巨椰 云手机 云游戏稳定运行

云手机与云游戏高度依赖服务器的计算能力,对于云游戏而言,GPU 的图形处理能力直接决定游戏画面质量,云手机若用于运行游戏,同样需要 GPU 提供图形加速,通过 GPU 虚拟化技术,合理分配 GPU 资源给不同云手机实…

作者头像 李华