TPF_TC_INTERCEPT: Intercept the call or return from a function

This C/C++ macro intercepts a call to a function, a return from a function, or whenever a call is made from a function. The intercept specifies an alternative function to call before calling the intended target.

Last updated

Added in 2019.

Format

maketpf_env += idevops
#include <tpf/c_devops.h>
void TPF_TC_INTERCEPT(char *function, void *call, void *data,
                      unsigned int length, char *scope, unsigned int case);
function
A pointer to a string that contains a function name or a 4-character program name that you want to intercept.
call
A pointer to the function to call. If you specify NULL, the function or program that is specified by the function parameter is not intercepted.
data
A pointer to optional additional data that you want to pass to the called function. To retrieve the data that is passed with this parameter, use the TPF_TC_GET_PROPERTY macro in the called function and specify TPF_TC_DATA for the property parameter.
length
The length of the data that is passed by the data parameter.
scope
A pointer to a function or program that calls the function or program that is specified by the function parameter. Specify this value when you want to limit the scope of the interception to a specific function or program. The function or program specified by the function parameter will be intercepted only when the function or program that you specify for the scope parameter is the caller. If you specify NULL for this parameter, the function or program specified by the function parameter is always intercepted.
case
Specify one of the following values:
TPF_TC_CALL
Intercepts the call to the function or program that is specified by the function parameter.
TPF_TC_RETURN
Intercepts the return from the function or program that is specified by the function parameter.
TPF_TC_LEAVING
Intercepts any call from the function or program that is specified by the function parameter.

Normal return

None.

Error return

If a test case handle is not set, a DE1045 system error is issued and the ECB exits.

Programming considerations

  • If you specify a C++ function name for the function, call, or scope parameter, you must use the mangled name of the function.
  • If you specify an EVM address for the data parameter, the data is visible to only the ECB that obtained the storage.
  • Do not use this macro in production applications.
  • The prototype for the intercept function must match the prototype for the intercepted function.
  • If the case parameter is set to TPF_TC_CALL, ensure that the function specified by the call parameter has the same parameters as the function being intercepted.
  • If the case parameter is set to TPF_TC_RETURN or TPF_TC_LEAVING, ensure that the function specified by the call parameter has no parameters and no return call.
  • If the case parameter is set to TPF_TC_LEAVING, the scope parameter is ignored.
  • When the case parameter is set to TPF_TC_LEAVING, anytime a function is entered and the caller is the value that is coded on the function parameter, the function name that is coded on the call parameter is called instead.

Examples

The following example intercepts the call to the my_function function and calls the intercept_function function instead.
TPF_TC_INTERCEPT("my_function", intercept_function, NULL, 0, NULL, TPF_TC_CALL);