ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.256 by root, Tue Feb 20 06:54:46 2018 UTC vs.
Revision 1.265 by root, Tue Aug 14 11:50:43 2018 UTC

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>
17#include <sys/socket.h>
13#include <sys/stat.h> 18#include <sys/stat.h>
14#include <limits.h> 19#include <limits.h>
15#include <fcntl.h> 20#include <fcntl.h>
16#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
17 28
18#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 29#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
19# include <sys/mman.h> 30# include <sys/mman.h>
20#endif 31#endif
21 32
102#define expect_false(expr) expect ((expr) != 0, 0) 113#define expect_false(expr) expect ((expr) != 0, 0)
103#define expect_true(expr) expect ((expr) != 0, 1) 114#define expect_true(expr) expect ((expr) != 0, 1)
104 115
105/*****************************************************************************/ 116/*****************************************************************************/
106 117
107#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
108 133
109#include "schmorp.h" 134#include "schmorp.h"
110 135
111#if HAVE_EVENTFD 136#if HAVE_EVENTFD
112# include <sys/eventfd.h> 137# include <sys/eventfd.h>
159# else 184# else
160# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 185# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
161# endif 186# endif
162#endif 187#endif
163 188
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 189#ifndef makedev
169# define makedev(maj,min) (((maj) << 8) | (min)) 190# define makedev(maj,min) (((maj) << 8) | (min))
170#endif 191#endif
171#ifndef major 192#ifndef major
172# define major(dev) ((dev) >> 8) 193# define major(dev) ((dev) >> 8)
180#endif 201#endif
181 202
182/*****************************************************************************/ 203/*****************************************************************************/
183 204
184#if !_POSIX_MAPPED_FILES 205#if !_POSIX_MAPPED_FILES
185# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 206# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
186# define munmap(addr,length) EIO_ENOSYS () 207# define munmap(addr,length) EIO_ENOSYS ()
187#endif 208#endif
188 209
189#if !_POSIX_MEMORY_PROTECTION 210#if !_POSIX_MEMORY_PROTECTION
190# define mprotect(addr,len,prot) EIO_ENOSYS () 211# define mprotect(addr,len,prot) EIO_ENOSYS ()
212#endif
213
214#if !MREMAP_MAYMOVE
215# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1)
191#endif 216#endif
192 217
193#define FOREIGN_MAGIC PERL_MAGIC_ext 218#define FOREIGN_MAGIC PERL_MAGIC_ext
194 219
195static int ecb_cold 220static int ecb_cold
267{ 292{
268 /* todo: iterate over magic and only free ours, but of course */ 293 /* todo: iterate over magic and only free ours, but of course */
269 /* the perl5porters will call that (correct) behaviour buggy */ 294 /* the perl5porters will call that (correct) behaviour buggy */
270 sv_unmagic (sv, FOREIGN_MAGIC); 295 sv_unmagic (sv, FOREIGN_MAGIC);
271} 296}
297
298/*****************************************************************************/
299
300/* defines all sorts of constants to 0 unless they are already defined */
301/* also provides const_iv_ and const_niv_ macros for them */
302#include "def0.h"
272 303
273/*****************************************************************************/ 304/*****************************************************************************/
274 305
275static void 306static void
276fiemap (eio_req *req) 307fiemap (eio_req *req)
1034 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1065 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1035 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1066 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1036 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1067 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1037 1068
1038 /* the second block will be 0 when missing */ 1069 /* the second block will be 0 when missing */
1070 const_iv (O_ACCMODE)
1071
1039 const_iv (O_RDONLY) 1072 const_iv (O_RDONLY)
1040 const_iv (O_WRONLY) 1073 const_iv (O_WRONLY)
1041 const_iv (O_RDWR) 1074 const_iv (O_RDWR)
1042 const_iv (O_CREAT) 1075 const_iv (O_CREAT)
1043 const_iv (O_TRUNC) 1076 const_iv (O_TRUNC)
1103 const_iv (MAP_GROWSDOWN) 1136 const_iv (MAP_GROWSDOWN)
1104 const_iv (MAP_32BIT) 1137 const_iv (MAP_32BIT)
1105 const_iv (MAP_HUGETLB) 1138 const_iv (MAP_HUGETLB)
1106 const_iv (MAP_STACK) 1139 const_iv (MAP_STACK)
1107 1140
1141 const_iv (MREMAP_MAYMOVE)
1142 const_iv (MREMAP_FIXED)
1143
1108 const_iv (F_DUPFD_CLOEXEC) 1144 const_iv (F_DUPFD_CLOEXEC)
1145
1146 const_iv (MSG_CMSG_CLOEXEC)
1147 const_iv (SOCK_CLOEXEC)
1109 1148
1110 const_iv (F_OFD_GETLK) 1149 const_iv (F_OFD_GETLK)
1111 const_iv (F_OFD_SETLK) 1150 const_iv (F_OFD_SETLK)
1112 const_iv (F_OFD_GETLKW) 1151 const_iv (F_OFD_GETLKW)
1113 1152
1594 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); 1633 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1595 1634
1596 REQ_SEND; 1635 REQ_SEND;
1597} 1636}
1598 1637
1638void
1639st_xtime ()
1640 ALIAS:
1641 st_atime = 1
1642 st_mtime = 2
1643 st_ctime = 4
1644 st_xtime = 7
1645 PPCODE:
1646 EXTEND (SP, 3);
1647 if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC));
1648 if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC));
1649 if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC));
1650
1651void
1652st_xtimensec ()
1653 ALIAS:
1654 st_atimensec = 1
1655 st_mtimensec = 2
1656 st_ctimensec = 4
1657 st_xtimensec = 7
1658 PPCODE:
1659 EXTEND (SP, 3);
1660 if (ix & 1) PUSHs (newSViv (ATIMENSEC));
1661 if (ix & 2) PUSHs (newSViv (MTIMENSEC));
1662 if (ix & 4) PUSHs (newSViv (CTIMENSEC));
1663
1599UV 1664UV
1600major (UV dev) 1665major (UV dev)
1601 ALIAS: 1666 ALIAS:
1602 minor = 1 1667 minor = 1
1603 CODE: 1668 CODE:
2056 2121
2057void 2122void
2058munmap (SV *scalar) 2123munmap (SV *scalar)
2059 CODE: 2124 CODE:
2060 sv_clear_foreign (scalar); 2125 sv_clear_foreign (scalar);
2126
2127SV *
2128mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2129 CODE:
2130{
2131 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2132 void *new;
2133
2134 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2135 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2136
2137 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2138
2139 RETVAL = &PL_sv_no;
2140
2141 if (new != (void *)-1)
2142 {
2143 RETVAL = new == (void *)mg->mg_ptr
2144 ? newSVpvn ("0 but true", 10)
2145 : &PL_sv_yes;
2146
2147 mg->mg_ptr = (char *)new;
2148 mg->mg_obj = (SV *)new_length;
2149
2150 SvPVX (scalar) = mg->mg_ptr;
2151 SvCUR_set (scalar, new_length);
2152 }
2153}
2154 OUTPUT:
2155 RETVAL
2061 2156
2062int 2157int
2063madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2158madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2064 ALIAS: 2159 ALIAS:
2065 mprotect = 1 2160 mprotect = 1

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines