b8109b370e434bdba23ad0ac2c93c9eb924871fb
[m6w6/ext-psi] / src / module.c
1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include <jit/jit.h>
7
8 #include "php.h"
9 #include "php_ini.h"
10 #include "ext/standard/info.h"
11
12 #include "php_psi.h"
13
14 #include "parser.h"
15 #include "validator.h"
16 #include "compiler.h"
17
18 ZEND_DECLARE_MODULE_GLOBALS(psi);
19
20 PHP_INI_BEGIN()
21 STD_PHP_INI_ENTRY("psi.directory", "psis", PHP_INI_ALL, OnUpdateString, directory, zend_psi_globals, psi_globals)
22 PHP_INI_END();
23
24 void psi_error(int type, const char *msg, ...)
25 {
26 char buf[0x1000];
27 va_list argv;
28
29 va_start(argv, msg);
30 vslprintf(buf, 0x1000, msg, argv);
31 va_end(argv);
32
33 php_error(type, buf);
34 }
35
36 PHP_MINIT_FUNCTION(psi)
37 {
38 REGISTER_INI_ENTRIES();
39
40 PSI_ContextInit(&PSI_G(context), PSI_Libjit(), psi_error);
41 PSI_ContextBuild(&PSI_G(context), PSI_G(directory));
42
43 return SUCCESS;
44 }
45 PHP_MSHUTDOWN_FUNCTION(psi)
46 {
47 jit_context_t ctx = PSI_G(context);
48 jit_context_destroy(ctx);
49
50 UNREGISTER_INI_ENTRIES();
51
52 return SUCCESS;
53 }
54
55 /* Remove if there's nothing to do at request start */
56 /* {{{ PHP_RINIT_FUNCTION
57 */
58 PHP_RINIT_FUNCTION(psi)
59 {
60 #if defined(COMPILE_DL_PSI) && defined(ZTS)
61 ZEND_TSRMLS_CACHE_UPDATE();
62 #endif
63 return SUCCESS;
64 }
65 /* }}} */
66
67 /* Remove if there's nothing to do at request end */
68 /* {{{ PHP_RSHUTDOWN_FUNCTION
69 */
70 PHP_RSHUTDOWN_FUNCTION(psi)
71 {
72 return SUCCESS;
73 }
74 /* }}} */
75
76 PHP_MINFO_FUNCTION(psi)
77 {
78 php_info_print_table_start();
79 php_info_print_table_header(2, "psi support", "enabled");
80 php_info_print_table_end();
81
82 DISPLAY_INI_ENTRIES();
83 }
84 const zend_function_entry psi_functions[] = {
85 PHP_FE_END
86 };
87
88 zend_module_entry psi_module_entry = {
89 STANDARD_MODULE_HEADER,
90 "psi",
91 psi_functions,
92 PHP_MINIT(psi),
93 PHP_MSHUTDOWN(psi),
94 PHP_RINIT(psi), /* Replace with NULL if there's nothing to do at request start */
95 PHP_RSHUTDOWN(psi), /* Replace with NULL if there's nothing to do at request end */
96 PHP_MINFO(psi),
97 PHP_PSI_VERSION,
98 STANDARD_MODULE_PROPERTIES
99 };
100
101 #ifdef COMPILE_DL_PSI
102 #ifdef ZTS
103 ZEND_TSRMLS_CACHE_DEFINE();
104 #endif
105 ZEND_GET_MODULE(psi)
106 #endif
107
108 /*
109 * Local variables:
110 * tab-width: 4
111 * c-basic-offset: 4
112 * End:
113 * vim600: noet sw=4 ts=4 fdm=marker
114 * vim<600: noet sw=4 ts=4
115 */