syscall_emul.cc (10931:42d846318962) | syscall_emul.cc (10932:cafae9abd4e4) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 198 unchanged lines hidden (view full) --- 207 208 209SyscallReturn 210closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 211{ 212 int index = 0; 213 int tgt_fd = p->getSyscallArg(tc, index); 214 | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 198 unchanged lines hidden (view full) --- 207 208 209SyscallReturn 210closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 211{ 212 int index = 0; 213 int tgt_fd = p->getSyscallArg(tc, index); 214 |
215 int sim_fd = p->sim_fd(tgt_fd); | 215 int sim_fd = p->getSimFD(tgt_fd); |
216 if (sim_fd < 0) 217 return -EBADF; 218 219 int status = 0; 220 if (sim_fd > 2) 221 status = close(sim_fd); 222 if (status >= 0) | 216 if (sim_fd < 0) 217 return -EBADF; 218 219 int status = 0; 220 if (sim_fd > 2) 221 status = close(sim_fd); 222 if (status >= 0) |
223 p->reset_fd_entry(tgt_fd); | 223 p->resetFDEntry(tgt_fd); |
224 return status; 225} 226 227 228SyscallReturn 229readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 230{ 231 int index = 0; 232 int tgt_fd = p->getSyscallArg(tc, index); 233 Addr bufPtr = p->getSyscallArg(tc, index); 234 int nbytes = p->getSyscallArg(tc, index); 235 BufferArg bufArg(bufPtr, nbytes); 236 | 224 return status; 225} 226 227 228SyscallReturn 229readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 230{ 231 int index = 0; 232 int tgt_fd = p->getSyscallArg(tc, index); 233 Addr bufPtr = p->getSyscallArg(tc, index); 234 int nbytes = p->getSyscallArg(tc, index); 235 BufferArg bufArg(bufPtr, nbytes); 236 |
237 int sim_fd = p->sim_fd(tgt_fd); | 237 int sim_fd = p->getSimFD(tgt_fd); |
238 if (sim_fd < 0) 239 return -EBADF; 240 241 int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes); 242 243 if (bytes_read != -1) 244 bufArg.copyOut(tc->getMemProxy()); 245 --- 4 unchanged lines hidden (view full) --- 250writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 251{ 252 int index = 0; 253 int tgt_fd = p->getSyscallArg(tc, index); 254 Addr bufPtr = p->getSyscallArg(tc, index); 255 int nbytes = p->getSyscallArg(tc, index); 256 BufferArg bufArg(bufPtr, nbytes); 257 | 238 if (sim_fd < 0) 239 return -EBADF; 240 241 int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes); 242 243 if (bytes_read != -1) 244 bufArg.copyOut(tc->getMemProxy()); 245 --- 4 unchanged lines hidden (view full) --- 250writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 251{ 252 int index = 0; 253 int tgt_fd = p->getSyscallArg(tc, index); 254 Addr bufPtr = p->getSyscallArg(tc, index); 255 int nbytes = p->getSyscallArg(tc, index); 256 BufferArg bufArg(bufPtr, nbytes); 257 |
258 int sim_fd = p->sim_fd(tgt_fd); | 258 int sim_fd = p->getSimFD(tgt_fd); |
259 if (sim_fd < 0) 260 return -EBADF; 261 262 bufArg.copyIn(tc->getMemProxy()); 263 264 int bytes_written = write(sim_fd, bufArg.bufferPtr(), nbytes); 265 266 fsync(sim_fd); --- 5 unchanged lines hidden (view full) --- 272SyscallReturn 273lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 274{ 275 int index = 0; 276 int tgt_fd = p->getSyscallArg(tc, index); 277 uint64_t offs = p->getSyscallArg(tc, index); 278 int whence = p->getSyscallArg(tc, index); 279 | 259 if (sim_fd < 0) 260 return -EBADF; 261 262 bufArg.copyIn(tc->getMemProxy()); 263 264 int bytes_written = write(sim_fd, bufArg.bufferPtr(), nbytes); 265 266 fsync(sim_fd); --- 5 unchanged lines hidden (view full) --- 272SyscallReturn 273lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 274{ 275 int index = 0; 276 int tgt_fd = p->getSyscallArg(tc, index); 277 uint64_t offs = p->getSyscallArg(tc, index); 278 int whence = p->getSyscallArg(tc, index); 279 |
280 int sim_fd = p->sim_fd(tgt_fd); | 280 int sim_fd = p->getSimFD(tgt_fd); |
281 if (sim_fd < 0) 282 return -EBADF; 283 284 off_t result = lseek(sim_fd, offs, whence); 285 286 return (result == (off_t)-1) ? -errno : result; 287} 288 289 290SyscallReturn 291_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 292{ 293 int index = 0; 294 int tgt_fd = p->getSyscallArg(tc, index); 295 uint64_t offset_high = p->getSyscallArg(tc, index); 296 uint32_t offset_low = p->getSyscallArg(tc, index); 297 Addr result_ptr = p->getSyscallArg(tc, index); 298 int whence = p->getSyscallArg(tc, index); 299 | 281 if (sim_fd < 0) 282 return -EBADF; 283 284 off_t result = lseek(sim_fd, offs, whence); 285 286 return (result == (off_t)-1) ? -errno : result; 287} 288 289 290SyscallReturn 291_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 292{ 293 int index = 0; 294 int tgt_fd = p->getSyscallArg(tc, index); 295 uint64_t offset_high = p->getSyscallArg(tc, index); 296 uint32_t offset_low = p->getSyscallArg(tc, index); 297 Addr result_ptr = p->getSyscallArg(tc, index); 298 int whence = p->getSyscallArg(tc, index); 299 |
300 int sim_fd = p->sim_fd(tgt_fd); | 300 int sim_fd = p->getSimFD(tgt_fd); |
301 if (sim_fd < 0) 302 return -EBADF; 303 304 uint64_t offset = (offset_high << 32) | offset_low; 305 306 uint64_t result = lseek(sim_fd, offset, whence); 307 result = TheISA::htog(result); 308 --- 187 unchanged lines hidden (view full) --- 496SyscallReturn 497ftruncateFunc(SyscallDesc *desc, int num, 498 LiveProcess *process, ThreadContext *tc) 499{ 500 int index = 0; 501 int tgt_fd = process->getSyscallArg(tc, index); 502 off_t length = process->getSyscallArg(tc, index); 503 | 301 if (sim_fd < 0) 302 return -EBADF; 303 304 uint64_t offset = (offset_high << 32) | offset_low; 305 306 uint64_t result = lseek(sim_fd, offset, whence); 307 result = TheISA::htog(result); 308 --- 187 unchanged lines hidden (view full) --- 496SyscallReturn 497ftruncateFunc(SyscallDesc *desc, int num, 498 LiveProcess *process, ThreadContext *tc) 499{ 500 int index = 0; 501 int tgt_fd = process->getSyscallArg(tc, index); 502 off_t length = process->getSyscallArg(tc, index); 503 |
504 int sim_fd = process->sim_fd(tgt_fd); | 504 int sim_fd = process->getSimFD(tgt_fd); |
505 if (sim_fd < 0) 506 return -EBADF; 507 508 int result = ftruncate(sim_fd, length); 509 return (result == -1) ? -errno : result; 510} 511 512SyscallReturn --- 22 unchanged lines hidden (view full) --- 535SyscallReturn 536ftruncate64Func(SyscallDesc *desc, int num, 537 LiveProcess *process, ThreadContext *tc) 538{ 539 int index = 0; 540 int tgt_fd = process->getSyscallArg(tc, index); 541 int64_t length = process->getSyscallArg(tc, index, 64); 542 | 505 if (sim_fd < 0) 506 return -EBADF; 507 508 int result = ftruncate(sim_fd, length); 509 return (result == -1) ? -errno : result; 510} 511 512SyscallReturn --- 22 unchanged lines hidden (view full) --- 535SyscallReturn 536ftruncate64Func(SyscallDesc *desc, int num, 537 LiveProcess *process, ThreadContext *tc) 538{ 539 int index = 0; 540 int tgt_fd = process->getSyscallArg(tc, index); 541 int64_t length = process->getSyscallArg(tc, index, 64); 542 |
543 int sim_fd = process->sim_fd(tgt_fd); | 543 int sim_fd = process->getSimFD(tgt_fd); |
544 if (sim_fd < 0) 545 return -EBADF; 546 547#if NO_STAT64 548 int result = ftruncate(sim_fd, length); 549#else 550 int result = ftruncate64(sim_fd, length); 551#endif --- 34 unchanged lines hidden (view full) --- 586} 587 588SyscallReturn 589fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 590{ 591 int index = 0; 592 int tgt_fd = process->getSyscallArg(tc, index); 593 | 544 if (sim_fd < 0) 545 return -EBADF; 546 547#if NO_STAT64 548 int result = ftruncate(sim_fd, length); 549#else 550 int result = ftruncate64(sim_fd, length); 551#endif --- 34 unchanged lines hidden (view full) --- 586} 587 588SyscallReturn 589fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 590{ 591 int index = 0; 592 int tgt_fd = process->getSyscallArg(tc, index); 593 |
594 int sim_fd = process->sim_fd(tgt_fd); | 594 int sim_fd = process->getSimFD(tgt_fd); |
595 if (sim_fd < 0) 596 return -EBADF; 597 598 /* XXX endianess */ 599 uint32_t owner = process->getSyscallArg(tc, index); 600 uid_t hostOwner = owner; 601 uint32_t group = process->getSyscallArg(tc, index); 602 gid_t hostGroup = group; --- 4 unchanged lines hidden (view full) --- 607 608 609SyscallReturn 610dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 611{ 612 int index = 0; 613 int tgt_fd = process->getSyscallArg(tc, index); 614 | 595 if (sim_fd < 0) 596 return -EBADF; 597 598 /* XXX endianess */ 599 uint32_t owner = process->getSyscallArg(tc, index); 600 uid_t hostOwner = owner; 601 uint32_t group = process->getSyscallArg(tc, index); 602 gid_t hostGroup = group; --- 4 unchanged lines hidden (view full) --- 607 608 609SyscallReturn 610dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 611{ 612 int index = 0; 613 int tgt_fd = process->getSyscallArg(tc, index); 614 |
615 int sim_fd = process->sim_fd(tgt_fd); | 615 int sim_fd = process->getSimFD(tgt_fd); |
616 if (sim_fd < 0) 617 return -EBADF; 618 | 616 if (sim_fd < 0) 617 return -EBADF; 618 |
619 FDEntry *fde = process->get_fd_entry(tgt_fd); | 619 FDEntry *fde = process->getFDEntry(tgt_fd); |
620 621 int result = dup(sim_fd); 622 return (result == -1) ? -errno : | 620 621 int result = dup(sim_fd); 622 return (result == -1) ? -errno : |
623 process->alloc_fd(result, fde->filename, fde->flags, fde->mode, false); | 623 process->allocFD(result, fde->filename, fde->flags, fde->mode, false); |
624} 625 626 627SyscallReturn 628fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 629 ThreadContext *tc) 630{ 631 int index = 0; 632 int tgt_fd = process->getSyscallArg(tc, index); 633 | 624} 625 626 627SyscallReturn 628fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 629 ThreadContext *tc) 630{ 631 int index = 0; 632 int tgt_fd = process->getSyscallArg(tc, index); 633 |
634 int sim_fd = process->sim_fd(tgt_fd); | 634 int sim_fd = process->getSimFD(tgt_fd); |
635 if (sim_fd < 0) 636 return -EBADF; 637 638 int cmd = process->getSyscallArg(tc, index); 639 switch (cmd) { 640 case 0: // F_DUPFD 641 // if we really wanted to support this, we'd need to do it 642 // in the target fd space. --- 27 unchanged lines hidden (view full) --- 670 671SyscallReturn 672fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 673 ThreadContext *tc) 674{ 675 int index = 0; 676 int tgt_fd = process->getSyscallArg(tc, index); 677 | 635 if (sim_fd < 0) 636 return -EBADF; 637 638 int cmd = process->getSyscallArg(tc, index); 639 switch (cmd) { 640 case 0: // F_DUPFD 641 // if we really wanted to support this, we'd need to do it 642 // in the target fd space. --- 27 unchanged lines hidden (view full) --- 670 671SyscallReturn 672fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 673 ThreadContext *tc) 674{ 675 int index = 0; 676 int tgt_fd = process->getSyscallArg(tc, index); 677 |
678 int sim_fd = process->sim_fd(tgt_fd); | 678 int sim_fd = process->getSimFD(tgt_fd); |
679 if (sim_fd < 0) 680 return -EBADF; 681 682 int cmd = process->getSyscallArg(tc, index); 683 switch (cmd) { 684 case 33: //F_GETLK64 685 warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", tgt_fd); 686 return -EMFILE; --- 20 unchanged lines hidden (view full) --- 707 int fds[2], sim_fds[2]; 708 int pipe_retval = pipe(fds); 709 710 if (pipe_retval < 0) { 711 // error 712 return pipe_retval; 713 } 714 | 679 if (sim_fd < 0) 680 return -EBADF; 681 682 int cmd = process->getSyscallArg(tc, index); 683 switch (cmd) { 684 case 33: //F_GETLK64 685 warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", tgt_fd); 686 return -EMFILE; --- 20 unchanged lines hidden (view full) --- 707 int fds[2], sim_fds[2]; 708 int pipe_retval = pipe(fds); 709 710 if (pipe_retval < 0) { 711 // error 712 return pipe_retval; 713 } 714 |
715 sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 716 sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); | 715 sim_fds[0] = process->allocFD(fds[0], "PIPE-READ", O_WRONLY, -1, true); 716 sim_fds[1] = process->allocFD(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); |
717 718 process->setReadPipeSource(sim_fds[0], sim_fds[1]); 719 // Alpha Linux convention for pipe() is that fd[0] is returned as 720 // the return value of the function, and fd[1] is returned in r20. 721 tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 722 return sim_fds[0]; 723} 724 --- 200 unchanged lines hidden --- | 717 718 process->setReadPipeSource(sim_fds[0], sim_fds[1]); 719 // Alpha Linux convention for pipe() is that fd[0] is returned as 720 // the return value of the function, and fd[1] is returned in r20. 721 tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 722 return sim_fds[0]; 723} 724 --- 200 unchanged lines hidden --- |