… | |
… | |
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> |
… | |
… | |
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 () |
191 | #endif |
195 | #endif |
192 | |
196 | |
|
|
197 | #if !MREMAP_MAYMOVE |
|
|
198 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
|
|
199 | #endif |
|
|
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 |
196 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
204 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
197 | { |
205 | { |
… | |
… | |
1034 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1042 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
1035 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1043 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
1036 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1044 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
1037 | |
1045 | |
1038 | /* the second block will be 0 when missing */ |
1046 | /* the second block will be 0 when missing */ |
|
|
1047 | const_iv (O_ACCMODE) |
|
|
1048 | |
1039 | const_iv (O_RDONLY) |
1049 | const_iv (O_RDONLY) |
1040 | const_iv (O_WRONLY) |
1050 | const_iv (O_WRONLY) |
1041 | const_iv (O_RDWR) |
1051 | const_iv (O_RDWR) |
1042 | const_iv (O_CREAT) |
1052 | const_iv (O_CREAT) |
1043 | const_iv (O_TRUNC) |
1053 | const_iv (O_TRUNC) |
… | |
… | |
1102 | const_iv (MAP_NONBLOCK) |
1112 | const_iv (MAP_NONBLOCK) |
1103 | const_iv (MAP_GROWSDOWN) |
1113 | const_iv (MAP_GROWSDOWN) |
1104 | const_iv (MAP_32BIT) |
1114 | const_iv (MAP_32BIT) |
1105 | const_iv (MAP_HUGETLB) |
1115 | const_iv (MAP_HUGETLB) |
1106 | const_iv (MAP_STACK) |
1116 | const_iv (MAP_STACK) |
|
|
1117 | |
|
|
1118 | const_iv (MREMAP_MAYMOVE) |
|
|
1119 | const_iv (MREMAP_FIXED) |
1107 | |
1120 | |
1108 | const_iv (F_DUPFD_CLOEXEC) |
1121 | const_iv (F_DUPFD_CLOEXEC) |
1109 | |
1122 | |
1110 | const_iv (F_OFD_GETLK) |
1123 | const_iv (F_OFD_GETLK) |
1111 | const_iv (F_OFD_SETLK) |
1124 | const_iv (F_OFD_SETLK) |
… | |
… | |
2057 | void |
2070 | void |
2058 | munmap (SV *scalar) |
2071 | munmap (SV *scalar) |
2059 | CODE: |
2072 | CODE: |
2060 | sv_clear_foreign (scalar); |
2073 | sv_clear_foreign (scalar); |
2061 | |
2074 | |
|
|
2075 | SV * |
|
|
2076 | mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0) |
|
|
2077 | CODE: |
|
|
2078 | { |
|
|
2079 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2080 | void *new; |
|
|
2081 | |
|
|
2082 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2083 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2084 | |
|
|
2085 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2086 | |
|
|
2087 | RETVAL = &PL_sv_no; |
|
|
2088 | |
|
|
2089 | if (new != (void *)-1) |
|
|
2090 | { |
|
|
2091 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2092 | ? newSVpvn ("0 but true", 10) |
|
|
2093 | : &PL_sv_yes; |
|
|
2094 | |
|
|
2095 | mg->mg_ptr = (char *)new; |
|
|
2096 | mg->mg_obj = (SV *)new_length; |
|
|
2097 | |
|
|
2098 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2099 | SvCUR_set (scalar, new_length); |
|
|
2100 | } |
|
|
2101 | } |
|
|
2102 | OUTPUT: |
|
|
2103 | RETVAL |
|
|
2104 | |
2062 | int |
2105 | int |
2063 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2106 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2064 | ALIAS: |
2107 | ALIAS: |
2065 | mprotect = 1 |
2108 | mprotect = 1 |
2066 | CODE: |
2109 | CODE: |