… | |
… | |
3 | #include <errno.h> |
3 | #include <errno.h> |
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 | |
|
|
9 | #if !defined mg_findext |
|
|
10 | # define mg_findext(sv,type,vtbl) mg_find (sv, type) |
|
|
11 | #endif |
8 | |
12 | |
9 | #include <stddef.h> |
13 | #include <stddef.h> |
10 | #include <stdlib.h> |
14 | #include <stdlib.h> |
11 | #include <errno.h> |
15 | #include <errno.h> |
12 | #include <sys/types.h> |
16 | #include <sys/types.h> |
… | |
… | |
159 | # else |
163 | # else |
160 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
164 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
161 | # endif |
165 | # endif |
162 | #endif |
166 | #endif |
163 | |
167 | |
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 |
168 | #ifndef makedev |
169 | # define makedev(maj,min) (((maj) << 8) | (min)) |
169 | # define makedev(maj,min) (((maj) << 8) | (min)) |
170 | #endif |
170 | #endif |
171 | #ifndef major |
171 | #ifndef major |
172 | # define major(dev) ((dev) >> 8) |
172 | # define major(dev) ((dev) >> 8) |
… | |
… | |
180 | #endif |
180 | #endif |
181 | |
181 | |
182 | /*****************************************************************************/ |
182 | /*****************************************************************************/ |
183 | |
183 | |
184 | #if !_POSIX_MAPPED_FILES |
184 | #if !_POSIX_MAPPED_FILES |
185 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
185 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
186 | # define munmap(addr,length) EIO_ENOSYS () |
186 | # define munmap(addr,length) EIO_ENOSYS () |
187 | #endif |
187 | #endif |
188 | |
188 | |
189 | #if !_POSIX_MEMORY_PROTECTION |
189 | #if !_POSIX_MEMORY_PROTECTION |
190 | # 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) |
191 | #endif |
195 | #endif |
192 | |
196 | |
193 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
197 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
194 | |
198 | |
195 | static int ecb_cold |
199 | static int ecb_cold |
… | |
… | |
267 | { |
271 | { |
268 | /* todo: iterate over magic and only free ours, but of course */ |
272 | /* todo: iterate over magic and only free ours, but of course */ |
269 | /* the perl5porters will call that (correct) behaviour buggy */ |
273 | /* the perl5porters will call that (correct) behaviour buggy */ |
270 | sv_unmagic (sv, FOREIGN_MAGIC); |
274 | sv_unmagic (sv, FOREIGN_MAGIC); |
271 | } |
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" |
272 | |
282 | |
273 | /*****************************************************************************/ |
283 | /*****************************************************************************/ |
274 | |
284 | |
275 | static void |
285 | static void |
276 | fiemap (eio_req *req) |
286 | fiemap (eio_req *req) |
… | |
… | |
1034 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1044 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1035 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1045 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1036 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1046 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1037 | |
1047 | |
1038 | /* the second block will be 0 when missing */ |
1048 | /* the second block will be 0 when missing */ |
|
|
1049 | const_iv (O_ACCMODE) |
|
|
1050 | |
1039 | const_iv (O_RDONLY) |
1051 | const_iv (O_RDONLY) |
1040 | const_iv (O_WRONLY) |
1052 | const_iv (O_WRONLY) |
1041 | const_iv (O_RDWR) |
1053 | const_iv (O_RDWR) |
1042 | const_iv (O_CREAT) |
1054 | const_iv (O_CREAT) |
1043 | const_iv (O_TRUNC) |
1055 | const_iv (O_TRUNC) |
… | |
… | |
1102 | const_iv (MAP_NONBLOCK) |
1114 | const_iv (MAP_NONBLOCK) |
1103 | const_iv (MAP_GROWSDOWN) |
1115 | const_iv (MAP_GROWSDOWN) |
1104 | const_iv (MAP_32BIT) |
1116 | const_iv (MAP_32BIT) |
1105 | const_iv (MAP_HUGETLB) |
1117 | const_iv (MAP_HUGETLB) |
1106 | const_iv (MAP_STACK) |
1118 | const_iv (MAP_STACK) |
|
|
1119 | |
|
|
1120 | const_iv (MREMAP_MAYMOVE) |
|
|
1121 | const_iv (MREMAP_FIXED) |
1107 | |
1122 | |
1108 | const_iv (F_DUPFD_CLOEXEC) |
1123 | const_iv (F_DUPFD_CLOEXEC) |
1109 | |
1124 | |
1110 | const_iv (F_OFD_GETLK) |
1125 | const_iv (F_OFD_GETLK) |
1111 | const_iv (F_OFD_SETLK) |
1126 | const_iv (F_OFD_SETLK) |
… | |
… | |
2057 | void |
2072 | void |
2058 | munmap (SV *scalar) |
2073 | munmap (SV *scalar) |
2059 | CODE: |
2074 | CODE: |
2060 | sv_clear_foreign (scalar); |
2075 | sv_clear_foreign (scalar); |
2061 | |
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 | |
2062 | int |
2107 | int |
2063 | 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) |
2064 | ALIAS: |
2109 | ALIAS: |
2065 | mprotect = 1 |
2110 | mprotect = 1 |
2066 | CODE: |
2111 | CODE: |
… | |
… | |
2230 | void |
2275 | void |
2231 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2276 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2232 | PPCODE: |
2277 | PPCODE: |
2233 | { |
2278 | { |
2234 | int fd = s_fileno_croak (fh, 0); |
2279 | int fd = s_fileno_croak (fh, 0); |
|
|
2280 | #if HAVE_TIMERFD |
2235 | int res; |
2281 | int res; |
2236 | struct itimerspec its, ots; |
2282 | struct itimerspec its, ots; |
2237 | |
2283 | |
2238 | ts_set (&its.it_interval, interval); |
2284 | ts_set (&its.it_interval, interval); |
2239 | ts_set (&its.it_value , value); |
2285 | ts_set (&its.it_value , value); |
2240 | #if HAVE_TIMERFD |
|
|
2241 | res = timerfd_settime (fd, flags, &its, &ots); |
2286 | res = timerfd_settime (fd, flags, &its, &ots); |
2242 | #else |
|
|
2243 | res = (errno = ENOSYS, -1); |
|
|
2244 | #endif |
|
|
2245 | |
2287 | |
2246 | if (!res) |
2288 | if (!res) |
2247 | { |
2289 | { |
2248 | EXTEND (SP, 2); |
2290 | EXTEND (SP, 2); |
2249 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2291 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2250 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2292 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2251 | } |
2293 | } |
|
|
2294 | #else |
|
|
2295 | errno = ENOSYS; |
|
|
2296 | #endif |
2252 | } |
2297 | } |
2253 | |
2298 | |
2254 | void |
2299 | void |
2255 | timerfd_gettime (SV *fh) |
2300 | timerfd_gettime (SV *fh) |
2256 | PPCODE: |
2301 | PPCODE: |
2257 | { |
2302 | { |
2258 | int fd = s_fileno_croak (fh, 0); |
2303 | int fd = s_fileno_croak (fh, 0); |
|
|
2304 | #if HAVE_TIMERFD |
2259 | int res; |
2305 | int res; |
2260 | struct itimerspec ots; |
2306 | struct itimerspec ots; |
2261 | #if HAVE_TIMERFD |
|
|
2262 | res = timerfd_gettime (fd, &ots); |
2307 | res = timerfd_gettime (fd, &ots); |
2263 | #else |
|
|
2264 | res = (errno = ENOSYS, -1); |
|
|
2265 | #endif |
|
|
2266 | |
2308 | |
2267 | if (!res) |
2309 | if (!res) |
2268 | { |
2310 | { |
2269 | EXTEND (SP, 2); |
2311 | EXTEND (SP, 2); |
2270 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2312 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2271 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2313 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2272 | } |
2314 | } |
|
|
2315 | #else |
|
|
2316 | errno = ENOSYS; |
|
|
2317 | #endif |
2273 | } |
2318 | } |
2274 | |
2319 | |
2275 | UV |
2320 | UV |
2276 | get_fdlimit () |
2321 | get_fdlimit () |
2277 | CODE: |
2322 | CODE: |