… | |
… | |
4 | |
4 | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
8 | |
8 | |
9 | #include "schmorp.h" |
9 | #if !defined mg_findext |
|
|
10 | # define mg_findext(sv,type,vtbl) mg_find (sv, type) |
|
|
11 | #endif |
10 | |
12 | |
11 | #include <stddef.h> |
13 | #include <stddef.h> |
12 | #include <stdlib.h> |
14 | #include <stdlib.h> |
13 | #include <errno.h> |
15 | #include <errno.h> |
14 | #include <sys/types.h> |
16 | #include <sys/types.h> |
|
|
17 | #include <sys/socket.h> |
15 | #include <sys/stat.h> |
18 | #include <sys/stat.h> |
16 | #include <limits.h> |
19 | #include <limits.h> |
17 | #include <fcntl.h> |
20 | #include <fcntl.h> |
18 | #include <sched.h> |
21 | #include <sched.h> |
|
|
22 | |
|
|
23 | #if HAVE_SYS_SYSMACROS_H |
|
|
24 | # include <sys/sysmacros.h> |
|
|
25 | #endif |
19 | |
26 | |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
27 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
21 | # include <sys/mman.h> |
28 | # include <sys/mman.h> |
22 | #endif |
29 | #endif |
23 | |
30 | |
… | |
… | |
104 | #define expect_false(expr) expect ((expr) != 0, 0) |
111 | #define expect_false(expr) expect ((expr) != 0, 0) |
105 | #define expect_true(expr) expect ((expr) != 0, 1) |
112 | #define expect_true(expr) expect ((expr) != 0, 1) |
106 | |
113 | |
107 | /*****************************************************************************/ |
114 | /*****************************************************************************/ |
108 | |
115 | |
109 | #include "libeio/config.h" |
116 | #include "config.h" |
|
|
117 | |
|
|
118 | #if HAVE_ST_XTIMENSEC |
|
|
119 | # define ATIMENSEC PL_statcache.st_atimensec |
|
|
120 | # define MTIMENSEC PL_statcache.st_mtimensec |
|
|
121 | # define CTIMENSEC PL_statcache.st_ctimensec |
|
|
122 | #elif HAVE_ST_XTIMESPEC |
|
|
123 | # define ATIMENSEC PL_statcache.st_atim.tv_nsec |
|
|
124 | # define MTIMENSEC PL_statcache.st_mtim.tv_nsec |
|
|
125 | # define CTIMENSEC PL_statcache.st_ctim.tv_nsec |
|
|
126 | #else |
|
|
127 | # define ATIMENSEC 0 |
|
|
128 | # define MTIMENSEC 0 |
|
|
129 | # define CTIMENSEC 0 |
|
|
130 | #endif |
|
|
131 | |
|
|
132 | #include "schmorp.h" |
110 | |
133 | |
111 | #if HAVE_EVENTFD |
134 | #if HAVE_EVENTFD |
112 | # include <sys/eventfd.h> |
135 | # include <sys/eventfd.h> |
113 | #endif |
136 | #endif |
114 | |
137 | |
… | |
… | |
159 | # else |
182 | # else |
160 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
183 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
161 | # endif |
184 | # endif |
162 | #endif |
185 | #endif |
163 | |
186 | |
164 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
165 | /* also provides const_iv_ and const_niv_ macros for them */ |
|
|
166 | #include "def0.h" |
|
|
167 | |
|
|
168 | #ifndef makedev |
187 | #ifndef makedev |
169 | # define makedev(maj,min) (((maj) << 8) | (min)) |
188 | # define makedev(maj,min) (((maj) << 8) | (min)) |
170 | #endif |
189 | #endif |
171 | #ifndef major |
190 | #ifndef major |
172 | # define major(dev) ((dev) >> 8) |
191 | # define major(dev) ((dev) >> 8) |
… | |
… | |
180 | #endif |
199 | #endif |
181 | |
200 | |
182 | /*****************************************************************************/ |
201 | /*****************************************************************************/ |
183 | |
202 | |
184 | #if !_POSIX_MAPPED_FILES |
203 | #if !_POSIX_MAPPED_FILES |
185 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
204 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
186 | # define munmap(addr,length) EIO_ENOSYS () |
205 | # define munmap(addr,length) EIO_ENOSYS () |
187 | #endif |
206 | #endif |
188 | |
207 | |
189 | #if !_POSIX_MEMORY_PROTECTION |
208 | #if !_POSIX_MEMORY_PROTECTION |
190 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
209 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
210 | #endif |
|
|
211 | |
|
|
212 | #if !MREMAP_MAYMOVE |
|
|
213 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
191 | #endif |
214 | #endif |
192 | |
215 | |
193 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
216 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
194 | |
217 | |
195 | static int ecb_cold |
218 | static int ecb_cold |
… | |
… | |
267 | { |
290 | { |
268 | /* todo: iterate over magic and only free ours, but of course */ |
291 | /* todo: iterate over magic and only free ours, but of course */ |
269 | /* the perl5porters will call that (correct) behaviour buggy */ |
292 | /* the perl5porters will call that (correct) behaviour buggy */ |
270 | sv_unmagic (sv, FOREIGN_MAGIC); |
293 | sv_unmagic (sv, FOREIGN_MAGIC); |
271 | } |
294 | } |
|
|
295 | |
|
|
296 | /*****************************************************************************/ |
|
|
297 | |
|
|
298 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
299 | /* also provides const_iv_ and const_niv_ macros for them */ |
|
|
300 | #include "def0.h" |
272 | |
301 | |
273 | /*****************************************************************************/ |
302 | /*****************************************************************************/ |
274 | |
303 | |
275 | static void |
304 | static void |
276 | fiemap (eio_req *req) |
305 | fiemap (eio_req *req) |
… | |
… | |
1034 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1063 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1035 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1064 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1036 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1065 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1037 | |
1066 | |
1038 | /* the second block will be 0 when missing */ |
1067 | /* the second block will be 0 when missing */ |
|
|
1068 | const_iv (O_ACCMODE) |
|
|
1069 | |
1039 | const_iv (O_RDONLY) |
1070 | const_iv (O_RDONLY) |
1040 | const_iv (O_WRONLY) |
1071 | const_iv (O_WRONLY) |
1041 | const_iv (O_RDWR) |
1072 | const_iv (O_RDWR) |
1042 | const_iv (O_CREAT) |
1073 | const_iv (O_CREAT) |
1043 | const_iv (O_TRUNC) |
1074 | const_iv (O_TRUNC) |
… | |
… | |
1103 | const_iv (MAP_GROWSDOWN) |
1134 | const_iv (MAP_GROWSDOWN) |
1104 | const_iv (MAP_32BIT) |
1135 | const_iv (MAP_32BIT) |
1105 | const_iv (MAP_HUGETLB) |
1136 | const_iv (MAP_HUGETLB) |
1106 | const_iv (MAP_STACK) |
1137 | const_iv (MAP_STACK) |
1107 | |
1138 | |
|
|
1139 | const_iv (MREMAP_MAYMOVE) |
|
|
1140 | const_iv (MREMAP_FIXED) |
|
|
1141 | |
1108 | const_iv (F_DUPFD_CLOEXEC) |
1142 | const_iv (F_DUPFD_CLOEXEC) |
|
|
1143 | |
|
|
1144 | const_iv (MSG_CMSG_CLOEXEC) |
|
|
1145 | const_iv (SOCK_CLOEXEC) |
1109 | |
1146 | |
1110 | const_iv (F_OFD_GETLK) |
1147 | const_iv (F_OFD_GETLK) |
1111 | const_iv (F_OFD_SETLK) |
1148 | const_iv (F_OFD_SETLK) |
1112 | const_iv (F_OFD_GETLKW) |
1149 | const_iv (F_OFD_GETLKW) |
1113 | |
1150 | |
… | |
… | |
1594 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1631 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1595 | |
1632 | |
1596 | REQ_SEND; |
1633 | REQ_SEND; |
1597 | } |
1634 | } |
1598 | |
1635 | |
|
|
1636 | void |
|
|
1637 | st_xtime () |
|
|
1638 | ALIAS: |
|
|
1639 | st_atime = 1 |
|
|
1640 | st_mtime = 2 |
|
|
1641 | st_ctime = 4 |
|
|
1642 | st_xtime = 7 |
|
|
1643 | PPCODE: |
|
|
1644 | EXTEND (SP, 3); |
|
|
1645 | if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC)); |
|
|
1646 | if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC)); |
|
|
1647 | if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC)); |
|
|
1648 | |
|
|
1649 | void |
|
|
1650 | st_xtimensec () |
|
|
1651 | ALIAS: |
|
|
1652 | st_atimensec = 1 |
|
|
1653 | st_mtimensec = 2 |
|
|
1654 | st_ctimensec = 4 |
|
|
1655 | st_xtimensec = 7 |
|
|
1656 | PPCODE: |
|
|
1657 | EXTEND (SP, 3); |
|
|
1658 | if (ix & 1) PUSHs (newSViv (ATIMENSEC)); |
|
|
1659 | if (ix & 2) PUSHs (newSViv (MTIMENSEC)); |
|
|
1660 | if (ix & 4) PUSHs (newSViv (CTIMENSEC)); |
|
|
1661 | |
1599 | UV |
1662 | UV |
1600 | major (UV dev) |
1663 | major (UV dev) |
1601 | ALIAS: |
1664 | ALIAS: |
1602 | minor = 1 |
1665 | minor = 1 |
1603 | CODE: |
1666 | CODE: |
… | |
… | |
2057 | void |
2120 | void |
2058 | munmap (SV *scalar) |
2121 | munmap (SV *scalar) |
2059 | CODE: |
2122 | CODE: |
2060 | sv_clear_foreign (scalar); |
2123 | sv_clear_foreign (scalar); |
2061 | |
2124 | |
|
|
2125 | SV * |
|
|
2126 | mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0) |
|
|
2127 | CODE: |
|
|
2128 | { |
|
|
2129 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2130 | void *new; |
|
|
2131 | |
|
|
2132 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2133 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2134 | |
|
|
2135 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2136 | |
|
|
2137 | RETVAL = &PL_sv_no; |
|
|
2138 | |
|
|
2139 | if (new != (void *)-1) |
|
|
2140 | { |
|
|
2141 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2142 | ? newSVpvn ("0 but true", 10) |
|
|
2143 | : &PL_sv_yes; |
|
|
2144 | |
|
|
2145 | mg->mg_ptr = (char *)new; |
|
|
2146 | mg->mg_obj = (SV *)new_length; |
|
|
2147 | |
|
|
2148 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2149 | SvCUR_set (scalar, new_length); |
|
|
2150 | } |
|
|
2151 | } |
|
|
2152 | OUTPUT: |
|
|
2153 | RETVAL |
|
|
2154 | |
2062 | int |
2155 | int |
2063 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2156 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2064 | ALIAS: |
2157 | ALIAS: |
2065 | mprotect = 1 |
2158 | mprotect = 1 |
2066 | CODE: |
2159 | CODE: |
… | |
… | |
2230 | void |
2323 | void |
2231 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2324 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2232 | PPCODE: |
2325 | PPCODE: |
2233 | { |
2326 | { |
2234 | int fd = s_fileno_croak (fh, 0); |
2327 | int fd = s_fileno_croak (fh, 0); |
|
|
2328 | #if HAVE_TIMERFD |
2235 | int res; |
2329 | int res; |
2236 | struct itimerspec its, ots; |
2330 | struct itimerspec its, ots; |
2237 | |
2331 | |
2238 | ts_set (&its.it_interval, interval); |
2332 | ts_set (&its.it_interval, interval); |
2239 | ts_set (&its.it_value , value); |
2333 | ts_set (&its.it_value , value); |
2240 | #if HAVE_TIMERFD |
|
|
2241 | res = timerfd_settime (fd, flags, &its, &ots); |
2334 | res = timerfd_settime (fd, flags, &its, &ots); |
2242 | #else |
|
|
2243 | res = (errno = ENOSYS, -1); |
|
|
2244 | #endif |
|
|
2245 | |
2335 | |
2246 | if (!res) |
2336 | if (!res) |
2247 | { |
2337 | { |
2248 | EXTEND (SP, 2); |
2338 | EXTEND (SP, 2); |
2249 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2339 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2250 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2340 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2251 | } |
2341 | } |
|
|
2342 | #else |
|
|
2343 | errno = ENOSYS; |
|
|
2344 | #endif |
2252 | } |
2345 | } |
2253 | |
2346 | |
2254 | void |
2347 | void |
2255 | timerfd_gettime (SV *fh) |
2348 | timerfd_gettime (SV *fh) |
2256 | PPCODE: |
2349 | PPCODE: |
2257 | { |
2350 | { |
2258 | int fd = s_fileno_croak (fh, 0); |
2351 | int fd = s_fileno_croak (fh, 0); |
|
|
2352 | #if HAVE_TIMERFD |
2259 | int res; |
2353 | int res; |
2260 | struct itimerspec ots; |
2354 | struct itimerspec ots; |
2261 | #if HAVE_TIMERFD |
|
|
2262 | res = timerfd_gettime (fd, &ots); |
2355 | res = timerfd_gettime (fd, &ots); |
2263 | #else |
|
|
2264 | res = (errno = ENOSYS, -1); |
|
|
2265 | #endif |
|
|
2266 | |
2356 | |
2267 | if (!res) |
2357 | if (!res) |
2268 | { |
2358 | { |
2269 | EXTEND (SP, 2); |
2359 | EXTEND (SP, 2); |
2270 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2360 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2271 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2361 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2272 | } |
2362 | } |
|
|
2363 | #else |
|
|
2364 | errno = ENOSYS; |
|
|
2365 | #endif |
2273 | } |
2366 | } |
2274 | |
2367 | |
2275 | UV |
2368 | UV |
2276 | get_fdlimit () |
2369 | get_fdlimit () |
2277 | CODE: |
2370 | CODE: |