… | |
… | |
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 | |
111 | #if HAVE_EVENTFD |
115 | #if HAVE_EVENTFD |
112 | # include <sys/eventfd.h> |
116 | # include <sys/eventfd.h> |
113 | #endif |
117 | #endif |
114 | |
118 | |
115 | #if HAVE_TIMERFD |
119 | #if HAVE_TIMERFD |
… | |
… | |
186 | # define munmap(addr,length) EIO_ENOSYS () |
190 | # define munmap(addr,length) EIO_ENOSYS () |
187 | #endif |
191 | #endif |
188 | |
192 | |
189 | #if !_POSIX_MEMORY_PROTECTION |
193 | #if !_POSIX_MEMORY_PROTECTION |
190 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
194 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
195 | #endif |
|
|
196 | |
|
|
197 | #if !MREMAP_MAYMOVE |
|
|
198 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
191 | #endif |
199 | #endif |
192 | |
200 | |
193 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
201 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
194 | |
202 | |
195 | static int ecb_cold |
203 | static int ecb_cold |
… | |
… | |
1102 | const_iv (MAP_NONBLOCK) |
1110 | const_iv (MAP_NONBLOCK) |
1103 | const_iv (MAP_GROWSDOWN) |
1111 | const_iv (MAP_GROWSDOWN) |
1104 | const_iv (MAP_32BIT) |
1112 | const_iv (MAP_32BIT) |
1105 | const_iv (MAP_HUGETLB) |
1113 | const_iv (MAP_HUGETLB) |
1106 | const_iv (MAP_STACK) |
1114 | const_iv (MAP_STACK) |
|
|
1115 | |
|
|
1116 | const_iv (MREMAP_MAYMOVE) |
|
|
1117 | const_iv (MREMAP_FIXED) |
1107 | |
1118 | |
1108 | const_iv (F_DUPFD_CLOEXEC) |
1119 | const_iv (F_DUPFD_CLOEXEC) |
1109 | |
1120 | |
1110 | const_iv (F_OFD_GETLK) |
1121 | const_iv (F_OFD_GETLK) |
1111 | const_iv (F_OFD_SETLK) |
1122 | const_iv (F_OFD_SETLK) |
… | |
… | |
2057 | void |
2068 | void |
2058 | munmap (SV *scalar) |
2069 | munmap (SV *scalar) |
2059 | CODE: |
2070 | CODE: |
2060 | sv_clear_foreign (scalar); |
2071 | sv_clear_foreign (scalar); |
2061 | |
2072 | |
|
|
2073 | SV * |
|
|
2074 | mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0) |
|
|
2075 | CODE: |
|
|
2076 | { |
|
|
2077 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2078 | void *new; |
|
|
2079 | |
|
|
2080 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2081 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2082 | |
|
|
2083 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2084 | |
|
|
2085 | RETVAL = &PL_sv_no; |
|
|
2086 | |
|
|
2087 | if (new != (void *)-1) |
|
|
2088 | { |
|
|
2089 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2090 | ? newSVpvn ("0 but true", 10) |
|
|
2091 | : &PL_sv_yes; |
|
|
2092 | |
|
|
2093 | mg->mg_ptr = (char *)new; |
|
|
2094 | mg->mg_obj = (SV *)new_length; |
|
|
2095 | |
|
|
2096 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2097 | SvCUR_set (scalar, new_length); |
|
|
2098 | } |
|
|
2099 | } |
|
|
2100 | OUTPUT: |
|
|
2101 | RETVAL |
|
|
2102 | |
2062 | int |
2103 | int |
2063 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2104 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2064 | ALIAS: |
2105 | ALIAS: |
2065 | mprotect = 1 |
2106 | mprotect = 1 |
2066 | CODE: |
2107 | CODE: |
… | |
… | |
2230 | void |
2271 | void |
2231 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2272 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
2232 | PPCODE: |
2273 | PPCODE: |
2233 | { |
2274 | { |
2234 | int fd = s_fileno_croak (fh, 0); |
2275 | int fd = s_fileno_croak (fh, 0); |
|
|
2276 | #if HAVE_TIMERFD |
2235 | int res; |
2277 | int res; |
2236 | struct itimerspec its, ots; |
2278 | struct itimerspec its, ots; |
2237 | |
2279 | |
2238 | ts_set (&its.it_interval, interval); |
2280 | ts_set (&its.it_interval, interval); |
2239 | ts_set (&its.it_value , value); |
2281 | ts_set (&its.it_value , value); |
2240 | #if HAVE_TIMERFD |
|
|
2241 | res = timerfd_settime (fd, flags, &its, &ots); |
2282 | res = timerfd_settime (fd, flags, &its, &ots); |
2242 | #else |
|
|
2243 | res = (errno = ENOSYS, -1); |
|
|
2244 | #endif |
|
|
2245 | |
2283 | |
2246 | if (!res) |
2284 | if (!res) |
2247 | { |
2285 | { |
2248 | EXTEND (SP, 2); |
2286 | EXTEND (SP, 2); |
2249 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2287 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2250 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2288 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2251 | } |
2289 | } |
|
|
2290 | #else |
|
|
2291 | errno = ENOSYS; |
|
|
2292 | #endif |
2252 | } |
2293 | } |
2253 | |
2294 | |
2254 | void |
2295 | void |
2255 | timerfd_gettime (SV *fh) |
2296 | timerfd_gettime (SV *fh) |
2256 | PPCODE: |
2297 | PPCODE: |
2257 | { |
2298 | { |
2258 | int fd = s_fileno_croak (fh, 0); |
2299 | int fd = s_fileno_croak (fh, 0); |
|
|
2300 | #if HAVE_TIMERFD |
2259 | int res; |
2301 | int res; |
2260 | struct itimerspec ots; |
2302 | struct itimerspec ots; |
2261 | #if HAVE_TIMERFD |
|
|
2262 | res = timerfd_gettime (fd, &ots); |
2303 | res = timerfd_gettime (fd, &ots); |
2263 | #else |
|
|
2264 | res = (errno = ENOSYS, -1); |
|
|
2265 | #endif |
|
|
2266 | |
2304 | |
2267 | if (!res) |
2305 | if (!res) |
2268 | { |
2306 | { |
2269 | EXTEND (SP, 2); |
2307 | EXTEND (SP, 2); |
2270 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2308 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
2271 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2309 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
2272 | } |
2310 | } |
|
|
2311 | #else |
|
|
2312 | errno = ENOSYS; |
|
|
2313 | #endif |
2273 | } |
2314 | } |
2274 | |
2315 | |
2275 | UV |
2316 | UV |
2276 | get_fdlimit () |
2317 | get_fdlimit () |
2277 | CODE: |
2318 | CODE: |