Current CPython patch: https://github.com/tochilinak/cpython/pull/4/files.
All interaction between CPython and USVM is done through structure SymbolicAdapter.
Header: symbolicadapter.h.
Creation of symbolic adapter:
SymbolicAdapter *create_new_adapter(void *param);param is a parameter that will be accessible in all symbolic handlers.
Run function with symbolic tracing:
PyObject *SymbolicAdapter_run(PyObject *self, PyObject *function, Py_ssize_t n, PyObject *const *args, runnable before_call, runnable after_call);self: pointer to SymbolicAdapter.function: function to run (onlyPyFunctionis supported).n: number of arguments.argsmust be an array of tuples of size 2 (concrete and symbolic value for each argument).before_call: function to call right before execution.after_call: function to call right after execution.
Each of the following functions has a default implementation that does nothing, so any of them can be omitted.
All handlers accept param from create_new_adapter function as their first argument.
If return value of handler is int:
-
0 on success
-
Anything else if an error has happened (exception must be set).
If return value of handler is PyObject *:
-
Symbolic object on success (or
Py_Noneif it is absent). -
0 if an error has happened (exception must be set).
For descriptions of handlers see comments in symbolicadapter.h.