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 in three ways.
Its program counter §2.9, the register that holds the address of the next instruction, points into , even while the thread is paused by an interrupt §6.11 or by the scheduler.
A return address into sits in a register, such as the link register §4.45 of Arm processors, or on the thread’s stack, because called a function that has not yet returned.
The thread, a timer or a queue holds a pointer to , such as a registered callback §14.22.
The second way is easy to miss: a thread that is outside now can still be certain to execute later.
Three strategies are sound, and each has a cost.
Wait until every execution that could depend on has ended, as read-copy update §9.20 waits for a grace period §9.21, the wait until every reader that might hold an old version has finished. One check pauses each thread at a known point and searches its stack for return addresses inside , retrying later if it finds one. A thread whose main loop is never lets the wait end.
Keep forever, at the cost of memory for every old version.
Transform each paused execution: rewrite its saved addresses and its stack frame, the stack region that holds one call’s return address and local variables, to the matching point in the new function. This needs a proof that the new code continues correctly from every such point.
Limits and common mistakes
While one thread still runs 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 is inside old function , waiting in a function that called, when the updater redirects calls to a new function and then frees the memory of . When the wait ends, returns to its saved address inside 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].