… | |
… | |
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 | // 128 seems to be enough most everywhere. alpha needs 256. |
18 | #define STACKSIZE (128 * sizeof (long)) /* yeah */ |
20 | #define STACKSIZE (256 * sizeof (long)) |
19 | |
21 | |
20 | enum { |
22 | enum { |
21 | REQ_QUIT, |
23 | REQ_QUIT, |
22 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
24 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
23 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
25 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
… | |
… | |
231 | static sigset_t fullsigset; |
233 | static sigset_t fullsigset; |
232 | |
234 | |
233 | #undef errno |
235 | #undef errno |
234 | #include <asm/unistd.h> |
236 | #include <asm/unistd.h> |
235 | #include <sys/prctl.h> |
237 | #include <sys/prctl.h> |
|
|
238 | |
|
|
239 | #if BYTE_ORDER == LITTLE_ENDIAN |
|
|
240 | # define LONG_LONG_PAIR(HI, LO) LO, HI |
|
|
241 | #elif BYTE_ORDER == BIG_ENDIAN |
|
|
242 | # define LONG_LONG_PAIR(HI, LO) HI, LO |
|
|
243 | #endif |
|
|
244 | |
|
|
245 | #if __alpha || __ia64 || __hppa || __v850__ |
|
|
246 | # define stat kernelstat |
|
|
247 | # define stat64 kernelstat64 |
|
|
248 | # include <asm/stat.h> |
|
|
249 | # undef stat |
|
|
250 | # undef stat64 |
|
|
251 | #else |
|
|
252 | # define kernelstat stat |
|
|
253 | # define kernelstat64 stat64 |
|
|
254 | #endif |
236 | |
255 | |
237 | #define COPY_STATDATA \ |
256 | #define COPY_STATDATA \ |
238 | req->statdata->st_dev = statdata.st_dev; \ |
257 | req->statdata->st_dev = statdata.st_dev; \ |
239 | req->statdata->st_ino = statdata.st_ino; \ |
258 | req->statdata->st_ino = statdata.st_ino; \ |
240 | req->statdata->st_mode = statdata.st_mode; \ |
259 | req->statdata->st_mode = statdata.st_mode; \ |
… | |
… | |
262 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
281 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
263 | |
282 | |
264 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
283 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
265 | _syscall1(int,close,int,fd) |
284 | _syscall1(int,close,int,fd) |
266 | |
285 | |
267 | #ifdef __NR_pread64 |
286 | #if __NR_pread64 |
268 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
287 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lh,unsigned int,offset_hl) |
269 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
288 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lh,unsigned int,offset_hl) |
270 | #elif __NR_pread |
289 | #elif __NR_pread |
271 | _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) |
290 | _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) |
272 | _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) |
291 | _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) |
273 | #else |
292 | #else |
274 | # error "neither pread nor pread64 defined" |
293 | # error "neither pread nor pread64 defined" |
275 | #endif |
294 | #endif |
276 | |
295 | |
277 | |
296 | |
278 | #ifdef __NR_stat64 |
297 | #if __NR_stat64 |
279 | _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) |
298 | _syscall2(int,stat64, const char *, filename, struct kernelstat64 *, buf) |
280 | _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) |
299 | _syscall2(int,lstat64, const char *, filename, struct kernelstat64 *, buf) |
281 | _syscall2(int,fstat64, int, fd, struct stat64 *, buf) |
300 | _syscall2(int,fstat64, int, fd, struct kernelstat64 *, buf) |
282 | #elif __NR_stat |
301 | #elif __NR_stat |
283 | _syscall2(int,stat, const char *, filename, struct stat *, buf) |
302 | _syscall2(int,stat, const char *, filename, struct kernelstat *, buf) |
284 | _syscall2(int,lstat, const char *, filename, struct stat *, buf) |
303 | _syscall2(int,lstat, const char *, filename, struct kernelstat *, buf) |
285 | _syscall2(int,fstat, int, fd, struct stat *, buf) |
304 | _syscall2(int,fstat, int, fd, struct kernelstat *, buf) |
286 | #else |
305 | #else |
287 | # error "neither stat64 nor stat defined" |
306 | # error "neither stat64 nor stat defined" |
288 | #endif |
307 | #endif |
289 | |
308 | |
290 | _syscall1(int,unlink, char *, filename); |
309 | _syscall1(int,unlink, char *, filename); |
… | |
… | |
298 | req->thread = thr; |
317 | req->thread = thr; |
299 | errno = 0; /* strictly unnecessary */ |
318 | errno = 0; /* strictly unnecessary */ |
300 | |
319 | |
301 | switch (req->type) |
320 | switch (req->type) |
302 | { |
321 | { |
303 | #ifdef __NR_pread64 |
322 | #if __NR_pread64 |
304 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
323 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, |
|
|
324 | LONG_LONG_PAIR (req->offset >> 32, req->offset & 0xffffffff)); break; |
305 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break; |
325 | case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, |
|
|
326 | LONG_LONG_PAIR (req->offset >> 32, req->offset & 0xffffffff)); break; |
306 | #else |
327 | #else |
307 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
328 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
308 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
329 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
309 | #endif |
330 | #endif |
310 | #ifdef __NR_stat64 |
331 | #if __NR_stat64 |
311 | struct stat64 statdata; |
332 | struct kernelstat64 statdata; |
312 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
333 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
313 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
334 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
314 | case REQ_FSTAT: req->result = fstat64 (req->fd, &statdata); COPY_STATDATA; break; |
335 | case REQ_FSTAT: req->result = fstat64 (req->fd, &statdata); COPY_STATDATA; break; |
315 | #else |
336 | #else |
316 | struct stat statdata; |
337 | struct kernelstat statdata; |
317 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
338 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
318 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
339 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
319 | case REQ_FSTAT: req->result = fstat (req->fd, &statdata); COPY_STATDATA; break; |
340 | case REQ_FSTAT: req->result = fstat (req->fd, &statdata); COPY_STATDATA; break; |
320 | #endif |
341 | #endif |
321 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
342 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |