syscall_emul.cc (14020:c9bf7a011602) | syscall_emul.cc (14024:abe47b13653d) |
---|---|
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; --- 76 unchanged lines hidden (view full) --- 85 86static void 87exitFutexWake(ThreadContext *tc, Addr addr, uint64_t tgid) 88{ 89 // Clear value at address pointed to by thread's childClearTID field. 90 BufferArg ctidBuf(addr, sizeof(long)); 91 long *ctid = (long *)ctidBuf.bufferPtr(); 92 *ctid = 0; | 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; --- 76 unchanged lines hidden (view full) --- 85 86static void 87exitFutexWake(ThreadContext *tc, Addr addr, uint64_t tgid) 88{ 89 // Clear value at address pointed to by thread's childClearTID field. 90 BufferArg ctidBuf(addr, sizeof(long)); 91 long *ctid = (long *)ctidBuf.bufferPtr(); 92 *ctid = 0; |
93 ctidBuf.copyOut(tc->getMemProxy()); | 93 ctidBuf.copyOut(tc->getVirtProxy()); |
94 95 FutexMap &futex_map = tc->getSystemPtr()->futexMap; 96 // Wake one of the waiting threads. 97 futex_map.wakeup(addr, tgid, 1); 98} 99 100static SyscallReturn 101exitImpl(SyscallDesc *desc, int callnum, ThreadContext *tc, bool group) --- 158 unchanged lines hidden (view full) --- 260 new_brk - brk_point, 261 PageBytes); !gen.done(); gen.next()) { 262 if (!p->pTable->translate(gen.addr())) 263 p->allocateMem(roundDown(gen.addr(), PageBytes), PageBytes); 264 265 // if the address is already there, zero it out 266 else { 267 uint8_t zero = 0; | 94 95 FutexMap &futex_map = tc->getSystemPtr()->futexMap; 96 // Wake one of the waiting threads. 97 futex_map.wakeup(addr, tgid, 1); 98} 99 100static SyscallReturn 101exitImpl(SyscallDesc *desc, int callnum, ThreadContext *tc, bool group) --- 158 unchanged lines hidden (view full) --- 260 new_brk - brk_point, 261 PageBytes); !gen.done(); gen.next()) { 262 if (!p->pTable->translate(gen.addr())) 263 p->allocateMem(roundDown(gen.addr(), PageBytes), PageBytes); 264 265 // if the address is already there, zero it out 266 else { 267 uint8_t zero = 0; |
268 PortProxy &tp = tc->getMemProxy(); | 268 PortProxy &tp = tc->getVirtProxy(); |
269 270 // split non-page aligned accesses 271 Addr next_page = roundUp(gen.addr(), PageBytes); 272 uint32_t size_needed = next_page - gen.addr(); 273 tp.memsetBlob(gen.addr(), zero, size_needed); 274 if (gen.addr() + PageBytes > next_page && 275 next_page < new_brk && 276 p->pTable->translate(next_page)) { --- 72 unchanged lines hidden (view full) --- 349 uint64_t result = lseek(sim_fd, offset, whence); 350 result = TheISA::htog(result); 351 352 if (result == (off_t)-1) 353 return -errno; 354 // Assuming that the size of loff_t is 64 bits on the target platform 355 BufferArg result_buf(result_ptr, sizeof(result)); 356 memcpy(result_buf.bufferPtr(), &result, sizeof(result)); | 269 270 // split non-page aligned accesses 271 Addr next_page = roundUp(gen.addr(), PageBytes); 272 uint32_t size_needed = next_page - gen.addr(); 273 tp.memsetBlob(gen.addr(), zero, size_needed); 274 if (gen.addr() + PageBytes > next_page && 275 next_page < new_brk && 276 p->pTable->translate(next_page)) { --- 72 unchanged lines hidden (view full) --- 349 uint64_t result = lseek(sim_fd, offset, whence); 350 result = TheISA::htog(result); 351 352 if (result == (off_t)-1) 353 return -errno; 354 // Assuming that the size of loff_t is 64 bits on the target platform 355 BufferArg result_buf(result_ptr, sizeof(result)); 356 memcpy(result_buf.bufferPtr(), &result, sizeof(result)); |
357 result_buf.copyOut(tc->getMemProxy()); | 357 result_buf.copyOut(tc->getVirtProxy()); |
358 return 0; 359} 360 361 362SyscallReturn 363munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc) 364{ 365 // With mmap more fully implemented, it might be worthwhile to bite --- 11 unchanged lines hidden (view full) --- 377 int index = 0; 378 auto p = tc->getProcessPtr(); 379 Addr buf_ptr = p->getSyscallArg(tc, index); 380 int name_len = p->getSyscallArg(tc, index); 381 BufferArg name(buf_ptr, name_len); 382 383 strncpy((char *)name.bufferPtr(), hostname, name_len); 384 | 358 return 0; 359} 360 361 362SyscallReturn 363munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc) 364{ 365 // With mmap more fully implemented, it might be worthwhile to bite --- 11 unchanged lines hidden (view full) --- 377 int index = 0; 378 auto p = tc->getProcessPtr(); 379 Addr buf_ptr = p->getSyscallArg(tc, index); 380 int name_len = p->getSyscallArg(tc, index); 381 BufferArg name(buf_ptr, name_len); 382 383 strncpy((char *)name.bufferPtr(), hostname, name_len); 384 |
385 name.copyOut(tc->getMemProxy()); | 385 name.copyOut(tc->getVirtProxy()); |
386 387 return 0; 388} 389 390SyscallReturn 391getcwdFunc(SyscallDesc *desc, int num, ThreadContext *tc) 392{ 393 int result = 0; --- 15 unchanged lines hidden (view full) --- 409 } else { 410 if (getcwd((char *)buf.bufferPtr(), size)) { 411 result = strlen((char *)buf.bufferPtr()); 412 } else { 413 result = -1; 414 } 415 } 416 | 386 387 return 0; 388} 389 390SyscallReturn 391getcwdFunc(SyscallDesc *desc, int num, ThreadContext *tc) 392{ 393 int result = 0; --- 15 unchanged lines hidden (view full) --- 409 } else { 410 if (getcwd((char *)buf.bufferPtr(), size)) { 411 result = strlen((char *)buf.bufferPtr()); 412 } else { 413 result = -1; 414 } 415 } 416 |
417 buf.copyOut(tc->getMemProxy()); | 417 buf.copyOut(tc->getVirtProxy()); |
418 419 return (result == -1) ? -errno : result; 420} 421 422SyscallReturn 423readlinkFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 424{ 425 return readlinkFunc(desc, callnum, tc, 0); 426} 427 428SyscallReturn 429readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, int index) 430{ 431 string path; 432 auto p = tc->getProcessPtr(); 433 | 418 419 return (result == -1) ? -errno : result; 420} 421 422SyscallReturn 423readlinkFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 424{ 425 return readlinkFunc(desc, callnum, tc, 0); 426} 427 428SyscallReturn 429readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, int index) 430{ 431 string path; 432 auto p = tc->getProcessPtr(); 433 |
434 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 434 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
435 return -EFAULT; 436 437 // Adjust path for cwd and redirection 438 path = p->checkPathRedirect(path); 439 440 Addr buf_ptr = p->getSyscallArg(tc, index); 441 size_t bufsiz = p->getSyscallArg(tc, index); 442 --- 32 unchanged lines hidden (view full) --- 475 } 476 477 // Issue a warning about potential unexpected results 478 warn_once("readlink() called on '/proc/self/exe' may yield unexpected " 479 "results in various settings.\n Returning '%s'\n", 480 (char*)buf.bufferPtr()); 481 } 482 | 435 return -EFAULT; 436 437 // Adjust path for cwd and redirection 438 path = p->checkPathRedirect(path); 439 440 Addr buf_ptr = p->getSyscallArg(tc, index); 441 size_t bufsiz = p->getSyscallArg(tc, index); 442 --- 32 unchanged lines hidden (view full) --- 475 } 476 477 // Issue a warning about potential unexpected results 478 warn_once("readlink() called on '/proc/self/exe' may yield unexpected " 479 "results in various settings.\n Returning '%s'\n", 480 (char*)buf.bufferPtr()); 481 } 482 |
483 buf.copyOut(tc->getMemProxy()); | 483 buf.copyOut(tc->getVirtProxy()); |
484 485 return (result == -1) ? -errno : result; 486} 487 488SyscallReturn 489unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 490{ 491 return unlinkHelper(desc, num, tc, 0); 492} 493 494SyscallReturn 495unlinkHelper(SyscallDesc *desc, int num, ThreadContext *tc, int index) 496{ 497 string path; 498 auto p = tc->getProcessPtr(); 499 | 484 485 return (result == -1) ? -errno : result; 486} 487 488SyscallReturn 489unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 490{ 491 return unlinkHelper(desc, num, tc, 0); 492} 493 494SyscallReturn 495unlinkHelper(SyscallDesc *desc, int num, ThreadContext *tc, int index) 496{ 497 string path; 498 auto p = tc->getProcessPtr(); 499 |
500 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 500 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
501 return -EFAULT; 502 503 path = p->checkPathRedirect(path); 504 505 int result = unlink(path.c_str()); 506 return (result == -1) ? -errno : result; 507} 508 509SyscallReturn 510linkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 511{ 512 string path; 513 string new_path; 514 auto p = tc->getProcessPtr(); 515 516 int index = 0; | 501 return -EFAULT; 502 503 path = p->checkPathRedirect(path); 504 505 int result = unlink(path.c_str()); 506 return (result == -1) ? -errno : result; 507} 508 509SyscallReturn 510linkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 511{ 512 string path; 513 string new_path; 514 auto p = tc->getProcessPtr(); 515 516 int index = 0; |
517 auto &virt_mem = tc->getMemProxy(); | 517 auto &virt_mem = tc->getVirtProxy(); |
518 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 519 return -EFAULT; 520 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 521 return -EFAULT; 522 523 path = p->absolutePath(path, true); 524 new_path = p->absolutePath(new_path, true); 525 --- 4 unchanged lines hidden (view full) --- 530SyscallReturn 531symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 532{ 533 string path; 534 string new_path; 535 auto p = tc->getProcessPtr(); 536 537 int index = 0; | 518 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 519 return -EFAULT; 520 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 521 return -EFAULT; 522 523 path = p->absolutePath(path, true); 524 new_path = p->absolutePath(new_path, true); 525 --- 4 unchanged lines hidden (view full) --- 530SyscallReturn 531symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) 532{ 533 string path; 534 string new_path; 535 auto p = tc->getProcessPtr(); 536 537 int index = 0; |
538 auto &virt_mem = tc->getMemProxy(); | 538 auto &virt_mem = tc->getVirtProxy(); |
539 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 540 return -EFAULT; 541 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 542 return -EFAULT; 543 544 path = p->absolutePath(path, true); 545 new_path = p->absolutePath(new_path, true); 546 547 int result = symlink(path.c_str(), new_path.c_str()); 548 return (result == -1) ? -errno : result; 549} 550 551SyscallReturn 552mkdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 553{ 554 auto p = tc->getProcessPtr(); 555 int index = 0; 556 std::string path; | 539 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 540 return -EFAULT; 541 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 542 return -EFAULT; 543 544 path = p->absolutePath(path, true); 545 new_path = p->absolutePath(new_path, true); 546 547 int result = symlink(path.c_str(), new_path.c_str()); 548 return (result == -1) ? -errno : result; 549} 550 551SyscallReturn 552mkdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 553{ 554 auto p = tc->getProcessPtr(); 555 int index = 0; 556 std::string path; |
557 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 557 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
558 return -EFAULT; 559 560 path = p->checkPathRedirect(path); 561 mode_t mode = p->getSyscallArg(tc, index); 562 563 auto result = mkdir(path.c_str(), mode); 564 return (result == -1) ? -errno : result; 565} 566 567SyscallReturn 568renameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 569{ 570 string old_name; 571 auto p = tc->getProcessPtr(); 572 573 int index = 0; | 558 return -EFAULT; 559 560 path = p->checkPathRedirect(path); 561 mode_t mode = p->getSyscallArg(tc, index); 562 563 auto result = mkdir(path.c_str(), mode); 564 return (result == -1) ? -errno : result; 565} 566 567SyscallReturn 568renameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 569{ 570 string old_name; 571 auto p = tc->getProcessPtr(); 572 573 int index = 0; |
574 if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) | 574 if (!tc->getVirtProxy().tryReadString( 575 old_name, p->getSyscallArg(tc, index))) { |
575 return -EFAULT; | 576 return -EFAULT; |
577 } |
|
576 577 string new_name; 578 | 578 579 string new_name; 580 |
579 if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index))) | 581 if (!tc->getVirtProxy().tryReadString( 582 new_name, p->getSyscallArg(tc, index))) { |
580 return -EFAULT; | 583 return -EFAULT; |
584 } |
|
581 582 // Adjust path for cwd and redirection 583 old_name = p->checkPathRedirect(old_name); 584 new_name = p->checkPathRedirect(new_name); 585 586 int64_t result = rename(old_name.c_str(), new_name.c_str()); 587 return (result == -1) ? -errno : result; 588} 589 590SyscallReturn 591truncateFunc(SyscallDesc *desc, int num, ThreadContext *tc) 592{ 593 string path; 594 auto p = tc->getProcessPtr(); 595 596 int index = 0; | 585 586 // Adjust path for cwd and redirection 587 old_name = p->checkPathRedirect(old_name); 588 new_name = p->checkPathRedirect(new_name); 589 590 int64_t result = rename(old_name.c_str(), new_name.c_str()); 591 return (result == -1) ? -errno : result; 592} 593 594SyscallReturn 595truncateFunc(SyscallDesc *desc, int num, ThreadContext *tc) 596{ 597 string path; 598 auto p = tc->getProcessPtr(); 599 600 int index = 0; |
597 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 601 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
598 return -EFAULT; 599 600 off_t length = p->getSyscallArg(tc, index); 601 602 // Adjust path for cwd and redirection 603 path = p->checkPathRedirect(path); 604 605 int result = truncate(path.c_str(), length); --- 19 unchanged lines hidden (view full) --- 625 626SyscallReturn 627truncate64Func(SyscallDesc *desc, int num, ThreadContext *tc) 628{ 629 int index = 0; 630 auto process = tc->getProcessPtr(); 631 string path; 632 | 602 return -EFAULT; 603 604 off_t length = p->getSyscallArg(tc, index); 605 606 // Adjust path for cwd and redirection 607 path = p->checkPathRedirect(path); 608 609 int result = truncate(path.c_str(), length); --- 19 unchanged lines hidden (view full) --- 629 630SyscallReturn 631truncate64Func(SyscallDesc *desc, int num, ThreadContext *tc) 632{ 633 int index = 0; 634 auto process = tc->getProcessPtr(); 635 string path; 636 |
633 if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) | 637 if (!tc->getVirtProxy().tryReadString( 638 path, process->getSyscallArg(tc, index))) { |
634 return -EFAULT; | 639 return -EFAULT; |
640 } |
|
635 636 int64_t length = process->getSyscallArg(tc, index, 64); 637 638 // Adjust path for cwd and redirection 639 path = process->checkPathRedirect(path); 640 641#if NO_STAT64 642 int result = truncate(path.c_str(), length); --- 37 unchanged lines hidden (view full) --- 680 681SyscallReturn 682chownFunc(SyscallDesc *desc, int num, ThreadContext *tc) 683{ 684 string path; 685 auto p = tc->getProcessPtr(); 686 687 int index = 0; | 641 642 int64_t length = process->getSyscallArg(tc, index, 64); 643 644 // Adjust path for cwd and redirection 645 path = process->checkPathRedirect(path); 646 647#if NO_STAT64 648 int result = truncate(path.c_str(), length); --- 37 unchanged lines hidden (view full) --- 686 687SyscallReturn 688chownFunc(SyscallDesc *desc, int num, ThreadContext *tc) 689{ 690 string path; 691 auto p = tc->getProcessPtr(); 692 693 int index = 0; |
688 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 694 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
689 return -EFAULT; 690 691 /* XXX endianess */ 692 uint32_t owner = p->getSyscallArg(tc, index); 693 uid_t hostOwner = owner; 694 uint32_t group = p->getSyscallArg(tc, index); 695 gid_t hostGroup = group; 696 --- 201 unchanged lines hidden (view full) --- 898 /** 899 * Copy the target file descriptors into buffer space and then copy 900 * the buffer space back into the target address space. 901 */ 902 BufferArg tgt_handle(tgt_addr, sizeof(int[2])); 903 int *buf_ptr = (int*)tgt_handle.bufferPtr(); 904 buf_ptr[0] = tgt_fds[0]; 905 buf_ptr[1] = tgt_fds[1]; | 695 return -EFAULT; 696 697 /* XXX endianess */ 698 uint32_t owner = p->getSyscallArg(tc, index); 699 uid_t hostOwner = owner; 700 uint32_t group = p->getSyscallArg(tc, index); 701 gid_t hostGroup = group; 702 --- 201 unchanged lines hidden (view full) --- 904 /** 905 * Copy the target file descriptors into buffer space and then copy 906 * the buffer space back into the target address space. 907 */ 908 BufferArg tgt_handle(tgt_addr, sizeof(int[2])); 909 int *buf_ptr = (int*)tgt_handle.bufferPtr(); 910 buf_ptr[0] = tgt_fds[0]; 911 buf_ptr[1] = tgt_fds[1]; |
906 tgt_handle.copyOut(tc->getMemProxy()); | 912 tgt_handle.copyOut(tc->getVirtProxy()); |
907 return 0; 908} 909 910SyscallReturn 911pipePseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 912{ 913 return pipeImpl(desc, callnum, tc, true); 914} --- 161 unchanged lines hidden (view full) --- 1076#endif 1077} 1078 1079SyscallReturn 1080accessFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int index) 1081{ 1082 string path; 1083 auto p = tc->getProcessPtr(); | 913 return 0; 914} 915 916SyscallReturn 917pipePseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 918{ 919 return pipeImpl(desc, callnum, tc, true); 920} --- 161 unchanged lines hidden (view full) --- 1082#endif 1083} 1084 1085SyscallReturn 1086accessFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int index) 1087{ 1088 string path; 1089 auto p = tc->getProcessPtr(); |
1084 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 1090 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
1085 return -EFAULT; 1086 1087 // Adjust path for cwd and redirection 1088 path = p->checkPathRedirect(path); 1089 1090 mode_t mode = p->getSyscallArg(tc, index); 1091 1092 int result = access(path.c_str(), mode); --- 7 unchanged lines hidden (view full) --- 1100} 1101 1102SyscallReturn 1103mknodFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1104{ 1105 auto p = tc->getProcessPtr(); 1106 int index = 0; 1107 std::string path; | 1091 return -EFAULT; 1092 1093 // Adjust path for cwd and redirection 1094 path = p->checkPathRedirect(path); 1095 1096 mode_t mode = p->getSyscallArg(tc, index); 1097 1098 int result = access(path.c_str(), mode); --- 7 unchanged lines hidden (view full) --- 1106} 1107 1108SyscallReturn 1109mknodFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1110{ 1111 auto p = tc->getProcessPtr(); 1112 int index = 0; 1113 std::string path; |
1108 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 1114 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
1109 return -EFAULT; 1110 1111 path = p->checkPathRedirect(path); 1112 mode_t mode = p->getSyscallArg(tc, index); 1113 dev_t dev = p->getSyscallArg(tc, index); 1114 1115 auto result = mknod(path.c_str(), mode, dev); 1116 return (result == -1) ? -errno : result; 1117} 1118 1119SyscallReturn 1120chdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1121{ 1122 auto p = tc->getProcessPtr(); 1123 int index = 0; 1124 std::string path; | 1115 return -EFAULT; 1116 1117 path = p->checkPathRedirect(path); 1118 mode_t mode = p->getSyscallArg(tc, index); 1119 dev_t dev = p->getSyscallArg(tc, index); 1120 1121 auto result = mknod(path.c_str(), mode, dev); 1122 return (result == -1) ? -errno : result; 1123} 1124 1125SyscallReturn 1126chdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1127{ 1128 auto p = tc->getProcessPtr(); 1129 int index = 0; 1130 std::string path; |
1125 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 1131 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
1126 return -EFAULT; 1127 1128 std::string tgt_cwd; 1129 if (startswith(path, "/")) { 1130 tgt_cwd = path; 1131 } else { 1132 char buf[PATH_MAX]; 1133 tgt_cwd = realpath((p->tgtCwd + "/" + path).c_str(), buf); --- 11 unchanged lines hidden (view full) --- 1145} 1146 1147SyscallReturn 1148rmdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1149{ 1150 auto p = tc->getProcessPtr(); 1151 int index = 0; 1152 std::string path; | 1132 return -EFAULT; 1133 1134 std::string tgt_cwd; 1135 if (startswith(path, "/")) { 1136 tgt_cwd = path; 1137 } else { 1138 char buf[PATH_MAX]; 1139 tgt_cwd = realpath((p->tgtCwd + "/" + path).c_str(), buf); --- 11 unchanged lines hidden (view full) --- 1151} 1152 1153SyscallReturn 1154rmdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1155{ 1156 auto p = tc->getProcessPtr(); 1157 int index = 0; 1158 std::string path; |
1153 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) | 1159 if (!tc->getVirtProxy().tryReadString(path, p->getSyscallArg(tc, index))) |
1154 return -EFAULT; 1155 1156 path = p->checkPathRedirect(path); 1157 1158 auto result = rmdir(path.c_str()); 1159 return (result == -1) ? -errno : result; 1160} 1161 --- 32 unchanged lines hidden (view full) --- 1194 */ 1195 buffer->d_ino = htog(buffer->d_ino); 1196 buffer->d_off = htog(buffer->d_off); 1197 buffer->d_reclen = htog(buffer->d_reclen); 1198 1199 traversed += host_reclen; 1200 } 1201 | 1160 return -EFAULT; 1161 1162 path = p->checkPathRedirect(path); 1163 1164 auto result = rmdir(path.c_str()); 1165 return (result == -1) ? -errno : result; 1166} 1167 --- 32 unchanged lines hidden (view full) --- 1200 */ 1201 buffer->d_ino = htog(buffer->d_ino); 1202 buffer->d_off = htog(buffer->d_off); 1203 buffer->d_reclen = htog(buffer->d_reclen); 1204 1205 traversed += host_reclen; 1206 } 1207 |
1202 buf_arg.copyOut(tc->getMemProxy()); | 1208 buf_arg.copyOut(tc->getVirtProxy()); |
1203 return status; 1204} 1205#endif 1206 1207#if defined(SYS_getdents) 1208SyscallReturn 1209getdentsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 1210{ --- 46 unchanged lines hidden (view full) --- 1257{ 1258 int index = 0; 1259 auto p = tc->getProcessPtr(); 1260 int tgt_fd = p->getSyscallArg(tc, index); 1261 Addr buf_ptr = p->getSyscallArg(tc, index); 1262 int addrlen = p->getSyscallArg(tc, index); 1263 1264 BufferArg bufSock(buf_ptr, addrlen); | 1209 return status; 1210} 1211#endif 1212 1213#if defined(SYS_getdents) 1214SyscallReturn 1215getdentsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) 1216{ --- 46 unchanged lines hidden (view full) --- 1263{ 1264 int index = 0; 1265 auto p = tc->getProcessPtr(); 1266 int tgt_fd = p->getSyscallArg(tc, index); 1267 Addr buf_ptr = p->getSyscallArg(tc, index); 1268 int addrlen = p->getSyscallArg(tc, index); 1269 1270 BufferArg bufSock(buf_ptr, addrlen); |
1265 bufSock.copyIn(tc->getMemProxy()); | 1271 bufSock.copyIn(tc->getVirtProxy()); |
1266 1267 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1268 if (!sfdp) 1269 return -EBADF; 1270 int sim_fd = sfdp->getSimFD(); 1271 1272 int status = ::bind(sim_fd, 1273 (struct sockaddr *)bufSock.bufferPtr(), --- 25 unchanged lines hidden (view full) --- 1299{ 1300 int index = 0; 1301 auto p = tc->getProcessPtr(); 1302 int tgt_fd = p->getSyscallArg(tc, index); 1303 Addr buf_ptr = p->getSyscallArg(tc, index); 1304 int addrlen = p->getSyscallArg(tc, index); 1305 1306 BufferArg addr(buf_ptr, addrlen); | 1272 1273 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1274 if (!sfdp) 1275 return -EBADF; 1276 int sim_fd = sfdp->getSimFD(); 1277 1278 int status = ::bind(sim_fd, 1279 (struct sockaddr *)bufSock.bufferPtr(), --- 25 unchanged lines hidden (view full) --- 1305{ 1306 int index = 0; 1307 auto p = tc->getProcessPtr(); 1308 int tgt_fd = p->getSyscallArg(tc, index); 1309 Addr buf_ptr = p->getSyscallArg(tc, index); 1310 int addrlen = p->getSyscallArg(tc, index); 1311 1312 BufferArg addr(buf_ptr, addrlen); |
1307 addr.copyIn(tc->getMemProxy()); | 1313 addr.copyIn(tc->getVirtProxy()); |
1308 1309 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1310 if (!sfdp) 1311 return -EBADF; 1312 int sim_fd = sfdp->getSimFD(); 1313 1314 int status = connect(sim_fd, 1315 (struct sockaddr *)addr.bufferPtr(), --- 22 unchanged lines hidden (view full) --- 1338 // Reserve buffer space. 1339 BufferArg bufrBuf(bufrPtr, bufrLen); 1340 1341 // Get address length. 1342 socklen_t addrLen = 0; 1343 if (addrlenPtr != 0) { 1344 // Read address length parameter. 1345 BufferArg addrlenBuf(addrlenPtr, sizeof(socklen_t)); | 1314 1315 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1316 if (!sfdp) 1317 return -EBADF; 1318 int sim_fd = sfdp->getSimFD(); 1319 1320 int status = connect(sim_fd, 1321 (struct sockaddr *)addr.bufferPtr(), --- 22 unchanged lines hidden (view full) --- 1344 // Reserve buffer space. 1345 BufferArg bufrBuf(bufrPtr, bufrLen); 1346 1347 // Get address length. 1348 socklen_t addrLen = 0; 1349 if (addrlenPtr != 0) { 1350 // Read address length parameter. 1351 BufferArg addrlenBuf(addrlenPtr, sizeof(socklen_t)); |
1346 addrlenBuf.copyIn(tc->getMemProxy()); | 1352 addrlenBuf.copyIn(tc->getVirtProxy()); |
1347 addrLen = *((socklen_t *)addrlenBuf.bufferPtr()); 1348 } 1349 1350 struct sockaddr sa, *sap = NULL; 1351 if (addrLen != 0) { 1352 BufferArg addrBuf(addrPtr, addrLen); | 1353 addrLen = *((socklen_t *)addrlenBuf.bufferPtr()); 1354 } 1355 1356 struct sockaddr sa, *sap = NULL; 1357 if (addrLen != 0) { 1358 BufferArg addrBuf(addrPtr, addrLen); |
1353 addrBuf.copyIn(tc->getMemProxy()); | 1359 addrBuf.copyIn(tc->getVirtProxy()); |
1354 memcpy(&sa, (struct sockaddr *)addrBuf.bufferPtr(), 1355 sizeof(struct sockaddr)); 1356 sap = &sa; 1357 } 1358 1359 ssize_t recvd_size = recvfrom(sim_fd, 1360 (void *)bufrBuf.bufferPtr(), 1361 bufrLen, flags, sap, (socklen_t *)&addrLen); 1362 1363 if (recvd_size == -1) 1364 return -errno; 1365 1366 // Pass the received data out. | 1360 memcpy(&sa, (struct sockaddr *)addrBuf.bufferPtr(), 1361 sizeof(struct sockaddr)); 1362 sap = &sa; 1363 } 1364 1365 ssize_t recvd_size = recvfrom(sim_fd, 1366 (void *)bufrBuf.bufferPtr(), 1367 bufrLen, flags, sap, (socklen_t *)&addrLen); 1368 1369 if (recvd_size == -1) 1370 return -errno; 1371 1372 // Pass the received data out. |
1367 bufrBuf.copyOut(tc->getMemProxy()); | 1373 bufrBuf.copyOut(tc->getVirtProxy()); |
1368 1369 // Copy address to addrPtr and pass it on. 1370 if (sap != NULL) { 1371 BufferArg addrBuf(addrPtr, addrLen); 1372 memcpy(addrBuf.bufferPtr(), sap, sizeof(sa)); | 1374 1375 // Copy address to addrPtr and pass it on. 1376 if (sap != NULL) { 1377 BufferArg addrBuf(addrPtr, addrLen); 1378 memcpy(addrBuf.bufferPtr(), sap, sizeof(sa)); |
1373 addrBuf.copyOut(tc->getMemProxy()); | 1379 addrBuf.copyOut(tc->getVirtProxy()); |
1374 } 1375 1376 // Copy len to addrlenPtr and pass it on. 1377 if (addrLen != 0) { 1378 BufferArg addrlenBuf(addrlenPtr, sizeof(socklen_t)); 1379 *(socklen_t *)addrlenBuf.bufferPtr() = addrLen; | 1380 } 1381 1382 // Copy len to addrlenPtr and pass it on. 1383 if (addrLen != 0) { 1384 BufferArg addrlenBuf(addrlenPtr, sizeof(socklen_t)); 1385 *(socklen_t *)addrlenBuf.bufferPtr() = addrLen; |
1380 addrlenBuf.copyOut(tc->getMemProxy()); | 1386 addrlenBuf.copyOut(tc->getVirtProxy()); |
1381 } 1382 1383 return recvd_size; 1384} 1385 1386SyscallReturn 1387sendtoFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1388{ --- 8 unchanged lines hidden (view full) --- 1397 1398 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1399 if (!sfdp) 1400 return -EBADF; 1401 int sim_fd = sfdp->getSimFD(); 1402 1403 // Reserve buffer space. 1404 BufferArg bufrBuf(bufrPtr, bufrLen); | 1387 } 1388 1389 return recvd_size; 1390} 1391 1392SyscallReturn 1393sendtoFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1394{ --- 8 unchanged lines hidden (view full) --- 1403 1404 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1405 if (!sfdp) 1406 return -EBADF; 1407 int sim_fd = sfdp->getSimFD(); 1408 1409 // Reserve buffer space. 1410 BufferArg bufrBuf(bufrPtr, bufrLen); |
1405 bufrBuf.copyIn(tc->getMemProxy()); | 1411 bufrBuf.copyIn(tc->getVirtProxy()); |
1406 1407 struct sockaddr sa, *sap = nullptr; 1408 memset(&sa, 0, sizeof(sockaddr)); 1409 if (addrLen != 0) { 1410 BufferArg addrBuf(addrPtr, addrLen); | 1412 1413 struct sockaddr sa, *sap = nullptr; 1414 memset(&sa, 0, sizeof(sockaddr)); 1415 if (addrLen != 0) { 1416 BufferArg addrBuf(addrPtr, addrLen); |
1411 addrBuf.copyIn(tc->getMemProxy()); | 1417 addrBuf.copyIn(tc->getVirtProxy()); |
1412 memcpy(&sa, (sockaddr*)addrBuf.bufferPtr(), addrLen); 1413 sap = &sa; 1414 } 1415 1416 ssize_t sent_size = sendto(sim_fd, 1417 (void *)bufrBuf.bufferPtr(), 1418 bufrLen, flags, sap, (socklen_t)addrLen); 1419 --- 33 unchanged lines hidden (view full) --- 1453 */ 1454 1455 /** 1456 * The plan with this system call is to replace all of the pointers in the 1457 * structure and the substructure with BufferArg class pointers. We will 1458 * copy every field from the structures into our BufferArg classes. 1459 */ 1460 BufferArg msgBuf(msgPtr, sizeof(struct msghdr)); | 1418 memcpy(&sa, (sockaddr*)addrBuf.bufferPtr(), addrLen); 1419 sap = &sa; 1420 } 1421 1422 ssize_t sent_size = sendto(sim_fd, 1423 (void *)bufrBuf.bufferPtr(), 1424 bufrLen, flags, sap, (socklen_t)addrLen); 1425 --- 33 unchanged lines hidden (view full) --- 1459 */ 1460 1461 /** 1462 * The plan with this system call is to replace all of the pointers in the 1463 * structure and the substructure with BufferArg class pointers. We will 1464 * copy every field from the structures into our BufferArg classes. 1465 */ 1466 BufferArg msgBuf(msgPtr, sizeof(struct msghdr)); |
1461 msgBuf.copyIn(tc->getMemProxy()); | 1467 msgBuf.copyIn(tc->getVirtProxy()); |
1462 struct msghdr *msgHdr = (struct msghdr *)msgBuf.bufferPtr(); 1463 1464 /** 1465 * We will use these address place holders to retain the pointers which 1466 * we are going to replace with our own buffers in our simulator address 1467 * space. 1468 */ 1469 Addr msg_name_phold = 0; 1470 Addr msg_iov_phold = 0; 1471 Addr iovec_base_phold[msgHdr->msg_iovlen]; 1472 Addr msg_control_phold = 0; 1473 1474 /** 1475 * Record msg_name pointer then replace with buffer pointer. 1476 */ 1477 BufferArg *nameBuf = NULL; 1478 if (msgHdr->msg_name) { 1479 /*1*/msg_name_phold = (Addr)msgHdr->msg_name; 1480 /*2*/nameBuf = new BufferArg(msg_name_phold, msgHdr->msg_namelen); | 1468 struct msghdr *msgHdr = (struct msghdr *)msgBuf.bufferPtr(); 1469 1470 /** 1471 * We will use these address place holders to retain the pointers which 1472 * we are going to replace with our own buffers in our simulator address 1473 * space. 1474 */ 1475 Addr msg_name_phold = 0; 1476 Addr msg_iov_phold = 0; 1477 Addr iovec_base_phold[msgHdr->msg_iovlen]; 1478 Addr msg_control_phold = 0; 1479 1480 /** 1481 * Record msg_name pointer then replace with buffer pointer. 1482 */ 1483 BufferArg *nameBuf = NULL; 1484 if (msgHdr->msg_name) { 1485 /*1*/msg_name_phold = (Addr)msgHdr->msg_name; 1486 /*2*/nameBuf = new BufferArg(msg_name_phold, msgHdr->msg_namelen); |
1481 /*3*/nameBuf->copyIn(tc->getMemProxy()); | 1487 /*3*/nameBuf->copyIn(tc->getVirtProxy()); |
1482 /*4*/msgHdr->msg_name = nameBuf->bufferPtr(); 1483 } 1484 1485 /** 1486 * Record msg_iov pointer then replace with buffer pointer. Also, setup 1487 * an array of buffer pointers for the iovec structs record and replace 1488 * their pointers with buffer pointers. 1489 */ 1490 BufferArg *iovBuf = NULL; 1491 BufferArg *iovecBuf[msgHdr->msg_iovlen]; 1492 for (int i = 0; i < msgHdr->msg_iovlen; i++) { 1493 iovec_base_phold[i] = 0; 1494 iovecBuf[i] = NULL; 1495 } 1496 1497 if (msgHdr->msg_iov) { 1498 /*1*/msg_iov_phold = (Addr)msgHdr->msg_iov; 1499 /*2*/iovBuf = new BufferArg(msg_iov_phold, msgHdr->msg_iovlen * 1500 sizeof(struct iovec)); | 1488 /*4*/msgHdr->msg_name = nameBuf->bufferPtr(); 1489 } 1490 1491 /** 1492 * Record msg_iov pointer then replace with buffer pointer. Also, setup 1493 * an array of buffer pointers for the iovec structs record and replace 1494 * their pointers with buffer pointers. 1495 */ 1496 BufferArg *iovBuf = NULL; 1497 BufferArg *iovecBuf[msgHdr->msg_iovlen]; 1498 for (int i = 0; i < msgHdr->msg_iovlen; i++) { 1499 iovec_base_phold[i] = 0; 1500 iovecBuf[i] = NULL; 1501 } 1502 1503 if (msgHdr->msg_iov) { 1504 /*1*/msg_iov_phold = (Addr)msgHdr->msg_iov; 1505 /*2*/iovBuf = new BufferArg(msg_iov_phold, msgHdr->msg_iovlen * 1506 sizeof(struct iovec)); |
1501 /*3*/iovBuf->copyIn(tc->getMemProxy()); | 1507 /*3*/iovBuf->copyIn(tc->getVirtProxy()); |
1502 for (int i = 0; i < msgHdr->msg_iovlen; i++) { 1503 if (((struct iovec *)iovBuf->bufferPtr())[i].iov_base) { 1504 /*1*/iovec_base_phold[i] = 1505 (Addr)((struct iovec *)iovBuf->bufferPtr())[i].iov_base; 1506 /*2*/iovecBuf[i] = new BufferArg(iovec_base_phold[i], 1507 ((struct iovec *)iovBuf->bufferPtr())[i].iov_len); | 1508 for (int i = 0; i < msgHdr->msg_iovlen; i++) { 1509 if (((struct iovec *)iovBuf->bufferPtr())[i].iov_base) { 1510 /*1*/iovec_base_phold[i] = 1511 (Addr)((struct iovec *)iovBuf->bufferPtr())[i].iov_base; 1512 /*2*/iovecBuf[i] = new BufferArg(iovec_base_phold[i], 1513 ((struct iovec *)iovBuf->bufferPtr())[i].iov_len); |
1508 /*3*/iovecBuf[i]->copyIn(tc->getMemProxy()); | 1514 /*3*/iovecBuf[i]->copyIn(tc->getVirtProxy()); |
1509 /*4*/((struct iovec *)iovBuf->bufferPtr())[i].iov_base = 1510 iovecBuf[i]->bufferPtr(); 1511 } 1512 } 1513 /*4*/msgHdr->msg_iov = (struct iovec *)iovBuf->bufferPtr(); 1514 } 1515 1516 /** 1517 * Record msg_control pointer then replace with buffer pointer. 1518 */ 1519 BufferArg *controlBuf = NULL; 1520 if (msgHdr->msg_control) { 1521 /*1*/msg_control_phold = (Addr)msgHdr->msg_control; 1522 /*2*/controlBuf = new BufferArg(msg_control_phold, 1523 CMSG_ALIGN(msgHdr->msg_controllen)); | 1515 /*4*/((struct iovec *)iovBuf->bufferPtr())[i].iov_base = 1516 iovecBuf[i]->bufferPtr(); 1517 } 1518 } 1519 /*4*/msgHdr->msg_iov = (struct iovec *)iovBuf->bufferPtr(); 1520 } 1521 1522 /** 1523 * Record msg_control pointer then replace with buffer pointer. 1524 */ 1525 BufferArg *controlBuf = NULL; 1526 if (msgHdr->msg_control) { 1527 /*1*/msg_control_phold = (Addr)msgHdr->msg_control; 1528 /*2*/controlBuf = new BufferArg(msg_control_phold, 1529 CMSG_ALIGN(msgHdr->msg_controllen)); |
1524 /*3*/controlBuf->copyIn(tc->getMemProxy()); | 1530 /*3*/controlBuf->copyIn(tc->getVirtProxy()); |
1525 /*4*/msgHdr->msg_control = controlBuf->bufferPtr(); 1526 } 1527 1528 ssize_t recvd_size = recvmsg(sim_fd, msgHdr, flags); 1529 1530 if (recvd_size < 0) 1531 return -errno; 1532 1533 if (msgHdr->msg_name) { | 1531 /*4*/msgHdr->msg_control = controlBuf->bufferPtr(); 1532 } 1533 1534 ssize_t recvd_size = recvmsg(sim_fd, msgHdr, flags); 1535 1536 if (recvd_size < 0) 1537 return -errno; 1538 1539 if (msgHdr->msg_name) { |
1534 nameBuf->copyOut(tc->getMemProxy()); | 1540 nameBuf->copyOut(tc->getVirtProxy()); |
1535 delete(nameBuf); 1536 msgHdr->msg_name = (void *)msg_name_phold; 1537 } 1538 1539 if (msgHdr->msg_iov) { 1540 for (int i = 0; i< msgHdr->msg_iovlen; i++) { 1541 if (((struct iovec *)iovBuf->bufferPtr())[i].iov_base) { | 1541 delete(nameBuf); 1542 msgHdr->msg_name = (void *)msg_name_phold; 1543 } 1544 1545 if (msgHdr->msg_iov) { 1546 for (int i = 0; i< msgHdr->msg_iovlen; i++) { 1547 if (((struct iovec *)iovBuf->bufferPtr())[i].iov_base) { |
1542 iovecBuf[i]->copyOut(tc->getMemProxy()); | 1548 iovecBuf[i]->copyOut(tc->getVirtProxy()); |
1543 delete iovecBuf[i]; 1544 ((struct iovec *)iovBuf->bufferPtr())[i].iov_base = 1545 (void *)iovec_base_phold[i]; 1546 } 1547 } | 1549 delete iovecBuf[i]; 1550 ((struct iovec *)iovBuf->bufferPtr())[i].iov_base = 1551 (void *)iovec_base_phold[i]; 1552 } 1553 } |
1548 iovBuf->copyOut(tc->getMemProxy()); | 1554 iovBuf->copyOut(tc->getVirtProxy()); |
1549 delete iovBuf; 1550 msgHdr->msg_iov = (struct iovec *)msg_iov_phold; 1551 } 1552 1553 if (msgHdr->msg_control) { | 1555 delete iovBuf; 1556 msgHdr->msg_iov = (struct iovec *)msg_iov_phold; 1557 } 1558 1559 if (msgHdr->msg_control) { |
1554 controlBuf->copyOut(tc->getMemProxy()); | 1560 controlBuf->copyOut(tc->getVirtProxy()); |
1555 delete(controlBuf); 1556 msgHdr->msg_control = (void *)msg_control_phold; 1557 } 1558 | 1561 delete(controlBuf); 1562 msgHdr->msg_control = (void *)msg_control_phold; 1563 } 1564 |
1559 msgBuf.copyOut(tc->getMemProxy()); | 1565 msgBuf.copyOut(tc->getVirtProxy()); |
1560 1561 return recvd_size; 1562} 1563 1564SyscallReturn 1565sendmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1566{ 1567 int index = 0; --- 6 unchanged lines hidden (view full) --- 1574 if (!sfdp) 1575 return -EBADF; 1576 int sim_fd = sfdp->getSimFD(); 1577 1578 /** 1579 * Reserve buffer space. 1580 */ 1581 BufferArg msgBuf(msgPtr, sizeof(struct msghdr)); | 1566 1567 return recvd_size; 1568} 1569 1570SyscallReturn 1571sendmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1572{ 1573 int index = 0; --- 6 unchanged lines hidden (view full) --- 1580 if (!sfdp) 1581 return -EBADF; 1582 int sim_fd = sfdp->getSimFD(); 1583 1584 /** 1585 * Reserve buffer space. 1586 */ 1587 BufferArg msgBuf(msgPtr, sizeof(struct msghdr)); |
1582 msgBuf.copyIn(tc->getMemProxy()); | 1588 msgBuf.copyIn(tc->getVirtProxy()); |
1583 struct msghdr msgHdr = *((struct msghdr *)msgBuf.bufferPtr()); 1584 1585 /** 1586 * Assuming msgHdr.msg_iovlen >= 1, then there is no point calling 1587 * recvmsg without a buffer. 1588 */ 1589 struct iovec *iovPtr = msgHdr.msg_iov; 1590 BufferArg iovBuf((Addr)iovPtr, sizeof(struct iovec) * msgHdr.msg_iovlen); | 1589 struct msghdr msgHdr = *((struct msghdr *)msgBuf.bufferPtr()); 1590 1591 /** 1592 * Assuming msgHdr.msg_iovlen >= 1, then there is no point calling 1593 * recvmsg without a buffer. 1594 */ 1595 struct iovec *iovPtr = msgHdr.msg_iov; 1596 BufferArg iovBuf((Addr)iovPtr, sizeof(struct iovec) * msgHdr.msg_iovlen); |
1591 iovBuf.copyIn(tc->getMemProxy()); | 1597 iovBuf.copyIn(tc->getVirtProxy()); |
1592 struct iovec *iov = (struct iovec *)iovBuf.bufferPtr(); 1593 msgHdr.msg_iov = iov; 1594 1595 /** 1596 * Cannot instantiate buffers till inside the loop. 1597 * Create array to hold buffer addresses, to be used during copyIn of 1598 * send data. 1599 */ 1600 BufferArg **bufferArray = (BufferArg **)malloc(msgHdr.msg_iovlen 1601 * sizeof(BufferArg *)); 1602 1603 /** 1604 * Iterate through the iovec structures: 1605 * Get the base buffer addreses, reserve iov_len amount of space for each. 1606 * Put the buf address into the bufferArray for later retrieval. 1607 */ 1608 for (int iovIndex = 0 ; iovIndex < msgHdr.msg_iovlen; iovIndex++) { 1609 Addr basePtr = (Addr) iov[iovIndex].iov_base; 1610 bufferArray[iovIndex] = new BufferArg(basePtr, iov[iovIndex].iov_len); | 1598 struct iovec *iov = (struct iovec *)iovBuf.bufferPtr(); 1599 msgHdr.msg_iov = iov; 1600 1601 /** 1602 * Cannot instantiate buffers till inside the loop. 1603 * Create array to hold buffer addresses, to be used during copyIn of 1604 * send data. 1605 */ 1606 BufferArg **bufferArray = (BufferArg **)malloc(msgHdr.msg_iovlen 1607 * sizeof(BufferArg *)); 1608 1609 /** 1610 * Iterate through the iovec structures: 1611 * Get the base buffer addreses, reserve iov_len amount of space for each. 1612 * Put the buf address into the bufferArray for later retrieval. 1613 */ 1614 for (int iovIndex = 0 ; iovIndex < msgHdr.msg_iovlen; iovIndex++) { 1615 Addr basePtr = (Addr) iov[iovIndex].iov_base; 1616 bufferArray[iovIndex] = new BufferArg(basePtr, iov[iovIndex].iov_len); |
1611 bufferArray[iovIndex]->copyIn(tc->getMemProxy()); | 1617 bufferArray[iovIndex]->copyIn(tc->getVirtProxy()); |
1612 iov[iovIndex].iov_base = bufferArray[iovIndex]->bufferPtr(); 1613 } 1614 1615 ssize_t sent_size = sendmsg(sim_fd, &msgHdr, flags); 1616 int local_errno = errno; 1617 1618 /** 1619 * Free dynamically allocated memory. --- 39 unchanged lines hidden (view full) --- 1659 int status = getsockopt(sim_fd, level, optname, &val, &len); 1660 1661 if (status == -1) 1662 return -errno; 1663 1664 // copy val to valPtr and pass it on 1665 BufferArg valBuf(valPtr, sizeof(val)); 1666 memcpy(valBuf.bufferPtr(), &val, sizeof(val)); | 1618 iov[iovIndex].iov_base = bufferArray[iovIndex]->bufferPtr(); 1619 } 1620 1621 ssize_t sent_size = sendmsg(sim_fd, &msgHdr, flags); 1622 int local_errno = errno; 1623 1624 /** 1625 * Free dynamically allocated memory. --- 39 unchanged lines hidden (view full) --- 1665 int status = getsockopt(sim_fd, level, optname, &val, &len); 1666 1667 if (status == -1) 1668 return -errno; 1669 1670 // copy val to valPtr and pass it on 1671 BufferArg valBuf(valPtr, sizeof(val)); 1672 memcpy(valBuf.bufferPtr(), &val, sizeof(val)); |
1667 valBuf.copyOut(tc->getMemProxy()); | 1673 valBuf.copyOut(tc->getVirtProxy()); |
1668 1669 // copy len to lenPtr and pass it on 1670 BufferArg lenBuf(lenPtr, sizeof(len)); 1671 memcpy(lenBuf.bufferPtr(), &len, sizeof(len)); | 1674 1675 // copy len to lenPtr and pass it on 1676 BufferArg lenBuf(lenPtr, sizeof(len)); 1677 memcpy(lenBuf.bufferPtr(), &len, sizeof(len)); |
1672 lenBuf.copyOut(tc->getMemProxy()); | 1678 lenBuf.copyOut(tc->getVirtProxy()); |
1673 1674 return status; 1675} 1676 1677SyscallReturn 1678getsocknameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1679{ 1680 int index = 0; --- 7 unchanged lines hidden (view full) --- 1688 return -EBADF; 1689 int sim_fd = sfdp->getSimFD(); 1690 1691 // lenPtr is an in-out paramenter: 1692 // sending the address length in, conveying the final length out 1693 1694 // Read in the value of len from the passed pointer. 1695 BufferArg lenBuf(lenPtr, sizeof(socklen_t)); | 1679 1680 return status; 1681} 1682 1683SyscallReturn 1684getsocknameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1685{ 1686 int index = 0; --- 7 unchanged lines hidden (view full) --- 1694 return -EBADF; 1695 int sim_fd = sfdp->getSimFD(); 1696 1697 // lenPtr is an in-out paramenter: 1698 // sending the address length in, conveying the final length out 1699 1700 // Read in the value of len from the passed pointer. 1701 BufferArg lenBuf(lenPtr, sizeof(socklen_t)); |
1696 lenBuf.copyIn(tc->getMemProxy()); | 1702 lenBuf.copyIn(tc->getVirtProxy()); |
1697 socklen_t len = *(socklen_t *)lenBuf.bufferPtr(); 1698 1699 struct sockaddr sa; 1700 int status = getsockname(sim_fd, &sa, &len); 1701 1702 if (status == -1) 1703 return -errno; 1704 1705 // Copy address to addrPtr and pass it on. 1706 BufferArg addrBuf(addrPtr, sizeof(sa)); 1707 memcpy(addrBuf.bufferPtr(), &sa, sizeof(sa)); | 1703 socklen_t len = *(socklen_t *)lenBuf.bufferPtr(); 1704 1705 struct sockaddr sa; 1706 int status = getsockname(sim_fd, &sa, &len); 1707 1708 if (status == -1) 1709 return -errno; 1710 1711 // Copy address to addrPtr and pass it on. 1712 BufferArg addrBuf(addrPtr, sizeof(sa)); 1713 memcpy(addrBuf.bufferPtr(), &sa, sizeof(sa)); |
1708 addrBuf.copyOut(tc->getMemProxy()); | 1714 addrBuf.copyOut(tc->getVirtProxy()); |
1709 1710 // Copy len to lenPtr and pass it on. 1711 *(socklen_t *)lenBuf.bufferPtr() = len; | 1715 1716 // Copy len to lenPtr and pass it on. 1717 *(socklen_t *)lenBuf.bufferPtr() = len; |
1712 lenBuf.copyOut(tc->getMemProxy()); | 1718 lenBuf.copyOut(tc->getVirtProxy()); |
1713 1714 return status; 1715} 1716 1717SyscallReturn 1718getpeernameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1719{ 1720 int index = 0; 1721 auto p = tc->getProcessPtr(); 1722 int tgt_fd = p->getSyscallArg(tc, index); 1723 Addr sockAddrPtr = p->getSyscallArg(tc, index); 1724 Addr addrlenPtr = p->getSyscallArg(tc, index); 1725 1726 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1727 if (!sfdp) 1728 return -EBADF; 1729 int sim_fd = sfdp->getSimFD(); 1730 1731 BufferArg bufAddrlen(addrlenPtr, sizeof(unsigned)); | 1719 1720 return status; 1721} 1722 1723SyscallReturn 1724getpeernameFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1725{ 1726 int index = 0; 1727 auto p = tc->getProcessPtr(); 1728 int tgt_fd = p->getSyscallArg(tc, index); 1729 Addr sockAddrPtr = p->getSyscallArg(tc, index); 1730 Addr addrlenPtr = p->getSyscallArg(tc, index); 1731 1732 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1733 if (!sfdp) 1734 return -EBADF; 1735 int sim_fd = sfdp->getSimFD(); 1736 1737 BufferArg bufAddrlen(addrlenPtr, sizeof(unsigned)); |
1732 bufAddrlen.copyIn(tc->getMemProxy()); | 1738 bufAddrlen.copyIn(tc->getVirtProxy()); |
1733 BufferArg bufSock(sockAddrPtr, *(unsigned *)bufAddrlen.bufferPtr()); 1734 1735 int retval = getpeername(sim_fd, 1736 (struct sockaddr *)bufSock.bufferPtr(), 1737 (unsigned *)bufAddrlen.bufferPtr()); 1738 1739 if (retval != -1) { | 1739 BufferArg bufSock(sockAddrPtr, *(unsigned *)bufAddrlen.bufferPtr()); 1740 1741 int retval = getpeername(sim_fd, 1742 (struct sockaddr *)bufSock.bufferPtr(), 1743 (unsigned *)bufAddrlen.bufferPtr()); 1744 1745 if (retval != -1) { |
1740 bufSock.copyOut(tc->getMemProxy()); 1741 bufAddrlen.copyOut(tc->getMemProxy()); | 1746 bufSock.copyOut(tc->getVirtProxy()); 1747 bufAddrlen.copyOut(tc->getVirtProxy()); |
1742 } 1743 1744 return (retval == -1) ? -errno : retval; 1745} 1746 1747SyscallReturn 1748setsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1749{ 1750 int index = 0; 1751 auto p = tc->getProcessPtr(); 1752 int tgt_fd = p->getSyscallArg(tc, index); 1753 int level = p->getSyscallArg(tc, index); 1754 int optname = p->getSyscallArg(tc, index); 1755 Addr valPtr = p->getSyscallArg(tc, index); 1756 socklen_t len = p->getSyscallArg(tc, index); 1757 1758 BufferArg valBuf(valPtr, len); | 1748 } 1749 1750 return (retval == -1) ? -errno : retval; 1751} 1752 1753SyscallReturn 1754setsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc) 1755{ 1756 int index = 0; 1757 auto p = tc->getProcessPtr(); 1758 int tgt_fd = p->getSyscallArg(tc, index); 1759 int level = p->getSyscallArg(tc, index); 1760 int optname = p->getSyscallArg(tc, index); 1761 Addr valPtr = p->getSyscallArg(tc, index); 1762 socklen_t len = p->getSyscallArg(tc, index); 1763 1764 BufferArg valBuf(valPtr, len); |
1759 valBuf.copyIn(tc->getMemProxy()); | 1765 valBuf.copyIn(tc->getVirtProxy()); |
1760 1761 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1762 if (!sfdp) 1763 return -EBADF; 1764 int sim_fd = sfdp->getSimFD(); 1765 1766 int status = setsockopt(sim_fd, level, optname, 1767 (struct sockaddr *)valBuf.bufferPtr(), len); 1768 1769 return (status == -1) ? -errno : status; 1770} 1771 | 1766 1767 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]); 1768 if (!sfdp) 1769 return -EBADF; 1770 int sim_fd = sfdp->getSimFD(); 1771 1772 int status = setsockopt(sim_fd, level, optname, 1773 (struct sockaddr *)valBuf.bufferPtr(), len); 1774 1775 return (status == -1) ? -errno : status; 1776} 1777 |