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@php.net>                                 |
16   |          Zeev Suraski <zeev@php.net>                                 |
17   +----------------------------------------------------------------------+
18*/
19
20#ifndef MODULES_H
21#define MODULES_H
22
23#include "zend.h"
24#include "zend_compile.h"
25#include "zend_build.h"
26
27#define INIT_FUNC_ARGS		int type, int module_number
28#define INIT_FUNC_ARGS_PASSTHRU	type, module_number
29#define SHUTDOWN_FUNC_ARGS	int type, int module_number
30#define SHUTDOWN_FUNC_ARGS_PASSTHRU type, module_number
31#define ZEND_MODULE_INFO_FUNC_ARGS zend_module_entry *zend_module
32#define ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU zend_module
33
34#define ZEND_MODULE_API_NO 20180731
35#ifdef ZTS
36#define USING_ZTS 1
37#else
38#define USING_ZTS 0
39#endif
40
41#define STANDARD_MODULE_HEADER_EX sizeof(zend_module_entry), ZEND_MODULE_API_NO, ZEND_DEBUG, USING_ZTS
42#define STANDARD_MODULE_HEADER \
43	STANDARD_MODULE_HEADER_EX, NULL, NULL
44#define ZE2_STANDARD_MODULE_HEADER \
45	STANDARD_MODULE_HEADER_EX, ini_entries, NULL
46
47#define ZEND_MODULE_BUILD_ID "API" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA
48
49#define STANDARD_MODULE_PROPERTIES_EX 0, 0, NULL, 0, ZEND_MODULE_BUILD_ID
50
51#define NO_MODULE_GLOBALS 0, NULL, NULL, NULL
52
53#ifdef ZTS
54# define ZEND_MODULE_GLOBALS(module_name) sizeof(zend_##module_name##_globals), &module_name##_globals_id
55#else
56# define ZEND_MODULE_GLOBALS(module_name) sizeof(zend_##module_name##_globals), &module_name##_globals
57#endif
58
59#define STANDARD_MODULE_PROPERTIES \
60	NO_MODULE_GLOBALS, NULL, STANDARD_MODULE_PROPERTIES_EX
61
62#define NO_VERSION_YET NULL
63
64#define MODULE_PERSISTENT 1
65#define MODULE_TEMPORARY 2
66
67struct _zend_ini_entry;
68typedef struct _zend_module_entry zend_module_entry;
69typedef struct _zend_module_dep zend_module_dep;
70
71struct _zend_module_entry {
72	unsigned short size;
73	unsigned int zend_api;
74	unsigned char zend_debug;
75	unsigned char zts;
76	const struct _zend_ini_entry *ini_entry;
77	const struct _zend_module_dep *deps;
78	const char *name;
79	const struct _zend_function_entry *functions;
80	int (*module_startup_func)(INIT_FUNC_ARGS);
81	int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);
82	int (*request_startup_func)(INIT_FUNC_ARGS);
83	int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS);
84	void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS);
85	const char *version;
86	size_t globals_size;
87#ifdef ZTS
88	ts_rsrc_id* globals_id_ptr;
89#else
90	void* globals_ptr;
91#endif
92	void (*globals_ctor)(void *global);
93	void (*globals_dtor)(void *global);
94	int (*post_deactivate_func)(void);
95	int module_started;
96	unsigned char type;
97	void *handle;
98	int module_number;
99	const char *build_id;
100};
101
102#define MODULE_DEP_REQUIRED		1
103#define MODULE_DEP_CONFLICTS	2
104#define MODULE_DEP_OPTIONAL		3
105
106#define ZEND_MOD_REQUIRED_EX(name, rel, ver)	{ name, rel, ver, MODULE_DEP_REQUIRED  },
107#define ZEND_MOD_CONFLICTS_EX(name, rel, ver)	{ name, rel, ver, MODULE_DEP_CONFLICTS },
108#define ZEND_MOD_OPTIONAL_EX(name, rel, ver)	{ name, rel, ver, MODULE_DEP_OPTIONAL  },
109
110#define ZEND_MOD_REQUIRED(name)		ZEND_MOD_REQUIRED_EX(name, NULL, NULL)
111#define ZEND_MOD_CONFLICTS(name)	ZEND_MOD_CONFLICTS_EX(name, NULL, NULL)
112#define ZEND_MOD_OPTIONAL(name)		ZEND_MOD_OPTIONAL_EX(name, NULL, NULL)
113
114#define ZEND_MOD_END { NULL, NULL, NULL, 0 }
115
116struct _zend_module_dep {
117	const char *name;		/* module name */
118	const char *rel;		/* version relationship: NULL (exists), lt|le|eq|ge|gt (to given version) */
119	const char *version;	/* version */
120	unsigned char type;		/* dependency type */
121};
122
123BEGIN_EXTERN_C()
124extern ZEND_API HashTable module_registry;
125
126void module_destructor(zend_module_entry *module);
127int module_registry_request_startup(zend_module_entry *module);
128int module_registry_unload_temp(const zend_module_entry *module);
129END_EXTERN_C()
130
131#endif
132
133/*
134 * Local variables:
135 * tab-width: 4
136 * c-basic-offset: 4
137 * indent-tabs-mode: t
138 * End:
139 * vim600: sw=4 ts=4 fdm=marker
140 * vim<600: sw=4 ts=4
141 */
142