windowslinuxkernelinsmod

infinite loop in linux/windows kernel module


In ubuntu10.04 linux kernel if I insmod a module which runs

while(1);

in init_module part, entire system stops.

However, if I load a sys file in Windows 7 which runs while(1); in DriverEntry part, system gets slow but still works.

can someone explain me why two system differs and what is happening inside kernel?...

I think in first case(infinite loop in init_module), there is no reason the system stops. because even if I make while(1); in init_module, it is running in context of insmod user application program. so the flow infinite loop has to be scheduled by hardware interrupt signal.

This is just my opinion, I want to know the details if I am wrong...


Solution

  • Adding to Frédéric's answer: on Windows the DriverEntry function runs at IRQL PASSIVE_LEVEL (same as virtually all user mode code, all if we exclude APCs). Which means that it can be interrupted by any code running at a higher IRQL at any point. So what you probably encounter here is that the thread that goes into the infinite loop is still being scheduled (thus consuming CPU time), but due to its (low) IRQL it isn't able to starve the system threads or much of the other code that is running. It will, however, be able to starve user mode threads. The effect can be anything from a slowdown to a perceived hanging system.