… | |
… | |
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> |
… | |
… | |
106 | |
108 | |
107 | /*****************************************************************************/ |
109 | /*****************************************************************************/ |
108 | |
110 | |
109 | #include "libeio/config.h" |
111 | #include "libeio/config.h" |
110 | |
112 | |
|
|
113 | #include "schmorp.h" |
|
|
114 | |
|
|
115 | #if HAVE_EVENTFD |
|
|
116 | # include <sys/eventfd.h> |
|
|
117 | #endif |
|
|
118 | |
|
|
119 | #if HAVE_TIMERFD |
|
|
120 | # include <sys/timerfd.h> |
|
|
121 | #endif |
|
|
122 | |
111 | #if HAVE_RLIMITS |
123 | #if HAVE_RLIMITS |
112 | #include <sys/time.h> |
124 | #include <sys/time.h> |
113 | #include <sys/resource.h> |
125 | #include <sys/resource.h> |
114 | #endif |
126 | #endif |
115 | |
127 | |
… | |
… | |
151 | # else |
163 | # else |
152 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
164 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
153 | # endif |
165 | # endif |
154 | #endif |
166 | #endif |
155 | |
167 | |
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 |
168 | #ifndef makedev |
161 | # define makedev(maj,min) (((maj) << 8) | (min)) |
169 | # define makedev(maj,min) (((maj) << 8) | (min)) |
162 | #endif |
170 | #endif |
163 | #ifndef major |
171 | #ifndef major |
164 | # define major(dev) ((dev) >> 8) |
172 | # define major(dev) ((dev) >> 8) |
… | |
… | |
172 | #endif |
180 | #endif |
173 | |
181 | |
174 | /*****************************************************************************/ |
182 | /*****************************************************************************/ |
175 | |
183 | |
176 | #if !_POSIX_MAPPED_FILES |
184 | #if !_POSIX_MAPPED_FILES |
177 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
185 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
178 | # define munmap(addr,length) EIO_ENOSYS () |
186 | # define munmap(addr,length) EIO_ENOSYS () |
179 | #endif |
187 | #endif |
180 | |
188 | |
181 | #if !_POSIX_MEMORY_PROTECTION |
189 | #if !_POSIX_MEMORY_PROTECTION |
182 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
190 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
191 | #endif |
|
|
192 | |
|
|
193 | #if !MREMAP_MAYMOVE |
|
|
194 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
183 | #endif |
195 | #endif |
184 | |
196 | |
185 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
197 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
186 | |
198 | |
187 | static int ecb_cold |
199 | static int ecb_cold |
… | |
… | |
259 | { |
271 | { |
260 | /* todo: iterate over magic and only free ours, but of course */ |
272 | /* todo: iterate over magic and only free ours, but of course */ |
261 | /* the perl5porters will call that (correct) behaviour buggy */ |
273 | /* the perl5porters will call that (correct) behaviour buggy */ |
262 | sv_unmagic (sv, FOREIGN_MAGIC); |
274 | sv_unmagic (sv, FOREIGN_MAGIC); |
263 | } |
275 | } |
|
|
276 | |
|
|
277 | /*****************************************************************************/ |
|
|
278 | |
|
|
279 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
280 | /* also provides const_iv_ and const_niv_ macros for them */ |
|
|
281 | #include "def0.h" |
264 | |
282 | |
265 | /*****************************************************************************/ |
283 | /*****************************************************************************/ |
266 | |
284 | |
267 | static void |
285 | static void |
268 | fiemap (eio_req *req) |
286 | fiemap (eio_req *req) |
… | |
… | |
969 | req_set_path1 (req, fh_or_path); |
987 | req_set_path1 (req, fh_or_path); |
970 | break; |
988 | break; |
971 | } |
989 | } |
972 | } |
990 | } |
973 | |
991 | |
|
|
992 | /*****************************************************************************/ |
|
|
993 | |
|
|
994 | static void |
|
|
995 | ts_set (struct timespec *ts, NV value) |
|
|
996 | { |
|
|
997 | ts->tv_sec = value; |
|
|
998 | ts->tv_nsec = (value - ts->tv_sec) * 1e9; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | static NV |
|
|
1002 | ts_get (const struct timespec *ts) |
|
|
1003 | { |
|
|
1004 | return ts->tv_sec + ts->tv_nsec * 1e-9; |
|
|
1005 | } |
|
|
1006 | |
|
|
1007 | /*****************************************************************************/ |
|
|
1008 | |
974 | XS(boot_IO__AIO) ecb_cold; |
1009 | XS(boot_IO__AIO) ecb_cold; |
975 | |
1010 | |
976 | MODULE = IO::AIO PACKAGE = IO::AIO |
1011 | MODULE = IO::AIO PACKAGE = IO::AIO |
977 | |
1012 | |
978 | PROTOTYPES: ENABLE |
1013 | PROTOTYPES: ENABLE |
… | |
… | |
1009 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1044 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1010 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1045 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1011 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1046 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1012 | |
1047 | |
1013 | /* the second block will be 0 when missing */ |
1048 | /* the second block will be 0 when missing */ |
|
|
1049 | const_iv (O_ACCMODE) |
|
|
1050 | |
1014 | const_iv (O_RDONLY) |
1051 | const_iv (O_RDONLY) |
1015 | const_iv (O_WRONLY) |
1052 | const_iv (O_WRONLY) |
1016 | const_iv (O_RDWR) |
1053 | const_iv (O_RDWR) |
1017 | const_iv (O_CREAT) |
1054 | const_iv (O_CREAT) |
1018 | const_iv (O_TRUNC) |
1055 | const_iv (O_TRUNC) |
… | |
… | |
1077 | const_iv (MAP_NONBLOCK) |
1114 | const_iv (MAP_NONBLOCK) |
1078 | const_iv (MAP_GROWSDOWN) |
1115 | const_iv (MAP_GROWSDOWN) |
1079 | const_iv (MAP_32BIT) |
1116 | const_iv (MAP_32BIT) |
1080 | const_iv (MAP_HUGETLB) |
1117 | const_iv (MAP_HUGETLB) |
1081 | const_iv (MAP_STACK) |
1118 | const_iv (MAP_STACK) |
|
|
1119 | |
|
|
1120 | const_iv (MREMAP_MAYMOVE) |
|
|
1121 | const_iv (MREMAP_FIXED) |
1082 | |
1122 | |
1083 | const_iv (F_DUPFD_CLOEXEC) |
1123 | const_iv (F_DUPFD_CLOEXEC) |
1084 | |
1124 | |
1085 | const_iv (F_OFD_GETLK) |
1125 | const_iv (F_OFD_GETLK) |
1086 | const_iv (F_OFD_SETLK) |
1126 | const_iv (F_OFD_SETLK) |
… | |
… | |
1161 | const_iv (SPLICE_F_MOVE) |
1201 | const_iv (SPLICE_F_MOVE) |
1162 | const_iv (SPLICE_F_NONBLOCK) |
1202 | const_iv (SPLICE_F_NONBLOCK) |
1163 | const_iv (SPLICE_F_MORE) |
1203 | const_iv (SPLICE_F_MORE) |
1164 | const_iv (SPLICE_F_GIFT) |
1204 | const_iv (SPLICE_F_GIFT) |
1165 | |
1205 | |
|
|
1206 | const_iv (EFD_CLOEXEC) |
|
|
1207 | const_iv (EFD_NONBLOCK) |
|
|
1208 | const_iv (EFD_SEMAPHORE) |
|
|
1209 | |
|
|
1210 | const_iv (CLOCK_REALTIME) |
|
|
1211 | const_iv (CLOCK_MONOTONIC) |
|
|
1212 | const_iv (CLOCK_BOOTTIME) |
|
|
1213 | const_iv (CLOCK_REALTIME_ALARM) |
|
|
1214 | const_iv (CLOCK_BOOTTIME_ALARM) |
|
|
1215 | |
|
|
1216 | const_iv (TFD_NONBLOCK) |
|
|
1217 | const_iv (TFD_CLOEXEC) |
|
|
1218 | |
|
|
1219 | const_iv (TFD_TIMER_ABSTIME) |
|
|
1220 | const_iv (TFD_TIMER_CANCEL_ON_SET) |
|
|
1221 | |
1166 | /* these are libeio constants, and are independent of gendef0 */ |
1222 | /* these are libeio constants, and are independent of gendef0 */ |
1167 | const_eio (SEEK_SET) |
1223 | const_eio (SEEK_SET) |
1168 | const_eio (SEEK_CUR) |
1224 | const_eio (SEEK_CUR) |
1169 | const_eio (SEEK_END) |
1225 | const_eio (SEEK_END) |
1170 | |
1226 | |
… | |
… | |
2016 | void |
2072 | void |
2017 | munmap (SV *scalar) |
2073 | munmap (SV *scalar) |
2018 | CODE: |
2074 | CODE: |
2019 | sv_clear_foreign (scalar); |
2075 | sv_clear_foreign (scalar); |
2020 | |
2076 | |
|
|
2077 | SV * |
|
|
2078 | mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0) |
|
|
2079 | CODE: |
|
|
2080 | { |
|
|
2081 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2082 | void *new; |
|
|
2083 | |
|
|
2084 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2085 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2086 | |
|
|
2087 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2088 | |
|
|
2089 | RETVAL = &PL_sv_no; |
|
|
2090 | |
|
|
2091 | if (new != (void *)-1) |
|
|
2092 | { |
|
|
2093 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2094 | ? newSVpvn ("0 but true", 10) |
|
|
2095 | : &PL_sv_yes; |
|
|
2096 | |
|
|
2097 | mg->mg_ptr = (char *)new; |
|
|
2098 | mg->mg_obj = (SV *)new_length; |
|
|
2099 | |
|
|
2100 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2101 | SvCUR_set (scalar, new_length); |
|
|
2102 | } |
|
|
2103 | } |
|
|
2104 | OUTPUT: |
|
|
2105 | RETVAL |
|
|
2106 | |
2021 | int |
2107 | int |
2022 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2108 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2023 | ALIAS: |
2109 | ALIAS: |
2024 | mprotect = 1 |
2110 | mprotect = 1 |
2025 | CODE: |
2111 | CODE: |
… | |
… | |
2154 | { |
2240 | { |
2155 | EXTEND (SP, 2); |
2241 | EXTEND (SP, 2); |
2156 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2242 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2157 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2243 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2158 | } |
2244 | } |
|
|
2245 | } |
|
|
2246 | |
|
|
2247 | void |
|
|
2248 | eventfd (unsigned int initval = 0, int flags = 0) |
|
|
2249 | PPCODE: |
|
|
2250 | { |
|
|
2251 | int fd; |
|
|
2252 | #if HAVE_EVENTFD |
|
|
2253 | fd = eventfd (initval, flags); |
|
|
2254 | #else |
|
|
2255 | fd = (errno = ENOSYS, -1); |
|
|
2256 | #endif |
|
|
2257 | |
|
|
2258 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2259 | } |
|
|
2260 | |
|
|
2261 | void |
|
|
2262 | timerfd_create (int clockid, int flags = 0) |
|
|
2263 | PPCODE: |
|
|
2264 | { |
|
|
2265 | int fd; |
|
|
2266 | #if HAVE_TIMERFD |
|
|
2267 | fd = timerfd_create (clockid, flags); |
|
|
2268 | #else |
|
|
2269 | fd = (errno = ENOSYS, -1); |
|
|
2270 | #endif |
|
|
2271 | |
|
|
2272 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2273 | } |
|
|
2274 | |
|
|
2275 | void |
|
|
2276 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
|
|
2277 | PPCODE: |
|
|
2278 | { |
|
|
2279 | int fd = s_fileno_croak (fh, 0); |
|
|
2280 | #if HAVE_TIMERFD |
|
|
2281 | int res; |
|
|
2282 | struct itimerspec its, ots; |
|
|
2283 | |
|
|
2284 | ts_set (&its.it_interval, interval); |
|
|
2285 | ts_set (&its.it_value , value); |
|
|
2286 | res = timerfd_settime (fd, flags, &its, &ots); |
|
|
2287 | |
|
|
2288 | if (!res) |
|
|
2289 | { |
|
|
2290 | EXTEND (SP, 2); |
|
|
2291 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2292 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2293 | } |
|
|
2294 | #else |
|
|
2295 | errno = ENOSYS; |
|
|
2296 | #endif |
|
|
2297 | } |
|
|
2298 | |
|
|
2299 | void |
|
|
2300 | timerfd_gettime (SV *fh) |
|
|
2301 | PPCODE: |
|
|
2302 | { |
|
|
2303 | int fd = s_fileno_croak (fh, 0); |
|
|
2304 | #if HAVE_TIMERFD |
|
|
2305 | int res; |
|
|
2306 | struct itimerspec ots; |
|
|
2307 | res = timerfd_gettime (fd, &ots); |
|
|
2308 | |
|
|
2309 | if (!res) |
|
|
2310 | { |
|
|
2311 | EXTEND (SP, 2); |
|
|
2312 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2313 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2314 | } |
|
|
2315 | #else |
|
|
2316 | errno = ENOSYS; |
|
|
2317 | #endif |
2159 | } |
2318 | } |
2160 | |
2319 | |
2161 | UV |
2320 | UV |
2162 | get_fdlimit () |
2321 | get_fdlimit () |
2163 | CODE: |
2322 | CODE: |