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    | Author: Ruslan Osmanov <osmanov@php.net>                             |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef EIO_PRIV_H
20 #  define EIO_PRIV_H
21 
22 extern const zend_function_entry eio_functions[];
23 
24 #ifndef TRUE
25 # define TRUE 1
26 #endif
27 
28 #ifndef FALSE
29 # define FALSE 0
30 #endif
31 
32 
33 #define PHP_EIO_GRP_DESCRIPTOR_NAME "EIO Group Descriptor"
34 #define PHP_EIO_REQ_DESCRIPTOR_NAME "EIO Request Descriptor"
35 
36 /* {{{ Macros */
37 
38 #ifdef EIO_DEBUG
39 # define PHP_EIO_RET_IF_FAILED(req, eio_func) \
40 	if (!req || (req->result != 0 && req->errorno)) { \
41 		php_error_docref(NULL, \
42 				E_WARNING, #eio_func " failed: %s", strerror(req->errorno)); \
43 		RETURN_FALSE; \
44 	}
45 #else
46 # define PHP_EIO_RET_IF_FAILED(req, eio_func) \
47 	if (!req || req->result != 0) RETURN_FALSE;
48 #endif
49 
50 #define PHP_EIO_RET_REQ_RESOURCE(req, eio_func) do { \
51 	PHP_EIO_RET_IF_FAILED(req, eio_func); \
52 	RETURN_RES(zend_register_resource(req, le_eio_req)); \
53 } while (0)
54 
55 #define PHP_EIO_IS_INIT() \
56 { \
57 	if (php_eio_pid <= 0 || php_eio_pipe.len == 0) { \
58 		php_eio_init(); \
59 	} \
60 }
61 
62 #define PHP_EIO_SETFD_CLOEXEC(fd) \
63 { \
64 	if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { \
65 		php_error_docref(NULL, \
66 				E_WARNING, "Failed to set FD_CLOEXEC on descriptor"); \
67 	} \
68 }
69 
70 
71 #define PHP_EIO_INIT \
72 	zend_long           pri    = EIO_PRI_DEFAULT; \
73 	zval               *zcb    = NULL;            \
74 	zval               *data   = NULL;            \
75 	php_eio_cb_t       *eio_cb;                   \
76 	eio_req            *req;                      \
77 	PHP_EIO_IS_INIT();
78 
79 #ifdef EIO_DEBUG
80 # define EIO_CHECK_PATH_LEN(path, path_len) \
81 	if (strlen(path) != path_len) { \
82 		php_error_docref(NULL, E_WARNING, \
83 				"failed calculating path length"); \
84 		RETURN_FALSE; \
85 	}
86 #else
87 # define EIO_CHECK_PATH_LEN(path, path_len) \
88 	if (strlen(path) != path_len) { \
89 		RETURN_FALSE; \
90 	}
91 #endif
92 
93 #define EIO_REGISTER_LONG_EIO_CONSTANT(name) \
94 	REGISTER_LONG_CONSTANT(#name, name, CONST_CS | CONST_PERSISTENT);
95 
96 #define EIO_REGISTER_LONG_CONSTANT(name, value) \
97 	REGISTER_LONG_CONSTANT(#name, value, CONST_CS | CONST_PERSISTENT);
98 
99 #define EIO_CB_CUSTOM_IS_LOCKED(eio_cb) ((eio_cb) ? (eio_cb)->locked : 0)
100 
101 /* }}} */
102 
103 /* {{{ Types */
104 
105 typedef struct _php_eio_func_info {
106 	zend_function    *func_ptr;
107 	zend_class_entry *ce;
108 	zval              obj;
109 	zval              closure;
110 } php_eio_func_info;
111 
112 typedef struct {
113 	php_eio_func_info func;
114 	zval              arg;    /* callback argument */
115 #ifdef ZTS
116 	void*** ls;
117 #endif
118 } php_eio_cb_t;
119 
120 typedef struct {
121 	zval              arg;         /* callback argument */
122 	zend_bool         locked;
123 	php_eio_func_info func_exec;
124 	php_eio_func_info func;
125 #ifdef ZTS
126 	void*** ls;
127 #endif
128 } php_eio_cb_custom_t;
129 
130 typedef struct {
131 	int fd[2];
132 	int len; /* 1 for pipe, 8 for eventfd */
133 } php_eio_pipe_t;
134 
135 /* }}} */
136 
137 #endif	/* EIO_PRIV_H */
138 /*
139  * vim600: fdm=marker
140  * vim: noet sts=4 sw=4 ts=4
141  */
142