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