Additional API calls are available for special preparation of source code to be updateable. These API calls are commonly used to develop test programs that can demonstrate the capabilities of UpStare, accurately test new features, and conduct experiments. Dynamic software updates of real-world programs do not rely on these API calls.
The API calls require including the file hcu_headers.h, and they are:
HCU_STATIC_REQUEST_UPDATE_IMMEDIATE()
Insertion of this function call in a program forces a dynamic software update to begin when this call is issued. This is different than applying a dynamic software update when the hcuapply tool is invoked, because there is no guarantee of which code the program may be executing when an update is requested with hcuapply. It is a way of initiating a dynamic software update precisely when a particular piece of code is executing during experimentation.
Additionally, this function call means apply a dynamic software update using the updating model of stack reconstruction. An alternative option is to apply a dynamic software update using the updating model of update on function entry using the HCU_STATIC_REQUEST_UPDATE_LAZY() call.
HCU_STATIC_REQUEST_UPDATE_LAZY()
Insertion of this function call in a program means apply a dynamic software update lazily: update datatypes, if possible, and update functions on function entry. Do not apply stack reconstruction.
HCU_STATIC_UPDATE_FILE( filename, version )
If the dynamic software update will be initiated with any of the HCU_STATIC_REQUEST_UPDATE_*() calls, this call is used to inform the dynamic software update runtime of the filename the dynamic software update patch is stored in, and the update version.
HCU_MANUAL_UPDATE_POINT()
This function call manually inserts an update point. This is not necessarily a point where an update will begin.
Figure 4-3 shows an example using these additional API calls to test if dynamic software updates are refused if a signal handler is executing. The HCU_STATIC_UPDATE_FILE() macro is used in the top of the program to define the name of the dynamic software update patch file. HCU_STATIC_REQUEST_UPDATE_IMMEDIATE() is called to request an update inside functionA() which is called inside a signal handler. HCU_MANUAL_UPDATE_POINT() is placed right after this call to ensure an update point will be encountered and the dynamic software update will be attempted. In this example, the runtime detects the request for an update is issued while a signal handler is executing and refuses to apply the update at that point. Of course, the update request will be served as soon as the signal handler exits. But in this example no other update point will be encountered and the update will not be applied at all.
Figure 4-3. Test program that attempts to be updated inside a signal handler.
#include <stdio.h> #include <signal.h> #include "hcu_headers.h" HCU_STATIC_UPDATE_FILE("./libsignal_handler_v1.c_v1_to_v2.hcupatch.so.2",2); void functionA() { printf("functionA_v1 entered\n"); HCU_STATIC_REQUEST_UPDATE_IMMEDIATE(); HCU_MANUAL_UPDATE_POINT(); printf("functionA_v1 exited\n"); } void signal_handler(int s) { printf("signal_handler_v1 executed\n"); functionA(); } int main() { if (signal(SIGUSR1, signal_handler) == SIG_ERR) { perror("There was an error setting the signal handler:"); exit(-1); } kill(getpid(), SIGUSR1); printf("Signal handler test exiting\n"); return 0; }