based on this code its block all processors
i want modify it so its block all processors but keep processor 0 how i can do it ?
static u32 locked;
static u32 inp_dpcs;
static u32 out_dpcs;
static u32 dpc_refs;
static void global_lock_proc(PKDPC dpc, PKDPC *cpu_dpc, void *arg1, void *arg2)
{
_disable();
lock_dec(&inp_dpcs);
while (locked != 0)
KeStallExecutionProcessor(1);
_enable();
if (lock_dec(&dpc_refs) == 0)
ExFreePool(cpu_dpc);
lock_dec(&out_dpcs);
}
KIRQL global_lock()
{
KIRQL old_irql;
PKDPC cpu_dpc;
CCHAR n_cpu, i;
n_cpu = KeNumberProcessors;
cpu_dpc = ExAllocatePool(NonPagedPoolMustSucceed, sizeof(KDPC) * n_cpu);
old_irql = KeRaiseIrqlToDpcLevel();
locked = 1;
inp_dpcs = n_cpu - 1;
out_dpcs = inp_dpcs;
dpc_refs = inp_dpcs;
for (i = 0; i < KeNumberProcessors; i++)
if (i != KeGetCurrentProcessorNumber()) {
KeInitializeDpc(&cpu_dpc[i], global_lock_proc, cpu_dpc);
KeSetTargetProcessorDpc(&cpu_dpc[i], i);
KeSetImportanceDpc(&cpu_dpc[i], HighImportance);
KeInsertQueueDpc(&cpu_dpc[i], NULL, NULL);
}
while (inp_dpcs != 0)
KeStallExecutionProcessor(1);
_disable();
return old_irql;
}
void global_unlock(KIRQL old_irql)
{
locked = 0;
while (out_dpcs != 0)
KeStallExecutionProcessor(1);
_enable();
KeLowerIrql(old_irql);
}
will this work ?
{
KIRQL old_irql;
PKDPC cpu_dpc;
CCHAR n_cpu, i;
// Get the original IRQL
old_irql = KeGetCurrentIrql();
// This function should only be run on processor 0
if (KeGetCurrentProcessorNumber() != 0) {
// Return original IRQL if not on processor 0
return old_irql;
}
n_cpu = KeNumberProcessors;
cpu_dpc = (PKDPC)ExAllocatePool(NonPagedPoolMustSucceed, sizeof(KDPC) * n_cpu);
old_irql = KeRaiseIrqlToDpcLevel();
locked = 1;
inp_dpcs = n_cpu - 1;
out_dpcs = inp_dpcs;
dpc_refs = inp_dpcs;
for (i = 0; i < KeNumberProcessors; i++)
if (i != KeGetCurrentProcessorNumber()) {
KeInitializeDpc(&cpu_dpc[i], (PKDEFERRED_ROUTINE)global_lock_proc, cpu_dpc);
KeSetTargetProcessorDpc(&cpu_dpc[i], i);
KeSetImportanceDpc(&cpu_dpc[i], HighImportance);
KeInsertQueueDpc(&cpu_dpc[i], NULL, NULL);
}
while (inp_dpcs != 0)
KeStallExecutionProcessor(1);
_disable();
return old_irql;
}```