xref: /PHP-7.4/main/php.h (revision ea3c992b)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 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@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    +----------------------------------------------------------------------+
18  */
19 
20 #ifndef PHP_H
21 #define PHP_H
22 
23 #ifdef HAVE_DMALLOC
24 #include <dmalloc.h>
25 #endif
26 
27 #define PHP_API_VERSION 20190902
28 #define PHP_HAVE_STREAMS
29 #define YYDEBUG 0
30 #define PHP_DEFAULT_CHARSET "UTF-8"
31 
32 #include "php_version.h"
33 #include "zend.h"
34 #include "zend_sort.h"
35 #include "php_compat.h"
36 
37 #include "zend_API.h"
38 
39 #define php_sprintf sprintf
40 
41 /* Operating system family definition */
42 #ifdef PHP_WIN32
43 # define PHP_OS_FAMILY			"Windows"
44 #elif defined(BSD) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
45 # define PHP_OS_FAMILY			"BSD"
46 #elif defined(__APPLE__) || defined(__MACH__)
47 # define PHP_OS_FAMILY			"Darwin"
48 #elif defined(__sun__)
49 # define PHP_OS_FAMILY			"Solaris"
50 #elif defined(__linux__)
51 # define PHP_OS_FAMILY			"Linux"
52 #else
53 # define PHP_OS_FAMILY			"Unknown"
54 #endif
55 
56 /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */
57 #undef PHP_DEBUG
58 #define PHP_DEBUG ZEND_DEBUG
59 
60 #ifdef PHP_WIN32
61 #	include "tsrm_win32.h"
62 #	ifdef PHP_EXPORTS
63 #		define PHPAPI __declspec(dllexport)
64 #	else
65 #		define PHPAPI __declspec(dllimport)
66 #	endif
67 #	define PHP_DIR_SEPARATOR '\\'
68 #	define PHP_EOL "\r\n"
69 #else
70 #	if defined(__GNUC__) && __GNUC__ >= 4
71 #		define PHPAPI __attribute__ ((visibility("default")))
72 #	else
73 #		define PHPAPI
74 #	endif
75 #	define THREAD_LS
76 #	define PHP_DIR_SEPARATOR '/'
77 #	define PHP_EOL "\n"
78 #endif
79 
80 /* Windows specific defines */
81 #ifdef PHP_WIN32
82 # define PHP_PROG_SENDMAIL		"Built in mailer"
83 # define WIN32_LEAN_AND_MEAN
84 # define NOOPENFILE
85 
86 # include <io.h>
87 # include <malloc.h>
88 # include <direct.h>
89 # include <stdlib.h>
90 # include <stdio.h>
91 # include <stdarg.h>
92 # include <sys/types.h>
93 # include <process.h>
94 
95 typedef int uid_t;
96 typedef int gid_t;
97 typedef char * caddr_t;
98 typedef int pid_t;
99 
100 # ifndef PHP_DEBUG
101 #  ifdef inline
102 #   undef inline
103 #  endif
104 #  define inline		__inline
105 # endif
106 
107 # define M_TWOPI        (M_PI * 2.0)
108 # define off_t			_off_t
109 
110 # define lstat(x, y)	php_sys_lstat(x, y)
111 # define chdir(path)	_chdir(path)
112 # define mkdir(a, b)	_mkdir(a)
113 # define rmdir(a)		_rmdir(a)
114 # define getpid			_getpid
115 # define php_sleep(t)	SleepEx(t*1000, TRUE)
116 
117 # ifndef getcwd
118 #  define getcwd(a, b)	_getcwd(a, b)
119 # endif
120 #endif
121 
122 #if PHP_DEBUG
123 #undef NDEBUG
124 #else
125 #ifndef NDEBUG
126 #define NDEBUG
127 #endif
128 #endif
129 #include <assert.h>
130 
131 #if HAVE_UNIX_H
132 #include <unix.h>
133 #endif
134 
135 #if HAVE_ALLOCA_H
136 #include <alloca.h>
137 #endif
138 
139 #if HAVE_BUILD_DEFS_H
140 #include <build-defs.h>
141 #endif
142 
143 /*
144  * This is a fast version of strlcpy which should be used, if you
145  * know the size of the destination buffer and if you know
146  * the length of the source string.
147  *
148  * size is the allocated number of bytes of dst
149  * src_size is the number of bytes excluding the NUL of src
150  */
151 
152 #define PHP_STRLCPY(dst, src, size, src_size)	\
153 	{											\
154 		size_t php_str_len;						\
155 												\
156 		if (src_size >= size)					\
157 			php_str_len = size - 1;				\
158 		else									\
159 			php_str_len = src_size;				\
160 		memcpy(dst, src, php_str_len);			\
161 		dst[php_str_len] = '\0';				\
162 	}
163 
164 #ifndef HAVE_STRLCPY
165 BEGIN_EXTERN_C()
166 PHPAPI size_t php_strlcpy(char *dst, const char *src, size_t siz);
167 END_EXTERN_C()
168 #undef strlcpy
169 #define strlcpy php_strlcpy
170 #define HAVE_STRLCPY 1
171 #define USE_STRLCPY_PHP_IMPL 1
172 #endif
173 
174 #ifndef HAVE_STRLCAT
175 BEGIN_EXTERN_C()
176 PHPAPI size_t php_strlcat(char *dst, const char *src, size_t siz);
177 END_EXTERN_C()
178 #undef strlcat
179 #define strlcat php_strlcat
180 #define HAVE_STRLCAT 1
181 #define USE_STRLCAT_PHP_IMPL 1
182 #endif
183 
184 #ifndef HAVE_EXPLICIT_BZERO
185 BEGIN_EXTERN_C()
186 PHPAPI void php_explicit_bzero(void *dst, size_t siz);
187 END_EXTERN_C()
188 #undef explicit_bzero
189 #define explicit_bzero php_explicit_bzero
190 #endif
191 
192 #ifndef HAVE_STRTOK_R
193 BEGIN_EXTERN_C()
194 char *strtok_r(char *s, const char *delim, char **last);
195 END_EXTERN_C()
196 #endif
197 
198 #ifndef HAVE_SOCKLEN_T
199 # ifdef PHP_WIN32
200 typedef int socklen_t;
201 # else
202 typedef unsigned int socklen_t;
203 # endif
204 #endif
205 
206 #define CREATE_MUTEX(a, b)
207 #define SET_MUTEX(a)
208 #define FREE_MUTEX(a)
209 
210 /*
211  * Then the ODBC support can use both iodbc and Solid,
212  * uncomment this.
213  * #define HAVE_ODBC (HAVE_IODBC|HAVE_SOLID)
214  */
215 
216 #include <stdlib.h>
217 #include <ctype.h>
218 #if HAVE_UNISTD_H
219 #include <unistd.h>
220 #endif
221 
222 #include <stdarg.h>
223 
224 #include "php_stdint.h"
225 
226 #include "zend_hash.h"
227 #include "zend_alloc.h"
228 #include "zend_stack.h"
229 #include <string.h>
230 
231 #if HAVE_PWD_H
232 # ifdef PHP_WIN32
233 #include "win32/param.h"
234 # else
235 #include <pwd.h>
236 #include <sys/param.h>
237 # endif
238 #endif
239 
240 #include <limits.h>
241 
242 #ifndef LONG_MAX
243 #define LONG_MAX 2147483647L
244 #endif
245 
246 #ifndef LONG_MIN
247 #define LONG_MIN (- LONG_MAX - 1)
248 #endif
249 
250 #ifndef INT_MAX
251 #define INT_MAX 2147483647
252 #endif
253 
254 #ifndef INT_MIN
255 #define INT_MIN (- INT_MAX - 1)
256 #endif
257 
258 /* double limits */
259 #include <float.h>
260 #if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP)
261 #define PHP_DOUBLE_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP)
262 #else
263 #define PHP_DOUBLE_MAX_LENGTH 1080
264 #endif
265 
266 #define PHP_GCC_VERSION ZEND_GCC_VERSION
267 #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
268 #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
269 
270 BEGIN_EXTERN_C()
271 #include "snprintf.h"
272 END_EXTERN_C()
273 #include "spprintf.h"
274 
275 #define EXEC_INPUT_BUF 4096
276 
277 #define PHP_MIME_TYPE "application/x-httpd-php"
278 
279 /* macros */
280 #define STR_PRINT(str)	((str)?(str):"")
281 
282 #ifndef MAXPATHLEN
283 # ifdef PHP_WIN32
284 #  include "win32/ioutil.h"
285 #  define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
286 # elif PATH_MAX
287 #  define MAXPATHLEN PATH_MAX
288 # elif defined(MAX_PATH)
289 #  define MAXPATHLEN MAX_PATH
290 # else
291 #  define MAXPATHLEN 256    /* Should be safe for any weird systems that do not define it */
292 # endif
293 #endif
294 
295 #define php_ignore_value(x) ZEND_IGNORE_VALUE(x)
296 
297 /* global variables */
298 #if !defined(PHP_WIN32)
299 #define PHP_SLEEP_NON_VOID
300 #define php_sleep sleep
301 extern char **environ;
302 #endif	/* !defined(PHP_WIN32) */
303 
304 #ifdef PHP_PWRITE_64
305 ssize_t pwrite(int, void *, size_t, off64_t);
306 #endif
307 
308 #ifdef PHP_PREAD_64
309 ssize_t pread(int, void *, size_t, off64_t);
310 #endif
311 
312 BEGIN_EXTERN_C()
313 void phperror(char *error);
314 PHPAPI size_t php_write(void *buf, size_t size);
315 PHPAPI size_t php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1,
316 		2);
317 PHPAPI int php_get_module_initialized(void);
318 #ifdef HAVE_SYSLOG_H
319 #include "php_syslog.h"
320 #define php_log_err(msg) php_log_err_with_severity(msg, LOG_NOTICE)
321 #else
322 #define php_log_err(msg) php_log_err_with_severity(msg, 5)
323 #endif
324 PHPAPI ZEND_COLD void php_log_err_with_severity(char *log_message, int syslog_type_int);
325 int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
326 int cfgparse(void);
327 END_EXTERN_C()
328 
329 #define php_error zend_error
330 #define error_handling_t zend_error_handling_t
331 
BEGIN_EXTERN_C()332 BEGIN_EXTERN_C()
333 static inline ZEND_ATTRIBUTE_DEPRECATED void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class)
334 {
335 	zend_replace_error_handling(error_handling, exception_class, NULL);
336 }
php_std_error_handling()337 static inline ZEND_ATTRIBUTE_DEPRECATED void php_std_error_handling() {}
338 
339 PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args) PHP_ATTRIBUTE_FORMAT(printf, 4, 0);
340 
341 /* PHPAPI void php_error(int type, const char *format, ...); */
342 PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format, ...)
343 	PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
344 PHPAPI ZEND_COLD void php_error_docref1(const char *docref, const char *param1, int type, const char *format, ...)
345 	PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
346 PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
347 	PHP_ATTRIBUTE_FORMAT(printf, 5, 6);
348 #ifdef PHP_WIN32
349 PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1);
350 PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2);
351 #endif
352 END_EXTERN_C()
353 
354 #define zenderror phperror
355 #define zendlex phplex
356 
357 #define phpparse zendparse
358 #define phprestart zendrestart
359 #define phpin zendin
360 
361 #define php_memnstr zend_memnstr
362 
363 /* functions */
364 BEGIN_EXTERN_C()
365 PHPAPI extern int (*php_register_internal_extensions_func)(void);
366 PHPAPI int php_register_internal_extensions(void);
367 PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *));
368 PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
369 PHPAPI void php_com_initialize(void);
370 PHPAPI char *php_get_current_user(void);
371 
372 PHPAPI const char *php_get_internal_encoding(void);
373 PHPAPI const char *php_get_input_encoding(void);
374 PHPAPI const char *php_get_output_encoding(void);
375 PHPAPI extern void (*php_internal_encoding_changed)(void);
376 END_EXTERN_C()
377 
378 /* PHP-named Zend macro wrappers */
379 #define PHP_FN					ZEND_FN
380 #define PHP_MN					ZEND_MN
381 #define PHP_NAMED_FUNCTION		ZEND_NAMED_FUNCTION
382 #define PHP_FUNCTION			ZEND_FUNCTION
383 #define PHP_METHOD  			ZEND_METHOD
384 
385 #define PHP_RAW_NAMED_FE ZEND_RAW_NAMED_FE
386 #define PHP_NAMED_FE	ZEND_NAMED_FE
387 #define PHP_FE			ZEND_FE
388 #define PHP_DEP_FE      ZEND_DEP_FE
389 #define PHP_FALIAS		ZEND_FALIAS
390 #define PHP_DEP_FALIAS	ZEND_DEP_FALIAS
391 #define PHP_ME          ZEND_ME
392 #define PHP_MALIAS      ZEND_MALIAS
393 #define PHP_ABSTRACT_ME ZEND_ABSTRACT_ME
394 #define PHP_ME_MAPPING  ZEND_ME_MAPPING
395 #define PHP_FE_END      ZEND_FE_END
396 
397 #define PHP_MODULE_STARTUP_N	ZEND_MODULE_STARTUP_N
398 #define PHP_MODULE_SHUTDOWN_N	ZEND_MODULE_SHUTDOWN_N
399 #define PHP_MODULE_ACTIVATE_N	ZEND_MODULE_ACTIVATE_N
400 #define PHP_MODULE_DEACTIVATE_N	ZEND_MODULE_DEACTIVATE_N
401 #define PHP_MODULE_INFO_N		ZEND_MODULE_INFO_N
402 
403 #define PHP_MODULE_STARTUP_D	ZEND_MODULE_STARTUP_D
404 #define PHP_MODULE_SHUTDOWN_D	ZEND_MODULE_SHUTDOWN_D
405 #define PHP_MODULE_ACTIVATE_D	ZEND_MODULE_ACTIVATE_D
406 #define PHP_MODULE_DEACTIVATE_D	ZEND_MODULE_DEACTIVATE_D
407 #define PHP_MODULE_INFO_D		ZEND_MODULE_INFO_D
408 
409 /* Compatibility macros */
410 #define PHP_MINIT		ZEND_MODULE_STARTUP_N
411 #define PHP_MSHUTDOWN	ZEND_MODULE_SHUTDOWN_N
412 #define PHP_RINIT		ZEND_MODULE_ACTIVATE_N
413 #define PHP_RSHUTDOWN	ZEND_MODULE_DEACTIVATE_N
414 #define PHP_MINFO		ZEND_MODULE_INFO_N
415 #define PHP_GINIT		ZEND_GINIT
416 #define PHP_GSHUTDOWN	ZEND_GSHUTDOWN
417 
418 #define PHP_MINIT_FUNCTION		ZEND_MODULE_STARTUP_D
419 #define PHP_MSHUTDOWN_FUNCTION	ZEND_MODULE_SHUTDOWN_D
420 #define PHP_RINIT_FUNCTION		ZEND_MODULE_ACTIVATE_D
421 #define PHP_RSHUTDOWN_FUNCTION	ZEND_MODULE_DEACTIVATE_D
422 #define PHP_MINFO_FUNCTION		ZEND_MODULE_INFO_D
423 #define PHP_GINIT_FUNCTION		ZEND_GINIT_FUNCTION
424 #define PHP_GSHUTDOWN_FUNCTION	ZEND_GSHUTDOWN_FUNCTION
425 
426 #define PHP_MODULE_GLOBALS		ZEND_MODULE_GLOBALS
427 
428 
429 /* Output support */
430 #include "main/php_output.h"
431 
432 
433 #include "php_streams.h"
434 #include "php_memory_streams.h"
435 #include "fopen_wrappers.h"
436 
437 
438 /* Virtual current working directory support */
439 #include "zend_virtual_cwd.h"
440 
441 #include "zend_constants.h"
442 
443 /* connection status states */
444 #define PHP_CONNECTION_NORMAL  0
445 #define PHP_CONNECTION_ABORTED 1
446 #define PHP_CONNECTION_TIMEOUT 2
447 
448 #include "php_reentrancy.h"
449 
450 #endif
451