PSTOP_PROCESSORS_DATA stopData = stop_processors();
if (stopData == nullptr) {
return false;
}
// dosomething
// ...
resume_processors(stopData); // sometimes will be crash at here
I just want to suspend the processor. Is there a better safe and stable way? thanks.
I just want to suspend the processor. Is there a better safe and stable way? thanks.
You should tell us what problem you are trying to solve, because the code you’ve posted there is total bullshit. A DPC is not supposed to stall, because it affects the performance of the entire system. That’s why the bug check is in there to begin with.
If you’re just playing around, perhaps you should try Linux instead. If you actually have a legitimate problem to solve, then there is obviously a better way. Tell us about the overall goal.
@Tim_Roberts
Thank you for pointing out, as in the stack context provided above, I need to hook certain functions, but in order to prevent the processor from executing where I am at the hook, I need to pause it and then resume after I install the hook., It only occasionally triggers this error.
PSTOP_PROCESSORS_DATA stopData = stop_processors();
if (stopData == nullptr) {
return false;
}
// dosomething
/* similar to user mode hooks, first suspend all threads and then check the eip/rip position to determine whether to hook, but I think the driver mode should be safer to suspend the processor
*/
hook_fun()
resume_processors(stopData); // sometimes will be crash at here
You’re using brute force to solve a problem that can be solved much more elegantly. You’re going to be inserting a jmp instruction, right? A jmp instruction is less than 8 bytes. If you use InterlockedExchange64, you can swap 8 bytes atomically. Atomically, in this case, means "all or nothing’. Any given processor will either execute all of the old code, or all of the new code. You don’t have to stop any processors at all.
Well this is still bullshit code, but you need to implement a processor
corral. You could use the existing IPC mechanism’s support, but it is
closed off. So instead you need to schedule dpcs on each cpu and have them
rendez-vous with each other and elect one of them to perform the horrible
nonsense you think you need to do.
Good luck.
Also if your implementation sucks you will still have to deal with dpc
timeouts.