Shutdown Handling

wRTOS Shutdown handling prepares real-time devices controlled by wRTOS for a sudden Windows STOP caused by a Windows emergency Blue screen or by “normal” Windows shutdown initiated outside of RTSS. When it happens, wRTOS postpones Windows imminent STOP and switches to wRTOS Shutdown mode which allows RTSS applications to make emergency clean-up calls. During wRTOS Shutdown handling, the RTSS subsystem is still operational and fully functional; Win32 wRTOS threads are not. Only RTSS processes with handlers attached by an RtAttachShutdownhandler call will function during wRTOS Shutdown. We will name such processes the shutdown processes. There is no time restriction on the duration of the wRTOS shutdown; it can even last forever (but Windows will never perform its shutdown then).

Shutdown processes behave differently than other processes in wRTOS Shutdown mode. Only these RTSS processes remain functional during Windows shutdown while all others are frozen. Every shutdown handler, attached by the RtAttachShutdownhandler, performs in a separate context for RTSS threads and will be active during wRTOS Shutdown only. During normal Windows and wRTOS operations, these RTSS shutdown threads are dormant. Only one shutdown handler can be attached to RTSS process. The second RtAttachShutdownhandler call for the same process will be ignored unless there was a RtReleaseShutdownhandler call ahead.

The shutdown thread starts by calling the shutdown handler attached by RtAttachShutdownhandler. This handler has two arguments: the first one is defined by the user in the RtAttachShutdownhandler call, and the second one is provided by wRTOS to describe the reason for the current shutdown. The second argument helps the shutdown handler dynamically detect what is wrong with Windows.

The shutdown thread is not the only active RTSS shutdown processes thread during Windows shutdown. All other RTSS shutdown processes threads are also active and not restricted from usual RTSS real-time performance (where Windows help is unnecessary). However, depending on the type of Windows shutdown, they can be restricted from all or some non-real-time calls. Windows can continue its shutdown only after all RTSS shutdown processes have finished. When the last RTSS shutdown process exits, RTSS is stopped or unloaded, and Windows continues the shutdown process.

During wRTOS shutdown, the RTSS shutdown process can manipulate all existing threads with its shutdown thread — it can postpone or even change its priority (this is not wise), but it cannot create new RTSS threads and objects. It can call GetCurrentThread in the shutdown thread context to obtain the shutdown thread handle.The only difference is that if the shutdown thread exits or is terminated (because of “return”, ExitThread or TerminateThread calls) – the whole shutdown process also exits (the same effect as it was the main thread).

Note: If a call to KeBugCheck or KeBugCheckEx occurs at high IRQL, and a shutdown handler has RtPrintf or printf calls, a shutdown handler may become stuck at the point of print call. This is because the Windows core(s) cannot service the print request from RTSS due to being at high IRQL.

Subsystem Shutdown

If you attempt to stop the Subsystem while RTSS processes or Windows processes linked to wRTOS are still running, a dialog appears with a list of the running processes. For more information, see Stopping the Subsystem While Processes are Running.

Windows Blue Screen Shutdown

All shutdown process threads are active, plus there is one extra-thread, the shutdown thread. wRTOS Timer works, and all threads can perform real-time calls. However, they cannot call any non-real-time functions, involved Windows services, because only wRTOS Subsystem is able to work while Windows is fatally damaged and going to die.

Note: The thread will continue to run on Windows 10 and newer versions, but no output will appear on the screen.

Windows Normal Shutdown

All shutdown process threads are alive, plus there is one extra thread, the shutdown thread. wRTOS Timer works, and all threads can perform almost any call, not just real-time calls. Since the Windows GUI is no longer responsive, printf and RtPrintf will not function correctly. Therefore, you should avoid calling printf and RtPrintf in your shutdown handler routines. Also, at this stage, it is not recommended that you create new RTSS threads and objects, because Windows has already shut down several services.

Important Considerations

Below are important things to consider with Shutdown Handling in wRTOS:

Related topics: