17
17
18
18
#define MIN_API_VERSION 320151012
19
19
#define MAX_API_VERSION 420240924
20
+ #define MAX_INI_API_VERSION MAX_API_VERSION + 1
20
21
21
22
#define PHP_70_VERSION 20151012
22
23
#define PHP_71_VERSION 20160303
24
+ #define PHP_72_VERSION 20170718
23
25
#define PHP_80_VERSION 20200930
24
26
25
27
#define MIN_PHP_VERSION "7.0"
@@ -44,6 +46,28 @@ static bool already_done = false;
44
46
# define OS_PATH "linux-gnu/"
45
47
#endif
46
48
49
+ static ZEND_INI_MH (ddloader_OnUpdateForceInject ) {
50
+ (void )entry ;
51
+ (void )mh_arg1 ;
52
+ (void )mh_arg2 ;
53
+ (void )mh_arg3 ;
54
+ (void )stage ;
55
+
56
+ if (!force_load ) {
57
+ force_load = ddloader_zend_ini_parse_bool (new_value );
58
+ }
59
+ return SUCCESS ;
60
+ }
61
+
62
+ PHP_INI_BEGIN ()
63
+ ZEND_INI_ENTRY ("datadog.loader.force_inject" , "0" , PHP_INI_SYSTEM , ddloader_OnUpdateForceInject )
64
+ PHP_INI_END ()
65
+
66
+ static const php7_0_to_2_zend_ini_entry_def ini_entries_7_0_to_2 [] = {
67
+ ZEND_INI_ENTRY ("datadog.loader.force_inject" , "0" , PHP_INI_SYSTEM , ddloader_OnUpdateForceInject )
68
+ PHP_INI_END ()
69
+
70
+
47
71
static void ddloader_telemetryf (telemetry_reason reason , injected_ext * config , const char * error , const char * format , ...);
48
72
49
73
static char * ddtrace_pre_load_hook (injected_ext * config ) {
@@ -752,6 +776,9 @@ static int ddloader_api_no_check(int api_no) {
752
776
return SUCCESS ;
753
777
}
754
778
779
+ // api_no is the Zend extension API number, similar to "420220829"
780
+ // It is an int, but represented as a string, we must remove the first char to get the PHP module API number
781
+ unsigned int module_api_no = api_no % 100000000 ;
755
782
ddloader_configure ();
756
783
757
784
TELEMETRY (REASON_START , NULL , NULL , "Starting injection" );
@@ -793,6 +820,11 @@ static int ddloader_api_no_check(int api_no) {
793
820
return SUCCESS ;
794
821
}
795
822
823
+ if (force_load || api_no <= MAX_INI_API_VERSION ) {
824
+ zend_module_entry * mod = zend_register_internal_module (& dd_library_loader_mod );
825
+ zend_register_ini_entries (module_api_no <= PHP_72_VERSION ? (zend_ini_entry_def * ) ini_entries_7_0_to_2 : ini_entries , mod -> module_number );
826
+ }
827
+
796
828
if (api_no > MAX_API_VERSION ) {
797
829
if (!force_load ) {
798
830
TELEMETRY (REASON_INCOMPATIBLE_RUNTIME , NULL , NULL , "Found incompatible runtime (api no: %d). Supported runtimes: PHP " MIN_PHP_VERSION " to " MAX_PHP_VERSION , api_no );
@@ -802,9 +834,7 @@ static int ddloader_api_no_check(int api_no) {
802
834
LOG (NULL , WARN , "DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing (api no: %d)." , api_no );
803
835
}
804
836
805
- // api_no is the Zend extension API number, similar to "420220829"
806
- // It is an int, but represented as a string, we must remove the first char to get the PHP module API number
807
- php_api_no = api_no % 100000000 ;
837
+ php_api_no = module_api_no ;
808
838
809
839
return SUCCESS ;
810
840
}
@@ -846,7 +876,6 @@ static int ddloader_build_id_check(const char *build_id) {
846
876
// Required. Otherwise the zend_extension is not loaded
847
877
static int ddloader_zend_extension_startup (zend_extension * ext ) {
848
878
UNUSED (ext );
849
- zend_register_internal_module (& dd_library_loader_mod );
850
879
return SUCCESS ;
851
880
}
852
881
0 commit comments