Section 19.5.1

Quiescent state for a live update

Definition

A live update, also called a hot update §14.33, is a replacement of code in a running program without a restart. A quiescent state for such an update is a state in which no execution depends on the old code any longer: no thread or interrupt handler §6.12 is executing the old code, none will return into it, and no stored pointer still leads to it. New calls may go to the new code at any time, but the old code may be freed or overwritten only in a quiescent state.

Where it fits

Main entry: Quiescent point (§14.34).

The Quiescent point entry states the general rule: an object may be reused only once nothing uses it or can start using it again. A thread depends on an old function AA in three ways.

The second way is easy to miss: a thread that is outside AA now can still be certain to execute AA later.

Three strategies are sound, and each has a cost.

Limits and common mistakes

While one thread still runs AA and new calls run the new function, both versions run at once; if they disagree about shared data, such as the meaning of a field, the mixture is a fault even though nothing was freed. Each published hotpatching system, such as RapidPatch §21.5, which He and colleagues presented in 2022 for the firmware of real-time embedded devices, argues its safety for its own patch mechanism. Citing one does not show that a different updater handles executions already inside old code.

Questions answered

What if an old function remains on a stack?

If an old function remains on a stack, its code must stay in memory, unchanged, until that execution has left it, because the thread will execute those old instructions when it continues. In a live update, which replaces code in a running program, changing the pointer through which callers reach a function redirects only future calls. Suppose thread RR is inside old function AA, waiting in a function that AA called, when the updater redirects calls to a new function and then frees the memory of AA. When the wait ends, RR returns to its saved address inside AA and executes whatever bytes now lie there: a use-after-free §4.6 of code.

The updater has three sound options: wait until no stack holds a return address into the old code and no paused thread’s next instruction lies in it; keep the old code forever; or rewrite each affected stack frame to the matching point in the new code, with a proof that execution continues correctly from there. A thread that never leaves the old function keeps the wait from ending, so the updater also needs a rule for retrying or refusing the update.

Related entries: Grace period (§9.21), Link register (LR) (§4.45), Dynamic patching and hot update (§14.33). Further reading: [157].