xref: /PHP-8.0/ext/standard/basic_functions.h (revision 8067cf47)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Andi Gutmans <andi@php.net>                                 |
14    |          Zeev Suraski <zeev@php.net>                                 |
15    +----------------------------------------------------------------------+
16 */
17 
18 #ifndef BASIC_FUNCTIONS_H
19 #define BASIC_FUNCTIONS_H
20 
21 #include <sys/stat.h>
22 #include <wchar.h>
23 
24 #include "php_filestat.h"
25 
26 #include "zend_highlight.h"
27 
28 #include "url_scanner_ex.h"
29 
30 #if defined(_WIN32) && !defined(__clang__)
31 #include <intrin.h>
32 #endif
33 
34 extern zend_module_entry basic_functions_module;
35 #define basic_functions_module_ptr &basic_functions_module
36 
37 PHP_MINIT_FUNCTION(basic);
38 PHP_MSHUTDOWN_FUNCTION(basic);
39 PHP_RINIT_FUNCTION(basic);
40 PHP_RSHUTDOWN_FUNCTION(basic);
41 PHP_MINFO_FUNCTION(basic);
42 
43 ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini);
44 
45 PHP_MINIT_FUNCTION(user_filters);
46 PHP_RSHUTDOWN_FUNCTION(user_filters);
47 PHP_RSHUTDOWN_FUNCTION(browscap);
48 
49 /* Left for BC (not binary safe!) */
50 PHPAPI int _php_error_log(int opt_err, const char *message, const char *opt, const char *headers);
51 PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_len, const char *opt, const char *headers);
52 PHPAPI int php_prefix_varname(zval *result, zend_string *prefix, const char *var_name, size_t var_name_len, zend_bool add_underscore);
53 
54 #define MT_N (624)
55 
56 /* Deprecated type aliases -- use the standard types instead */
57 typedef uint32_t php_uint32;
58 typedef int32_t php_int32;
59 
60 typedef struct _php_basic_globals {
61 	HashTable *user_shutdown_function_names;
62 	HashTable putenv_ht;
63 	zend_string *strtok_string;
64 	zend_string *ctype_string; /* current LC_CTYPE locale (or NULL for 'C') */
65 	zend_bool locale_changed;   /* locale was changed and has to be restored */
66 	char *strtok_last;
67 	char strtok_table[256];
68 	size_t strtok_len;
69 	zend_fcall_info array_walk_fci;
70 	zend_fcall_info_cache array_walk_fci_cache;
71 	zend_fcall_info user_compare_fci;
72 	zend_fcall_info_cache user_compare_fci_cache;
73 	zend_llist *user_tick_functions;
74 
75 	zval active_ini_file_section;
76 
77 	/* pageinfo.c */
78 	zend_long page_uid;
79 	zend_long page_gid;
80 	zend_long page_inode;
81 	time_t page_mtime;
82 
83 	/* filestat.c && main/streams/streams.c */
84 	char *CurrentStatFile, *CurrentLStatFile;
85 	php_stream_statbuf ssb, lssb;
86 
87 	/* mt_rand.c */
88 	uint32_t state[MT_N+1];  /* state vector + 1 extra to not violate ANSI C */
89 	uint32_t *next;       /* next random value is computed from here */
90 	int      left;        /* can *next++ this many times before reloading */
91 
92 	zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */
93 	zend_long mt_rand_mode;
94 
95 	/* syslog.c */
96 	char *syslog_device;
97 
98 	/* var.c */
99 	unsigned serialize_lock; /* whether to use the locally supplied var_hash instead (__sleep/__wakeup) */
100 	struct {
101 		struct php_serialize_data *data;
102 		unsigned level;
103 	} serialize;
104 	struct {
105 		struct php_unserialize_data *data;
106 		unsigned level;
107 	} unserialize;
108 
109 	/* url_scanner_ex.re */
110 	url_adapt_state_ex_t url_adapt_session_ex;
111 	HashTable url_adapt_session_hosts_ht;
112 	url_adapt_state_ex_t url_adapt_output_ex;
113 	HashTable url_adapt_output_hosts_ht;
114 	HashTable *user_filter_map;
115 
116 	/* file.c */
117 #if defined(_REENTRANT)
118 	mbstate_t mblen_state;
119 #endif
120 
121 	int umask;
122 	zend_long unserialize_max_depth;
123 } php_basic_globals;
124 
125 #ifdef ZTS
126 #define BG(v) ZEND_TSRMG(basic_globals_id, php_basic_globals *, v)
127 PHPAPI extern int basic_globals_id;
128 #else
129 #define BG(v) (basic_globals.v)
130 PHPAPI extern php_basic_globals basic_globals;
131 #endif
132 
133 #if HAVE_PUTENV
134 typedef struct {
135 	char *putenv_string;
136 	char *previous_value;
137 	char *key;
138 	size_t key_len;
139 } putenv_entry;
140 #endif
141 
142 PHPAPI double php_get_nan(void);
143 PHPAPI double php_get_inf(void);
144 
145 typedef struct _php_shutdown_function_entry {
146 	zval function_name;
147 	zval *arguments;
148 	int arg_count;
149 } php_shutdown_function_entry;
150 
151 PHPAPI extern zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
152 PHPAPI extern zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len);
153 PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry *shutdown_function_entry);
154 
155 PHPAPI void php_call_shutdown_functions(void);
156 PHPAPI void php_free_shutdown_functions(void);
157 
158 
159 #endif /* BASIC_FUNCTIONS_H */
160