xref: /PHP-7.4/Zend/zend_extensions.h (revision c739023a)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef ZEND_EXTENSIONS_H
21 #define ZEND_EXTENSIONS_H
22 
23 #include "zend_compile.h"
24 #include "zend_build.h"
25 
26 /*
27 The constants below are derived from ext/opcache/ZendAccelerator.h
28 
29 You can use the following macro to check the extension API version for compatibilities:
30 
31 #define	ZEND_EXTENSION_API_NO_5_0_X	220040412
32 #define	ZEND_EXTENSION_API_NO_5_1_X	220051025
33 #define	ZEND_EXTENSION_API_NO_5_2_X	220060519
34 #define	ZEND_EXTENSION_API_NO_5_3_X	220090626
35 #define	ZEND_EXTENSION_API_NO_5_4_X	220100525
36 #define	ZEND_EXTENSION_API_NO_5_5_X	220121212
37 #define	ZEND_EXTENSION_API_NO_5_6_X	220131226
38 #define	ZEND_EXTENSION_API_NO_7_0_X	320151012
39 
40 #if ZEND_EXTENSION_API_NO < ZEND_EXTENSION_API_NO_5_5_X
41    // do something for php versions lower than 5.5.x
42 #endif
43 */
44 
45 /* The first number is the engine version and the rest is the date (YYYYMMDD).
46  * This way engine 2/3 API no. is always greater than engine 1 API no..  */
47 #define ZEND_EXTENSION_API_NO	320190902
48 
49 typedef struct _zend_extension_version_info {
50 	int zend_extension_api_no;
51 	char *build_id;
52 } zend_extension_version_info;
53 
54 #define ZEND_EXTENSION_BUILD_ID "API" ZEND_TOSTR(ZEND_EXTENSION_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA
55 
56 typedef struct _zend_extension zend_extension;
57 
58 /* Typedef's for zend_extension function pointers */
59 typedef int (*startup_func_t)(zend_extension *extension);
60 typedef void (*shutdown_func_t)(zend_extension *extension);
61 typedef void (*activate_func_t)(void);
62 typedef void (*deactivate_func_t)(void);
63 
64 typedef void (*message_handler_func_t)(int message, void *arg);
65 
66 typedef void (*op_array_handler_func_t)(zend_op_array *op_array);
67 
68 typedef void (*statement_handler_func_t)(zend_execute_data *frame);
69 typedef void (*fcall_begin_handler_func_t)(zend_execute_data *frame);
70 typedef void (*fcall_end_handler_func_t)(zend_execute_data *frame);
71 
72 typedef void (*op_array_ctor_func_t)(zend_op_array *op_array);
73 typedef void (*op_array_dtor_func_t)(zend_op_array *op_array);
74 typedef size_t (*op_array_persist_calc_func_t)(zend_op_array *op_array);
75 typedef size_t (*op_array_persist_func_t)(zend_op_array *op_array, void *mem);
76 
77 struct _zend_extension {
78 	char *name;
79 	char *version;
80 	char *author;
81 	char *URL;
82 	char *copyright;
83 
84 	startup_func_t startup;
85 	shutdown_func_t shutdown;
86 	activate_func_t activate;
87 	deactivate_func_t deactivate;
88 
89 	message_handler_func_t message_handler;
90 
91 	op_array_handler_func_t op_array_handler;
92 
93 	statement_handler_func_t statement_handler;
94 	fcall_begin_handler_func_t fcall_begin_handler;
95 	fcall_end_handler_func_t fcall_end_handler;
96 
97 	op_array_ctor_func_t op_array_ctor;
98 	op_array_dtor_func_t op_array_dtor;
99 
100 	int (*api_no_check)(int api_no);
101 	int (*build_id_check)(const char* build_id);
102 	op_array_persist_calc_func_t op_array_persist_calc;
103 	op_array_persist_func_t op_array_persist;
104 	void *reserved5;
105 	void *reserved6;
106 	void *reserved7;
107 	void *reserved8;
108 
109 	DL_HANDLE handle;
110 	int resource_number;
111 };
112 
113 BEGIN_EXTERN_C()
114 extern ZEND_API int zend_op_array_extension_handles;
115 
116 ZEND_API int zend_get_resource_handle(zend_extension *extension);
117 ZEND_API int zend_get_op_array_extension_handle(void);
118 ZEND_API void zend_extension_dispatch_message(int message, void *arg);
119 END_EXTERN_C()
120 
121 #define ZEND_EXTMSG_NEW_EXTENSION		1
122 
123 
124 #define ZEND_EXTENSION()	\
125 	ZEND_EXT_API zend_extension_version_info extension_version_info = { ZEND_EXTENSION_API_NO, ZEND_EXTENSION_BUILD_ID }
126 
127 #define STANDARD_ZEND_EXTENSION_PROPERTIES       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
128 #define COMPAT_ZEND_EXTENSION_PROPERTIES         NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
129 #define BUILD_COMPAT_ZEND_EXTENSION_PROPERTIES   NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
130 
131 
132 ZEND_API extern zend_llist zend_extensions;
133 ZEND_API extern uint32_t zend_extension_flags;
134 
135 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_CTOR         (1<<0)
136 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_DTOR         (1<<1)
137 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_HANDLER      (1<<2)
138 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST_CALC (1<<3)
139 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST      (1<<4)
140 
141 void zend_extension_dtor(zend_extension *extension);
142 ZEND_API void zend_append_version_info(const zend_extension *extension);
143 int zend_startup_extensions_mechanism(void);
144 int zend_startup_extensions(void);
145 void zend_shutdown_extensions(void);
146 
147 BEGIN_EXTERN_C()
148 ZEND_API int zend_load_extension(const char *path);
149 ZEND_API int zend_load_extension_handle(DL_HANDLE handle, const char *path);
150 ZEND_API int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle);
151 ZEND_API zend_extension *zend_get_extension(const char *extension_name);
152 ZEND_API size_t zend_extensions_op_array_persist_calc(zend_op_array *op_array);
153 ZEND_API size_t zend_extensions_op_array_persist(zend_op_array *op_array, void *mem);
154 END_EXTERN_C()
155 
156 #endif /* ZEND_EXTENSIONS_H */
157