1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 7 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2017 The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP 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.php.net/license/3_01.txt | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net 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 BASIC_FUNCTIONS_H 23 #define BASIC_FUNCTIONS_H 24 25 #include <sys/stat.h> 26 27 #ifdef HAVE_WCHAR_H 28 #include <wchar.h> 29 #endif 30 31 #include "php_filestat.h" 32 33 #include "zend_highlight.h" 34 35 #include "url_scanner_ex.h" 36 37 #if defined(_WIN32) && defined(__clang__) 38 #include <intrin.h> 39 #endif 40 41 extern zend_module_entry basic_functions_module; 42 #define basic_functions_module_ptr &basic_functions_module 43 44 PHP_MINIT_FUNCTION(basic); 45 PHP_MSHUTDOWN_FUNCTION(basic); 46 PHP_RINIT_FUNCTION(basic); 47 PHP_RSHUTDOWN_FUNCTION(basic); 48 PHP_MINFO_FUNCTION(basic); 49 50 PHP_FUNCTION(constant); 51 PHP_FUNCTION(sleep); 52 PHP_FUNCTION(usleep); 53 #if HAVE_NANOSLEEP 54 PHP_FUNCTION(time_nanosleep); 55 PHP_FUNCTION(time_sleep_until); 56 #endif 57 PHP_FUNCTION(flush); 58 #ifdef HAVE_INET_NTOP 59 PHP_NAMED_FUNCTION(php_inet_ntop); 60 #endif 61 #ifdef HAVE_INET_PTON 62 PHP_NAMED_FUNCTION(php_inet_pton); 63 #endif 64 PHP_FUNCTION(ip2long); 65 PHP_FUNCTION(long2ip); 66 67 /* system functions */ 68 PHP_FUNCTION(getenv); 69 PHP_FUNCTION(putenv); 70 71 PHP_FUNCTION(getopt); 72 73 PHP_FUNCTION(get_current_user); 74 PHP_FUNCTION(set_time_limit); 75 76 PHP_FUNCTION(header_register_callback); 77 78 PHP_FUNCTION(get_cfg_var); 79 PHP_FUNCTION(get_magic_quotes_runtime); 80 PHP_FUNCTION(get_magic_quotes_gpc); 81 82 PHP_FUNCTION(error_log); 83 PHP_FUNCTION(error_get_last); 84 PHP_FUNCTION(error_clear_last); 85 86 PHP_FUNCTION(call_user_func); 87 PHP_FUNCTION(call_user_func_array); 88 PHP_FUNCTION(forward_static_call); 89 PHP_FUNCTION(forward_static_call_array); 90 91 PHP_FUNCTION(register_shutdown_function); 92 PHP_FUNCTION(highlight_file); 93 PHP_FUNCTION(highlight_string); 94 PHP_FUNCTION(php_strip_whitespace); 95 ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini); 96 97 PHP_FUNCTION(ini_get); 98 PHP_FUNCTION(ini_get_all); 99 PHP_FUNCTION(ini_set); 100 PHP_FUNCTION(ini_restore); 101 PHP_FUNCTION(get_include_path); 102 PHP_FUNCTION(set_include_path); 103 PHP_FUNCTION(restore_include_path); 104 105 PHP_FUNCTION(print_r); 106 PHP_FUNCTION(fprintf); 107 PHP_FUNCTION(vfprintf); 108 109 PHP_FUNCTION(connection_aborted); 110 PHP_FUNCTION(connection_status); 111 PHP_FUNCTION(ignore_user_abort); 112 113 PHP_FUNCTION(getservbyname); 114 PHP_FUNCTION(getservbyport); 115 PHP_FUNCTION(getprotobyname); 116 PHP_FUNCTION(getprotobynumber); 117 118 PHP_NAMED_FUNCTION(php_if_crc32); 119 120 PHP_FUNCTION(register_tick_function); 121 PHP_FUNCTION(unregister_tick_function); 122 #ifdef HAVE_GETLOADAVG 123 PHP_FUNCTION(sys_getloadavg); 124 #endif 125 126 PHP_FUNCTION(is_uploaded_file); 127 PHP_FUNCTION(move_uploaded_file); 128 129 /* From the INI parser */ 130 PHP_FUNCTION(parse_ini_file); 131 PHP_FUNCTION(parse_ini_string); 132 #if ZEND_DEBUG 133 PHP_FUNCTION(config_get_hash); 134 #endif 135 136 PHP_FUNCTION(str_rot13); 137 PHP_FUNCTION(stream_get_filters); 138 PHP_FUNCTION(stream_filter_register); 139 PHP_FUNCTION(stream_bucket_make_writeable); 140 PHP_FUNCTION(stream_bucket_prepend); 141 PHP_FUNCTION(stream_bucket_append); 142 PHP_FUNCTION(stream_bucket_new); 143 PHP_MINIT_FUNCTION(user_filters); 144 PHP_RSHUTDOWN_FUNCTION(user_filters); 145 PHP_RSHUTDOWN_FUNCTION(browscap); 146 147 /* Left for BC (not binary safe!) */ 148 PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers); 149 PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers); 150 PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, size_t var_name_len, zend_bool add_underscore); 151 152 #if SIZEOF_INT == 4 153 /* Most 32-bit and 64-bit systems have 32-bit ints */ 154 typedef unsigned int php_uint32; 155 typedef signed int php_int32; 156 #elif SIZEOF_LONG == 4 157 /* 16-bit systems? */ 158 typedef unsigned long php_uint32; 159 typedef signed long php_int32; 160 #else 161 #error Need type which holds 32 bits 162 #endif 163 164 #define MT_N (624) 165 166 typedef struct _php_basic_globals { 167 HashTable *user_shutdown_function_names; 168 HashTable putenv_ht; 169 zval strtok_zval; 170 char *strtok_string; 171 zend_string *locale_string; /* current LC_CTYPE locale (or NULL for 'C') */ 172 zend_bool locale_changed; /* locale was changed and has to be restored */ 173 char *strtok_last; 174 char strtok_table[256]; 175 zend_ulong strtok_len; 176 char str_ebuf[40]; 177 zend_fcall_info array_walk_fci; 178 zend_fcall_info_cache array_walk_fci_cache; 179 zend_fcall_info user_compare_fci; 180 zend_fcall_info_cache user_compare_fci_cache; 181 zend_llist *user_tick_functions; 182 183 zval active_ini_file_section; 184 185 /* pageinfo.c */ 186 zend_long page_uid; 187 zend_long page_gid; 188 zend_long page_inode; 189 time_t page_mtime; 190 191 /* filestat.c && main/streams/streams.c */ 192 char *CurrentStatFile, *CurrentLStatFile; 193 php_stream_statbuf ssb, lssb; 194 195 /* rand.c */ 196 php_uint32 state[MT_N+1]; /* state vector + 1 extra to not violate ANSI C */ 197 php_uint32 *next; /* next random value is computed from here */ 198 int left; /* can *next++ this many times before reloading */ 199 200 unsigned int rand_seed; /* Seed for rand(), in ts version */ 201 202 zend_bool rand_is_seeded; /* Whether rand() has been seeded */ 203 zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */ 204 205 /* syslog.c */ 206 char *syslog_device; 207 208 /* var.c */ 209 zend_class_entry *incomplete_class; 210 unsigned serialize_lock; /* whether to use the locally supplied var_hash instead (__sleep/__wakeup) */ 211 struct { 212 struct php_serialize_data *data; 213 unsigned level; 214 } serialize; 215 struct { 216 struct php_unserialize_data *data; 217 unsigned level; 218 } unserialize; 219 220 /* url_scanner_ex.re */ 221 url_adapt_state_ex_t url_adapt_state_ex; 222 223 #ifdef HAVE_MMAP 224 void *mmap_file; 225 size_t mmap_len; 226 #endif 227 228 HashTable *user_filter_map; 229 230 /* file.c */ 231 #if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T) 232 mbstate_t mblen_state; 233 #endif 234 235 int umask; 236 } php_basic_globals; 237 238 #ifdef ZTS 239 #define BG(v) ZEND_TSRMG(basic_globals_id, php_basic_globals *, v) 240 PHPAPI extern int basic_globals_id; 241 #else 242 #define BG(v) (basic_globals.v) 243 PHPAPI extern php_basic_globals basic_globals; 244 #endif 245 246 #if HAVE_PUTENV 247 typedef struct { 248 char *putenv_string; 249 char *previous_value; 250 char *key; 251 int key_len; 252 } putenv_entry; 253 #endif 254 255 PHPAPI double php_get_nan(void); 256 PHPAPI double php_get_inf(void); 257 258 typedef struct _php_shutdown_function_entry { 259 zval *arguments; 260 int arg_count; 261 } php_shutdown_function_entry; 262 263 PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry); 264 PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len); 265 PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry); 266 267 PHPAPI void php_call_shutdown_functions(void); 268 PHPAPI void php_free_shutdown_functions(void); 269 270 271 #endif /* BASIC_FUNCTIONS_H */ 272