… | |
… | |
9 | #include <unistd.h> |
9 | #include <unistd.h> |
10 | #include <fcntl.h> |
10 | #include <fcntl.h> |
11 | #include <signal.h> |
11 | #include <signal.h> |
12 | #include <sched.h> |
12 | #include <sched.h> |
13 | |
13 | |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | |
|
|
18 | #ifndef __NR_pread64 |
|
|
19 | # define __NR_pread64 __NR_pread |
|
|
20 | #endif |
|
|
21 | #ifndef __NR_pwrite64 |
|
|
22 | # define __NR_pwrite64 __NR_pwrite |
|
|
23 | #endif |
|
|
24 | |
17 | |
25 | #define STACKSIZE 1024 /* yeah */ |
18 | #define STACKSIZE 1024 /* yeah */ |
26 | |
19 | |
27 | enum { |
20 | enum { |
28 | REQ_QUIT, |
21 | REQ_QUIT, |
… | |
… | |
48 | int errorno; |
41 | int errorno; |
49 | SV *data, *callback; |
42 | SV *data, *callback; |
50 | void *dataptr; |
43 | void *dataptr; |
51 | STRLEN dataoffset; |
44 | STRLEN dataoffset; |
52 | |
45 | |
53 | struct stat64 *statdata; |
46 | Stat_t *statdata; |
54 | } aio_cb; |
47 | } aio_cb; |
55 | |
48 | |
56 | typedef aio_cb *aio_req; |
49 | typedef aio_cb *aio_req; |
57 | |
50 | |
58 | static int started; |
51 | static int started; |
… | |
… | |
189 | if (req->data) |
182 | if (req->data) |
190 | SvREFCNT_dec (req->data); |
183 | SvREFCNT_dec (req->data); |
191 | |
184 | |
192 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
185 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
193 | { |
186 | { |
194 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
187 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
195 | PL_laststatval = req->result; |
188 | PL_laststatval = req->result; |
196 | PL_statcache.st_dev = req->statdata->st_dev; |
189 | PL_statcache = *(req->statdata); |
197 | PL_statcache.st_ino = req->statdata->st_ino; |
|
|
198 | PL_statcache.st_mode = req->statdata->st_mode; |
|
|
199 | PL_statcache.st_nlink = req->statdata->st_nlink; |
|
|
200 | PL_statcache.st_uid = req->statdata->st_uid; |
|
|
201 | PL_statcache.st_gid = req->statdata->st_gid; |
|
|
202 | PL_statcache.st_rdev = req->statdata->st_rdev; |
|
|
203 | PL_statcache.st_size = req->statdata->st_size; |
|
|
204 | PL_statcache.st_atime = req->statdata->st_atime; |
|
|
205 | PL_statcache.st_mtime = req->statdata->st_mtime; |
|
|
206 | PL_statcache.st_ctime = req->statdata->st_ctime; |
|
|
207 | PL_statcache.st_blksize = req->statdata->st_blksize; |
|
|
208 | PL_statcache.st_blocks = req->statdata->st_blocks; |
|
|
209 | |
190 | |
210 | Safefree (req->statdata); |
191 | Safefree (req->statdata); |
211 | } |
192 | } |
212 | |
193 | |
213 | PUSHMARK (SP); |
194 | PUSHMARK (SP); |
… | |
… | |
237 | |
218 | |
238 | #undef errno |
219 | #undef errno |
239 | #include <asm/unistd.h> |
220 | #include <asm/unistd.h> |
240 | #include <sys/prctl.h> |
221 | #include <sys/prctl.h> |
241 | |
222 | |
|
|
223 | #define COPY_STATDATA \ |
|
|
224 | req->statdata->st_dev = statdata.st_dev; \ |
|
|
225 | req->statdata->st_ino = statdata.st_ino; \ |
|
|
226 | req->statdata->st_mode = statdata.st_mode; \ |
|
|
227 | req->statdata->st_nlink = statdata.st_nlink; \ |
|
|
228 | req->statdata->st_uid = statdata.st_uid; \ |
|
|
229 | req->statdata->st_gid = statdata.st_gid; \ |
|
|
230 | req->statdata->st_rdev = statdata.st_rdev; \ |
|
|
231 | req->statdata->st_size = statdata.st_size; \ |
|
|
232 | req->statdata->st_atime = statdata.st_atime; \ |
|
|
233 | req->statdata->st_mtime = statdata.st_mtime; \ |
|
|
234 | req->statdata->st_ctime = statdata.st_ctime; \ |
|
|
235 | req->statdata->st_blksize = statdata.st_blksize; \ |
|
|
236 | req->statdata->st_blocks = statdata.st_blocks; \ |
|
|
237 | |
242 | static int |
238 | static int |
243 | aio_proc (void *thr_arg) |
239 | aio_proc (void *thr_arg) |
244 | { |
240 | { |
245 | aio_thread *thr = thr_arg; |
241 | aio_thread *thr = thr_arg; |
246 | aio_req req; |
242 | aio_req req; |
247 | int errno; |
243 | int errno; |
248 | |
244 | |
249 | /* this is very much x86 and kernel-specific :(:(:( */ |
245 | /* this is very much kernel-specific :(:(:( */ |
250 | /* we rely on gcc's ability to create closures. */ |
246 | /* we rely on gcc's ability to create closures. */ |
251 | _syscall3(int,read,int,fd,char *,buf,size_t,count) |
247 | _syscall3(int,read,int,fd,char *,buf,size_t,count) |
252 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
248 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
253 | |
249 | |
254 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
250 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
255 | _syscall1(int,close,int,fd) |
251 | _syscall1(int,close,int,fd) |
256 | |
252 | |
|
|
253 | #ifdef __NR_pread64 |
257 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
254 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
258 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
255 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
|
|
256 | #elif __NR_pread |
|
|
257 | _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) |
|
|
258 | _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) |
|
|
259 | #else |
|
|
260 | # error "neither pread nor pread64 defined" |
|
|
261 | #endif |
259 | |
262 | |
|
|
263 | |
|
|
264 | #ifdef __NR_stat64 |
260 | _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) |
265 | _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) |
261 | _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) |
266 | _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) |
262 | _syscall2(int,fstat64, int, fd, struct stat64 *, buf) |
267 | _syscall2(int,fstat64, int, fd, struct stat64 *, buf) |
|
|
268 | #elif __NR_stat |
|
|
269 | _syscall2(int,stat, const char *, filename, struct stat *, buf) |
|
|
270 | _syscall2(int,lstat, const char *, filename, struct stat *, buf) |
|
|
271 | _syscall2(int,fstat, int, fd, struct stat *, buf) |
|
|
272 | #else |
|
|
273 | # error "neither stat64 nor stat defined" |
|
|
274 | #endif |
263 | |
275 | |
264 | _syscall1(int,unlink, char *, filename); |
276 | _syscall1(int,unlink, char *, filename); |
265 | |
277 | |
266 | sigprocmask (SIG_SETMASK, &fullsigset, 0); |
278 | sigprocmask (SIG_SETMASK, &fullsigset, 0); |
267 | prctl (PR_SET_PDEATHSIG, SIGKILL); |
279 | prctl (PR_SET_PDEATHSIG, SIGKILL); |
… | |
… | |
272 | req->thread = thr; |
284 | req->thread = thr; |
273 | errno = 0; /* strictly unnecessary */ |
285 | errno = 0; /* strictly unnecessary */ |
274 | |
286 | |
275 | switch (req->type) |
287 | switch (req->type) |
276 | { |
288 | { |
|
|
289 | #ifdef __NR_pread64 |
277 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
290 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
278 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
291 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
|
|
292 | #else |
|
|
293 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
|
|
294 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
|
|
295 | #endif |
|
|
296 | #ifdef __NR_stat64 |
|
|
297 | struct stat64 statdata; |
|
|
298 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
299 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
300 | case REQ_FSTAT: req->result = fstat64 (req->fd, &statdata); COPY_STATDATA; break; |
|
|
301 | #else |
|
|
302 | struct stat statdata; |
|
|
303 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
304 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
305 | case REQ_FSTAT: req->result = fstat (req->fd, &statdata); COPY_STATDATA; break; |
|
|
306 | #endif |
279 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
307 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
280 | case REQ_CLOSE: req->result = close (req->fd); break; |
308 | case REQ_CLOSE: req->result = close (req->fd); break; |
281 | case REQ_STAT: req->result = stat64 (req->dataptr, req->statdata); break; |
|
|
282 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, req->statdata); break; |
|
|
283 | case REQ_FSTAT: req->result = fstat64 (req->fd, req->statdata); break; |
|
|
284 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
309 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
285 | |
310 | |
286 | case REQ_QUIT: |
311 | case REQ_QUIT: |
287 | default: |
312 | default: |
288 | write (respipe[1], (void *)&req, sizeof (req)); |
313 | write (respipe[1], (void *)&req, sizeof (req)); |
… | |
… | |
426 | Newz (0, req, 1, aio_cb); |
451 | Newz (0, req, 1, aio_cb); |
427 | |
452 | |
428 | if (!req) |
453 | if (!req) |
429 | croak ("out of memory during aio_req allocation"); |
454 | croak ("out of memory during aio_req allocation"); |
430 | |
455 | |
431 | New (0, req->statdata, 1, struct stat64); |
456 | New (0, req->statdata, 1, Stat_t); |
432 | |
457 | |
433 | if (!req->statdata) |
458 | if (!req->statdata) |
434 | croak ("out of memory during aio_req->statdata allocation"); |
459 | croak ("out of memory during aio_req->statdata allocation"); |
435 | |
460 | |
436 | if (SvPOK (fh_or_path)) |
461 | if (SvPOK (fh_or_path)) |