xref: /PHP-7.1/Zend/zend_extensions.h (revision ccd4716e)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 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@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifndef ZEND_EXTENSIONS_H
23 #define ZEND_EXTENSIONS_H
24 
25 #include "zend_compile.h"
26 #include "zend_build.h"
27 
28 /*
29 The constants below are derived from ext/opcache/ZendAccelerator.h
30 
31 You can use the following macro to check the extension API version for compatibilities:
32 
33 #define	ZEND_EXTENSION_API_NO_5_0_X	220040412
34 #define	ZEND_EXTENSION_API_NO_5_1_X	220051025
35 #define	ZEND_EXTENSION_API_NO_5_2_X	220060519
36 #define	ZEND_EXTENSION_API_NO_5_3_X	220090626
37 #define	ZEND_EXTENSION_API_NO_5_4_X	220100525
38 #define	ZEND_EXTENSION_API_NO_5_5_X	220121212
39 #define	ZEND_EXTENSION_API_NO_5_6_X	220131226
40 #define	ZEND_EXTENSION_API_NO_7_0_X	320151012
41 
42 #if ZEND_EXTENSION_API_NO < ZEND_EXTENSION_API_NO_5_5_X
43    // do something for php versions lower than 5.5.x
44 #endif
45 */
46 
47 /* The first number is the engine version and the rest is the date (YYYYMMDD).
48  * This way engine 2/3 API no. is always greater than engine 1 API no..  */
49 #define ZEND_EXTENSION_API_NO	320160303
50 
51 typedef struct _zend_extension_version_info {
52 	int zend_extension_api_no;
53 	char *build_id;
54 } zend_extension_version_info;
55 
56 #define ZEND_EXTENSION_BUILD_ID "API" ZEND_TOSTR(ZEND_EXTENSION_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA
57 
58 typedef struct _zend_extension zend_extension;
59 
60 /* Typedef's for zend_extension function pointers */
61 typedef int (*startup_func_t)(zend_extension *extension);
62 typedef void (*shutdown_func_t)(zend_extension *extension);
63 typedef void (*activate_func_t)(void);
64 typedef void (*deactivate_func_t)(void);
65 
66 typedef void (*message_handler_func_t)(int message, void *arg);
67 
68 typedef void (*op_array_handler_func_t)(zend_op_array *op_array);
69 
70 typedef void (*statement_handler_func_t)(zend_execute_data *frame);
71 typedef void (*fcall_begin_handler_func_t)(zend_execute_data *frame);
72 typedef void (*fcall_end_handler_func_t)(zend_execute_data *frame);
73 
74 typedef void (*op_array_ctor_func_t)(zend_op_array *op_array);
75 typedef void (*op_array_dtor_func_t)(zend_op_array *op_array);
76 typedef size_t (*op_array_persist_calc_func_t)(zend_op_array *op_array);
77 typedef size_t (*op_array_persist_func_t)(zend_op_array *op_array, void *mem);
78 
79 struct _zend_extension {
80 	char *name;
81 	char *version;
82 	char *author;
83 	char *URL;
84 	char *copyright;
85 
86 	startup_func_t startup;
87 	shutdown_func_t shutdown;
88 	activate_func_t activate;
89 	deactivate_func_t deactivate;
90 
91 	message_handler_func_t message_handler;
92 
93 	op_array_handler_func_t op_array_handler;
94 
95 	statement_handler_func_t statement_handler;
96 	fcall_begin_handler_func_t fcall_begin_handler;
97 	fcall_end_handler_func_t fcall_end_handler;
98 
99 	op_array_ctor_func_t op_array_ctor;
100 	op_array_dtor_func_t op_array_dtor;
101 
102 	int (*api_no_check)(int api_no);
103 	int (*build_id_check)(const char* build_id);
104 	op_array_persist_calc_func_t op_array_persist_calc;
105 	op_array_persist_func_t op_array_persist;
106 	void *reserved5;
107 	void *reserved6;
108 	void *reserved7;
109 	void *reserved8;
110 
111 	DL_HANDLE handle;
112 	int resource_number;
113 };
114 
115 BEGIN_EXTERN_C()
116 ZEND_API int zend_get_resource_handle(zend_extension *extension);
117 ZEND_API void zend_extension_dispatch_message(int message, void *arg);
118 END_EXTERN_C()
119 
120 #define ZEND_EXTMSG_NEW_EXTENSION		1
121 
122 
123 #define ZEND_EXTENSION()	\
124 	ZEND_EXT_API zend_extension_version_info extension_version_info = { ZEND_EXTENSION_API_NO, ZEND_EXTENSION_BUILD_ID }
125 
126 #define STANDARD_ZEND_EXTENSION_PROPERTIES       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
127 #define COMPAT_ZEND_EXTENSION_PROPERTIES         NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
128 #define BUILD_COMPAT_ZEND_EXTENSION_PROPERTIES   NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1
129 
130 
131 ZEND_API extern zend_llist zend_extensions;
132 ZEND_API extern uint32_t zend_extension_flags;
133 
134 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_CTOR         (1<<0)
135 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_DTOR         (1<<1)
136 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_HANDLER      (1<<2)
137 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST_CALC (1<<3)
138 #define ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST      (1<<4)
139 
140 void zend_extension_dtor(zend_extension *extension);
141 ZEND_API void zend_append_version_info(const zend_extension *extension);
142 int zend_startup_extensions_mechanism(void);
143 int zend_startup_extensions(void);
144 void zend_shutdown_extensions(void);
145 
146 BEGIN_EXTERN_C()
147 ZEND_API int zend_load_extension(const char *path);
148 ZEND_API int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle);
149 ZEND_API zend_extension *zend_get_extension(const char *extension_name);
150 ZEND_API size_t zend_extensions_op_array_persist_calc(zend_op_array *op_array);
151 ZEND_API size_t zend_extensions_op_array_persist(zend_op_array *op_array, void *mem);
152 END_EXTERN_C()
153 
154 #endif /* ZEND_EXTENSIONS_H */
155 
156 /*
157  * Local variables:
158  * tab-width: 4
159  * c-basic-offset: 4
160  * indent-tabs-mode: t
161  * End:
162  */
163