… | |
… | |
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_MKDEV_H |
|
|
24 | # include <sys/mkdev.h> |
|
|
25 | #elif HAVE_SYS_SYSMACROS_H |
|
|
26 | # include <sys/sysmacros.h> |
|
|
27 | #endif |
19 | |
28 | |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
29 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
21 | # include <sys/mman.h> |
30 | # include <sys/mman.h> |
22 | #endif |
31 | #endif |
23 | |
32 | |
… | |
… | |
104 | #define expect_false(expr) expect ((expr) != 0, 0) |
113 | #define expect_false(expr) expect ((expr) != 0, 0) |
105 | #define expect_true(expr) expect ((expr) != 0, 1) |
114 | #define expect_true(expr) expect ((expr) != 0, 1) |
106 | |
115 | |
107 | /*****************************************************************************/ |
116 | /*****************************************************************************/ |
108 | |
117 | |
109 | #include "libeio/config.h" |
118 | #include "config.h" |
|
|
119 | |
|
|
120 | #if HAVE_ST_XTIMENSEC |
|
|
121 | # define ATIMENSEC PL_statcache.st_atimensec |
|
|
122 | # define MTIMENSEC PL_statcache.st_mtimensec |
|
|
123 | # define CTIMENSEC PL_statcache.st_ctimensec |
|
|
124 | #elif HAVE_ST_XTIMESPEC |
|
|
125 | # define ATIMENSEC PL_statcache.st_atim.tv_nsec |
|
|
126 | # define MTIMENSEC PL_statcache.st_mtim.tv_nsec |
|
|
127 | # define CTIMENSEC PL_statcache.st_ctim.tv_nsec |
|
|
128 | #else |
|
|
129 | # define ATIMENSEC 0 |
|
|
130 | # define MTIMENSEC 0 |
|
|
131 | # define CTIMENSEC 0 |
|
|
132 | #endif |
|
|
133 | |
|
|
134 | #include "schmorp.h" |
|
|
135 | |
|
|
136 | #if HAVE_EVENTFD |
|
|
137 | # include <sys/eventfd.h> |
|
|
138 | #endif |
|
|
139 | |
|
|
140 | #if HAVE_TIMERFD |
|
|
141 | # include <sys/timerfd.h> |
|
|
142 | #endif |
110 | |
143 | |
111 | #if HAVE_RLIMITS |
144 | #if HAVE_RLIMITS |
112 | #include <sys/time.h> |
145 | #include <sys/time.h> |
113 | #include <sys/resource.h> |
146 | #include <sys/resource.h> |
114 | #endif |
147 | #endif |
… | |
… | |
151 | # else |
184 | # else |
152 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
185 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
153 | # endif |
186 | # endif |
154 | #endif |
187 | #endif |
155 | |
188 | |
156 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
157 | /* also provides const_iv_ and const_niv_ macros for them */ |
|
|
158 | #include "def0.h" |
|
|
159 | |
|
|
160 | #ifndef makedev |
189 | #ifndef makedev |
161 | # define makedev(maj,min) (((maj) << 8) | (min)) |
190 | # define makedev(maj,min) (((maj) << 8) | (min)) |
162 | #endif |
191 | #endif |
163 | #ifndef major |
192 | #ifndef major |
164 | # define major(dev) ((dev) >> 8) |
193 | # define major(dev) ((dev) >> 8) |
165 | #endif |
194 | #endif |
166 | #ifndef minor |
195 | #ifndef minor |
167 | # define minor(dev) ((dev) & 0xff) |
196 | # define minor(dev) ((dev) & 0xff) |
168 | #endif |
197 | #endif |
169 | |
198 | |
|
|
199 | /* solaris has a non-posix/unix compliant PAGESIZE that breaks compilation */ |
|
|
200 | #ifdef __sun |
|
|
201 | # undef PAGESIZE |
|
|
202 | #endif |
|
|
203 | |
170 | #if PAGESIZE <= 0 |
204 | #if PAGESIZE <= 0 |
171 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
205 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
172 | #endif |
206 | #endif |
173 | |
207 | |
174 | /*****************************************************************************/ |
208 | /*****************************************************************************/ |
175 | |
209 | |
176 | #if !_POSIX_MAPPED_FILES |
210 | #if !_POSIX_MAPPED_FILES |
177 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
211 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
178 | # define munmap(addr,length) EIO_ENOSYS () |
212 | # define munmap(addr,length) EIO_ENOSYS () |
179 | #endif |
213 | #endif |
180 | |
214 | |
181 | #if !_POSIX_MEMORY_PROTECTION |
215 | #if !_POSIX_MEMORY_PROTECTION |
182 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
216 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
217 | #endif |
|
|
218 | |
|
|
219 | #if !MREMAP_MAYMOVE |
|
|
220 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
183 | #endif |
221 | #endif |
184 | |
222 | |
185 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
223 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
186 | |
224 | |
187 | static int ecb_cold |
225 | static int ecb_cold |
… | |
… | |
259 | { |
297 | { |
260 | /* todo: iterate over magic and only free ours, but of course */ |
298 | /* todo: iterate over magic and only free ours, but of course */ |
261 | /* the perl5porters will call that (correct) behaviour buggy */ |
299 | /* the perl5porters will call that (correct) behaviour buggy */ |
262 | sv_unmagic (sv, FOREIGN_MAGIC); |
300 | sv_unmagic (sv, FOREIGN_MAGIC); |
263 | } |
301 | } |
|
|
302 | |
|
|
303 | /*****************************************************************************/ |
|
|
304 | |
|
|
305 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
306 | /* also provides const_iv_ and const_niv_ macros for them */ |
|
|
307 | #include "def0.h" |
264 | |
308 | |
265 | /*****************************************************************************/ |
309 | /*****************************************************************************/ |
266 | |
310 | |
267 | static void |
311 | static void |
268 | fiemap (eio_req *req) |
312 | fiemap (eio_req *req) |
… | |
… | |
969 | req_set_path1 (req, fh_or_path); |
1013 | req_set_path1 (req, fh_or_path); |
970 | break; |
1014 | break; |
971 | } |
1015 | } |
972 | } |
1016 | } |
973 | |
1017 | |
|
|
1018 | /*****************************************************************************/ |
|
|
1019 | |
|
|
1020 | static void |
|
|
1021 | ts_set (struct timespec *ts, NV value) |
|
|
1022 | { |
|
|
1023 | ts->tv_sec = value; |
|
|
1024 | ts->tv_nsec = (value - ts->tv_sec) * 1e9; |
|
|
1025 | } |
|
|
1026 | |
|
|
1027 | static NV |
|
|
1028 | ts_get (const struct timespec *ts) |
|
|
1029 | { |
|
|
1030 | return ts->tv_sec + ts->tv_nsec * 1e-9; |
|
|
1031 | } |
|
|
1032 | |
|
|
1033 | /*****************************************************************************/ |
|
|
1034 | |
974 | XS(boot_IO__AIO) ecb_cold; |
1035 | XS(boot_IO__AIO) ecb_cold; |
975 | |
1036 | |
976 | MODULE = IO::AIO PACKAGE = IO::AIO |
1037 | MODULE = IO::AIO PACKAGE = IO::AIO |
977 | |
1038 | |
978 | PROTOTYPES: ENABLE |
1039 | PROTOTYPES: ENABLE |
… | |
… | |
1009 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1070 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1010 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1071 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1011 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1072 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1012 | |
1073 | |
1013 | /* the second block will be 0 when missing */ |
1074 | /* the second block will be 0 when missing */ |
|
|
1075 | const_iv (O_ACCMODE) |
|
|
1076 | |
1014 | const_iv (O_RDONLY) |
1077 | const_iv (O_RDONLY) |
1015 | const_iv (O_WRONLY) |
1078 | const_iv (O_WRONLY) |
1016 | const_iv (O_RDWR) |
1079 | const_iv (O_RDWR) |
1017 | const_iv (O_CREAT) |
1080 | const_iv (O_CREAT) |
1018 | const_iv (O_TRUNC) |
1081 | const_iv (O_TRUNC) |
… | |
… | |
1078 | const_iv (MAP_GROWSDOWN) |
1141 | const_iv (MAP_GROWSDOWN) |
1079 | const_iv (MAP_32BIT) |
1142 | const_iv (MAP_32BIT) |
1080 | const_iv (MAP_HUGETLB) |
1143 | const_iv (MAP_HUGETLB) |
1081 | const_iv (MAP_STACK) |
1144 | const_iv (MAP_STACK) |
1082 | |
1145 | |
|
|
1146 | const_iv (MREMAP_MAYMOVE) |
|
|
1147 | const_iv (MREMAP_FIXED) |
|
|
1148 | |
1083 | const_iv (F_DUPFD_CLOEXEC) |
1149 | const_iv (F_DUPFD_CLOEXEC) |
|
|
1150 | |
|
|
1151 | const_iv (MSG_CMSG_CLOEXEC) |
|
|
1152 | const_iv (SOCK_CLOEXEC) |
1084 | |
1153 | |
1085 | const_iv (F_OFD_GETLK) |
1154 | const_iv (F_OFD_GETLK) |
1086 | const_iv (F_OFD_SETLK) |
1155 | const_iv (F_OFD_SETLK) |
1087 | const_iv (F_OFD_GETLKW) |
1156 | const_iv (F_OFD_GETLKW) |
1088 | |
1157 | |
… | |
… | |
1161 | const_iv (SPLICE_F_MOVE) |
1230 | const_iv (SPLICE_F_MOVE) |
1162 | const_iv (SPLICE_F_NONBLOCK) |
1231 | const_iv (SPLICE_F_NONBLOCK) |
1163 | const_iv (SPLICE_F_MORE) |
1232 | const_iv (SPLICE_F_MORE) |
1164 | const_iv (SPLICE_F_GIFT) |
1233 | const_iv (SPLICE_F_GIFT) |
1165 | |
1234 | |
|
|
1235 | const_iv (EFD_CLOEXEC) |
|
|
1236 | const_iv (EFD_NONBLOCK) |
|
|
1237 | const_iv (EFD_SEMAPHORE) |
|
|
1238 | |
|
|
1239 | const_iv (CLOCK_REALTIME) |
|
|
1240 | const_iv (CLOCK_MONOTONIC) |
|
|
1241 | const_iv (CLOCK_BOOTTIME) |
|
|
1242 | const_iv (CLOCK_REALTIME_ALARM) |
|
|
1243 | const_iv (CLOCK_BOOTTIME_ALARM) |
|
|
1244 | |
|
|
1245 | const_iv (TFD_NONBLOCK) |
|
|
1246 | const_iv (TFD_CLOEXEC) |
|
|
1247 | |
|
|
1248 | const_iv (TFD_TIMER_ABSTIME) |
|
|
1249 | const_iv (TFD_TIMER_CANCEL_ON_SET) |
|
|
1250 | |
1166 | /* these are libeio constants, and are independent of gendef0 */ |
1251 | /* these are libeio constants, and are independent of gendef0 */ |
1167 | const_eio (SEEK_SET) |
1252 | const_eio (SEEK_SET) |
1168 | const_eio (SEEK_CUR) |
1253 | const_eio (SEEK_CUR) |
1169 | const_eio (SEEK_END) |
1254 | const_eio (SEEK_END) |
1170 | |
1255 | |
… | |
… | |
1553 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1638 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1554 | |
1639 | |
1555 | REQ_SEND; |
1640 | REQ_SEND; |
1556 | } |
1641 | } |
1557 | |
1642 | |
|
|
1643 | void |
|
|
1644 | st_xtime () |
|
|
1645 | ALIAS: |
|
|
1646 | st_atime = 1 |
|
|
1647 | st_mtime = 2 |
|
|
1648 | st_ctime = 4 |
|
|
1649 | st_xtime = 7 |
|
|
1650 | PPCODE: |
|
|
1651 | EXTEND (SP, 3); |
|
|
1652 | if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC)); |
|
|
1653 | if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC)); |
|
|
1654 | if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC)); |
|
|
1655 | |
|
|
1656 | void |
|
|
1657 | st_xtimensec () |
|
|
1658 | ALIAS: |
|
|
1659 | st_atimensec = 1 |
|
|
1660 | st_mtimensec = 2 |
|
|
1661 | st_ctimensec = 4 |
|
|
1662 | st_xtimensec = 7 |
|
|
1663 | PPCODE: |
|
|
1664 | EXTEND (SP, 3); |
|
|
1665 | if (ix & 1) PUSHs (newSViv (ATIMENSEC)); |
|
|
1666 | if (ix & 2) PUSHs (newSViv (MTIMENSEC)); |
|
|
1667 | if (ix & 4) PUSHs (newSViv (CTIMENSEC)); |
|
|
1668 | |
1558 | UV |
1669 | UV |
1559 | major (UV dev) |
1670 | major (UV dev) |
1560 | ALIAS: |
1671 | ALIAS: |
1561 | minor = 1 |
1672 | minor = 1 |
1562 | CODE: |
1673 | CODE: |
… | |
… | |
2016 | void |
2127 | void |
2017 | munmap (SV *scalar) |
2128 | munmap (SV *scalar) |
2018 | CODE: |
2129 | CODE: |
2019 | sv_clear_foreign (scalar); |
2130 | sv_clear_foreign (scalar); |
2020 | |
2131 | |
|
|
2132 | SV * |
|
|
2133 | mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0) |
|
|
2134 | CODE: |
|
|
2135 | { |
|
|
2136 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2137 | void *new; |
|
|
2138 | |
|
|
2139 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2140 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2141 | |
|
|
2142 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2143 | |
|
|
2144 | RETVAL = &PL_sv_no; |
|
|
2145 | |
|
|
2146 | if (new != (void *)-1) |
|
|
2147 | { |
|
|
2148 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2149 | ? newSVpvn ("0 but true", 10) |
|
|
2150 | : &PL_sv_yes; |
|
|
2151 | |
|
|
2152 | mg->mg_ptr = (char *)new; |
|
|
2153 | mg->mg_obj = (SV *)new_length; |
|
|
2154 | |
|
|
2155 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2156 | SvCUR_set (scalar, new_length); |
|
|
2157 | } |
|
|
2158 | } |
|
|
2159 | OUTPUT: |
|
|
2160 | RETVAL |
|
|
2161 | |
2021 | int |
2162 | int |
2022 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2163 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2023 | ALIAS: |
2164 | ALIAS: |
2024 | mprotect = 1 |
2165 | mprotect = 1 |
2025 | CODE: |
2166 | CODE: |
… | |
… | |
2154 | { |
2295 | { |
2155 | EXTEND (SP, 2); |
2296 | EXTEND (SP, 2); |
2156 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2297 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2157 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2298 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2158 | } |
2299 | } |
|
|
2300 | } |
|
|
2301 | |
|
|
2302 | void |
|
|
2303 | eventfd (unsigned int initval = 0, int flags = 0) |
|
|
2304 | PPCODE: |
|
|
2305 | { |
|
|
2306 | int fd; |
|
|
2307 | #if HAVE_EVENTFD |
|
|
2308 | fd = eventfd (initval, flags); |
|
|
2309 | #else |
|
|
2310 | fd = (errno = ENOSYS, -1); |
|
|
2311 | #endif |
|
|
2312 | |
|
|
2313 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2314 | } |
|
|
2315 | |
|
|
2316 | void |
|
|
2317 | timerfd_create (int clockid, int flags = 0) |
|
|
2318 | PPCODE: |
|
|
2319 | { |
|
|
2320 | int fd; |
|
|
2321 | #if HAVE_TIMERFD |
|
|
2322 | fd = timerfd_create (clockid, flags); |
|
|
2323 | #else |
|
|
2324 | fd = (errno = ENOSYS, -1); |
|
|
2325 | #endif |
|
|
2326 | |
|
|
2327 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2328 | } |
|
|
2329 | |
|
|
2330 | void |
|
|
2331 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
|
|
2332 | PPCODE: |
|
|
2333 | { |
|
|
2334 | int fd = s_fileno_croak (fh, 0); |
|
|
2335 | #if HAVE_TIMERFD |
|
|
2336 | int res; |
|
|
2337 | struct itimerspec its, ots; |
|
|
2338 | |
|
|
2339 | ts_set (&its.it_interval, interval); |
|
|
2340 | ts_set (&its.it_value , value); |
|
|
2341 | res = timerfd_settime (fd, flags, &its, &ots); |
|
|
2342 | |
|
|
2343 | if (!res) |
|
|
2344 | { |
|
|
2345 | EXTEND (SP, 2); |
|
|
2346 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2347 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2348 | } |
|
|
2349 | #else |
|
|
2350 | errno = ENOSYS; |
|
|
2351 | #endif |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | void |
|
|
2355 | timerfd_gettime (SV *fh) |
|
|
2356 | PPCODE: |
|
|
2357 | { |
|
|
2358 | int fd = s_fileno_croak (fh, 0); |
|
|
2359 | #if HAVE_TIMERFD |
|
|
2360 | int res; |
|
|
2361 | struct itimerspec ots; |
|
|
2362 | res = timerfd_gettime (fd, &ots); |
|
|
2363 | |
|
|
2364 | if (!res) |
|
|
2365 | { |
|
|
2366 | EXTEND (SP, 2); |
|
|
2367 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2368 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2369 | } |
|
|
2370 | #else |
|
|
2371 | errno = ENOSYS; |
|
|
2372 | #endif |
2159 | } |
2373 | } |
2160 | |
2374 | |
2161 | UV |
2375 | UV |
2162 | get_fdlimit () |
2376 | get_fdlimit () |
2163 | CODE: |
2377 | CODE: |