… | |
… | |
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 | |
|
|
19 | #if __i386 || __amd64 |
|
|
20 | # define STACKSIZE ( 256 * sizeof (long)) |
|
|
21 | #elif __ia64 |
18 | #define STACKSIZE (128 * sizeof (long)) /* yeah */ |
22 | # define STACKSIZE (8192 * sizeof (long)) |
|
|
23 | #else |
|
|
24 | # define STACKSIZE ( 512 * sizeof (long)) |
|
|
25 | #endif |
19 | |
26 | |
20 | enum { |
27 | enum { |
21 | REQ_QUIT, |
28 | REQ_QUIT, |
22 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
29 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
23 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
30 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
… | |
… | |
62 | aio_thread *thr; |
69 | aio_thread *thr; |
63 | |
70 | |
64 | New (0, thr, 1, aio_thread); |
71 | New (0, thr, 1, aio_thread); |
65 | |
72 | |
66 | if (clone (aio_proc, |
73 | if (clone (aio_proc, |
67 | &(thr->stack[STACKSIZE - sizeof (long)]), |
74 | &(thr->stack[STACKSIZE - 16]), |
68 | CLONE_VM|CLONE_FS|CLONE_FILES, |
75 | CLONE_VM|CLONE_FS|CLONE_FILES, |
69 | thr) >= 0) |
76 | thr) >= 0) |
70 | started++; |
77 | started++; |
71 | else |
78 | else |
72 | Safefree (thr); |
79 | Safefree (thr); |
… | |
… | |
230 | |
237 | |
231 | static sigset_t fullsigset; |
238 | static sigset_t fullsigset; |
232 | |
239 | |
233 | #undef errno |
240 | #undef errno |
234 | #include <asm/unistd.h> |
241 | #include <asm/unistd.h> |
|
|
242 | #include <linux/types.h> |
235 | #include <sys/prctl.h> |
243 | #include <sys/prctl.h> |
|
|
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 | |
|
|
251 | #if __alpha || __ia64 || __hppa || __v850__ |
|
|
252 | # define stat kernelstat |
|
|
253 | # define stat64 kernelstat64 |
|
|
254 | # include <asm/stat.h> |
|
|
255 | # undef stat |
|
|
256 | # undef stat64 |
|
|
257 | #else |
|
|
258 | # define kernelstat stat |
|
|
259 | # define kernelstat64 stat64 |
|
|
260 | #endif |
236 | |
261 | |
237 | #define COPY_STATDATA \ |
262 | #define COPY_STATDATA \ |
238 | req->statdata->st_dev = statdata.st_dev; \ |
263 | req->statdata->st_dev = statdata.st_dev; \ |
239 | req->statdata->st_ino = statdata.st_ino; \ |
264 | req->statdata->st_ino = statdata.st_ino; \ |
240 | req->statdata->st_mode = statdata.st_mode; \ |
265 | req->statdata->st_mode = statdata.st_mode; \ |
… | |
… | |
256 | aio_req req; |
281 | aio_req req; |
257 | int errno; |
282 | int errno; |
258 | |
283 | |
259 | /* this is very much kernel-specific :(:(:( */ |
284 | /* this is very much kernel-specific :(:(:( */ |
260 | /* we rely on gcc's ability to create closures. */ |
285 | /* we rely on gcc's ability to create closures. */ |
261 | _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) |
262 | _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) |
263 | |
288 | |
264 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
289 | _syscall3(int,open,char *,pathname,int,flags,int,mode) |
265 | _syscall1(int,close,int,fd) |
290 | _syscall1(int,close,unsigned int,fd) |
266 | |
291 | |
267 | #define arch64 (__ia64 || __alpha) |
|
|
268 | |
|
|
269 | #ifdef __NR_pread64 && !arch64 |
|
|
270 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
|
|
271 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
|
|
272 | #elif __NR_pread |
292 | #ifndef __NR_pread64 |
273 | _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) |
293 | # define __NR_pread64 __NR_pread |
274 | _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) |
294 | # define __NR_pwrite64 __NR_write |
275 | #else |
|
|
276 | # error "neither pread nor pread64 defined" |
|
|
277 | #endif |
295 | #endif |
|
|
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) |
278 | |
298 | |
279 | |
299 | #if __NR_stat64 |
280 | #ifdef __NR_stat64 && !arch64 |
|
|
281 | _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) |
300 | _syscall2(int,stat64, const char *, filename, struct kernelstat64 *, buf) |
282 | _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) |
301 | _syscall2(int,lstat64, const char *, filename, struct kernelstat64 *, buf) |
283 | _syscall2(int,fstat64, int, fd, struct stat64 *, buf) |
302 | _syscall2(int,fstat64, int, fd, struct kernelstat64 *, buf) |
284 | #elif __NR_stat |
303 | #elif __NR_stat |
285 | _syscall2(int,stat, const char *, filename, struct stat *, buf) |
304 | _syscall2(int,stat, const char *, filename, struct kernelstat *, buf) |
286 | _syscall2(int,lstat, const char *, filename, struct stat *, buf) |
305 | _syscall2(int,lstat, const char *, filename, struct kernelstat *, buf) |
287 | _syscall2(int,fstat, int, fd, struct stat *, buf) |
306 | _syscall2(int,fstat, int, fd, struct kernelstat *, buf) |
288 | #else |
307 | #else |
289 | # error "neither stat64 nor stat defined" |
308 | # error "neither stat64 nor stat defined" |
290 | #endif |
309 | #endif |
291 | |
310 | |
292 | _syscall1(int,unlink, char *, filename); |
311 | _syscall1(int,unlink, char *, filename); |
… | |
… | |
300 | req->thread = thr; |
319 | req->thread = thr; |
301 | errno = 0; /* strictly unnecessary */ |
320 | errno = 0; /* strictly unnecessary */ |
302 | |
321 | |
303 | switch (req->type) |
322 | switch (req->type) |
304 | { |
323 | { |
305 | #ifdef __NR_pread64 |
|
|
306 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
|
|
307 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
|
|
308 | #else |
|
|
309 | 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; |
310 | 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, |
311 | #endif |
327 | LONG_LONG_PAIR (req->offset >> 32, req->offset & 0xffffffff)); break; |
312 | #ifdef __NR_stat64 |
328 | #if __NR_stat64 |
313 | struct stat64 statdata; |
329 | struct kernelstat64 statdata; |
314 | 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; |
315 | 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; |
316 | 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; |
317 | #else |
333 | #else |
318 | struct stat statdata; |
334 | struct kernelstat statdata; |
319 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
335 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
320 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
336 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
321 | case REQ_FSTAT: req->result = fstat (req->fd, &statdata); COPY_STATDATA; break; |
337 | case REQ_FSTAT: req->result = fstat (req->fd, &statdata); COPY_STATDATA; break; |
322 | #endif |
338 | #endif |
323 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
339 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |