in prod/native/extension/code/InternalFunctionInstrumentation.cpp [242:297]
void ZEND_FASTCALL internal_function_handler(INTERNAL_FUNCTION_PARAMETERS) {
auto hash = getClassAndFunctionHashFromExecuteData(execute_data);
auto originalHandler = InternalStorage_t::getInstance().get(hash);
if (!originalHandler) {
auto [cls, func] = getClassAndFunctionName(execute_data);
ELOGF_CRITICAL(EAPM_GL(logger_), INSTRUMENTATION, "Unable to find function handler " PRsv "::" PRsv, PRsvArg(cls), PRsvArg(func));
return;
}
if (!EAPM_GL(requestScope_)->isFunctional()) {
callOriginalHandler(originalHandler, INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}
auto callbacks = reinterpret_cast<InstrumentedFunctionHooksStorage_t *>(EAPM_GL(hooksStorage_).get())->find(hash);
if (!callbacks) {
callOriginalHandler(originalHandler, INTERNAL_FUNCTION_PARAM_PASSTHRU);
ELOGF_WARNING(EAPM_GL(logger_), INSTRUMENTATION, "Unable to find function callbacks");
return;
}
for (auto &callback : *callbacks) {
if (callback.first.isNull() || callback.first.isUndef()) {
continue;
}
try {
AutomaticExceptionStateRestorer restorer;
callPreHook(callback.first);
handleAndReleaseHookException(EG(exception));
} catch (std::exception const &e) {
auto [cls, func] = getClassAndFunctionName(execute_data);
ELOGF_CRITICAL(EAPM_GL(logger_), INSTRUMENTATION, "%s hash: 0x%X " PRsv "::" PRsv, e.what(), hash, PRsvArg(cls), PRsvArg(func));
}
}
callOriginalHandler(originalHandler, INTERNAL_FUNCTION_PARAM_PASSTHRU);
for (auto &callback : *callbacks) {
if (callback.second.isNull() || callback.second.isUndef()) {
continue;
}
try {
AutomaticExceptionStateRestorer restorer;
callPostHook(callback.second, return_value, restorer.getException(), execute_data);
handleAndReleaseHookException(EG(exception));
} catch (std::exception const &e) {
auto [cls, func] = getClassAndFunctionName(execute_data);
ELOGF_CRITICAL(EAPM_GL(logger_), INSTRUMENTATION, "%s hash: 0x%X " PRsv "::" PRsv, e.what(), hash, PRsvArg(cls), PRsvArg(func));
}
}
}