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