… | |
… | |
8 | #include <sys/stat.h> |
8 | #include <sys/stat.h> |
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 | #include <endian.h> |
13 | |
14 | |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | 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 ;) */ |
16 | 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 ;) */ |
17 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | |
18 | |
18 | // 128 seems to be enough most everywhere. alpha needs 256. |
19 | #if __i386 || __amd64 |
19 | #define STACKSIZE (256 * sizeof (long)) |
20 | # define STACKSIZE ( 256 * sizeof (long)) |
|
|
21 | #elif __ia64 |
|
|
22 | # define STACKSIZE (8192 * sizeof (long)) |
|
|
23 | #else |
|
|
24 | # define STACKSIZE ( 512 * sizeof (long)) |
|
|
25 | #endif |
20 | |
26 | |
21 | enum { |
27 | enum { |
22 | REQ_QUIT, |
28 | REQ_QUIT, |
23 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
29 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
24 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
30 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
… | |
… | |
63 | aio_thread *thr; |
69 | aio_thread *thr; |
64 | |
70 | |
65 | New (0, thr, 1, aio_thread); |
71 | New (0, thr, 1, aio_thread); |
66 | |
72 | |
67 | if (clone (aio_proc, |
73 | if (clone (aio_proc, |
68 | &(thr->stack[STACKSIZE - sizeof (long)]), |
74 | &(thr->stack[STACKSIZE - 16]), |
69 | CLONE_VM|CLONE_FS|CLONE_FILES, |
75 | CLONE_VM|CLONE_FS|CLONE_FILES, |
70 | thr) >= 0) |
76 | thr) >= 0) |
71 | started++; |
77 | started++; |
72 | else |
78 | else |
73 | Safefree (thr); |
79 | Safefree (thr); |
… | |
… | |
231 | |
237 | |
232 | static sigset_t fullsigset; |
238 | static sigset_t fullsigset; |
233 | |
239 | |
234 | #undef errno |
240 | #undef errno |
235 | #include <asm/unistd.h> |
241 | #include <asm/unistd.h> |
|
|
242 | #include <linux/types.h> |
236 | #include <sys/prctl.h> |
243 | #include <sys/prctl.h> |
237 | |
244 | |
|
|
245 | #if BYTE_ORDER == LITTLE_ENDIAN |
|
|
246 | # define LONG_LONG_PAIR(HI, LO) LO, HI |
|
|
247 | #elif BYTE_ORDER == BIG_ENDIAN |
|
|
248 | # define LONG_LONG_PAIR(HI, LO) HI, LO |
|
|
249 | #endif |
|
|
250 | |
238 | #if __alpha || __ia64 || __hppa || __sparc64__ || __v850__ |
251 | #if __alpha || __ia64 || __hppa || __v850__ |
239 | # define stat kernelstat |
252 | # define stat kernelstat |
240 | # define stat64 kernelstat64 |
253 | # define stat64 kernelstat64 |
241 | # include <asm/stat.h> |
254 | # include <asm/stat.h> |
242 | # undef stat |
255 | # undef stat |
243 | # undef stat64 |
256 | # undef stat64 |
… | |
… | |
268 | aio_req req; |
281 | aio_req req; |
269 | int errno; |
282 | int errno; |
270 | |
283 | |
271 | /* this is very much kernel-specific :(:(:( */ |
284 | /* this is very much kernel-specific :(:(:( */ |
272 | /* we rely on gcc's ability to create closures. */ |
285 | /* we rely on gcc's ability to create closures. */ |
273 | _syscall3(int,read,int,fd,char *,buf,size_t,count) |
286 | _syscall3(__kernel_size_t,read,unsigned int,fd,char *,buf,__kernel_size_t,count) |
274 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
287 | _syscall3(__kernel_size_t,write,unsigned int,fd,char *,buf,__kernel_size_t,count) |
275 | |
288 | |
276 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
289 | _syscall3(int,open,char *,pathname,int,flags,int,mode) |
277 | _syscall1(int,close,int,fd) |
290 | _syscall1(int,close,unsigned int,fd) |
278 | |
291 | |
279 | #if __NR_pread64 |
292 | #ifndef __NR_pread64 |
280 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
293 | # define __NR_pread64 __NR_pread |
281 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
294 | # define __NR_pwrite64 __NR_write |
282 | #elif __NR_pread |
|
|
283 | _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) |
|
|
284 | _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) |
|
|
285 | #else |
|
|
286 | # error "neither pread nor pread64 defined" |
|
|
287 | #endif |
295 | #endif |
288 | |
296 | _syscall5(__kernel_ssize_t,pread64,unsigned int,fd,char *,buf,__kernel_size_t,count,unsigned int,offset_lh,unsigned int,offset_hl) |
|
|
297 | _syscall5(__kernel_ssize_t,pwrite64,unsigned int,fd,char *,buf,__kernel_size_t,count,unsigned int,offset_lh,unsigned int,offset_hl) |
289 | |
298 | |
290 | #if __NR_stat64 |
299 | #if __NR_stat64 |
291 | _syscall2(int,stat64, const char *, filename, struct kernelstat64 *, buf) |
300 | _syscall2(int,stat64, const char *, filename, struct kernelstat64 *, buf) |
292 | _syscall2(int,lstat64, const char *, filename, struct kernelstat64 *, buf) |
301 | _syscall2(int,lstat64, const char *, filename, struct kernelstat64 *, buf) |
293 | _syscall2(int,fstat64, int, fd, struct kernelstat64 *, buf) |
302 | _syscall2(int,fstat64, int, fd, struct kernelstat64 *, buf) |
… | |
… | |
310 | req->thread = thr; |
319 | req->thread = thr; |
311 | errno = 0; /* strictly unnecessary */ |
320 | errno = 0; /* strictly unnecessary */ |
312 | |
321 | |
313 | switch (req->type) |
322 | switch (req->type) |
314 | { |
323 | { |
315 | #if __NR_pread64 |
|
|
316 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
|
|
317 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
|
|
318 | #else |
|
|
319 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
324 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, |
|
|
325 | LONG_LONG_PAIR (req->offset >> 32, req->offset & 0xffffffff)); break; |
320 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
326 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, |
321 | #endif |
327 | LONG_LONG_PAIR (req->offset >> 32, req->offset & 0xffffffff)); break; |
322 | #if __NR_stat64 |
328 | #if __NR_stat64 |
323 | struct kernelstat64 statdata; |
329 | struct kernelstat64 statdata; |
324 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
330 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
325 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
331 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
326 | case REQ_FSTAT: req->result = fstat64 (req->fd, &statdata); COPY_STATDATA; break; |
332 | case REQ_FSTAT: req->result = fstat64 (req->fd, &statdata); COPY_STATDATA; break; |