syscall_emul.cc (13644:6180ee72e061) | syscall_emul.cc (13883:f44e21d3aaa7) |
---|---|
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; --- 374 unchanged lines hidden (view full) --- 383{ 384 int result = 0; 385 int index = 0; 386 Addr buf_ptr = p->getSyscallArg(tc, index); 387 unsigned long size = p->getSyscallArg(tc, index); 388 BufferArg buf(buf_ptr, size); 389 390 // Is current working directory defined? | 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; --- 374 unchanged lines hidden (view full) --- 383{ 384 int result = 0; 385 int index = 0; 386 Addr buf_ptr = p->getSyscallArg(tc, index); 387 unsigned long size = p->getSyscallArg(tc, index); 388 BufferArg buf(buf_ptr, size); 389 390 // Is current working directory defined? |
391 string cwd = p->getcwd(); | 391 string cwd = p->tgtCwd; |
392 if (!cwd.empty()) { 393 if (cwd.length() >= size) { 394 // Buffer too small 395 return -ERANGE; 396 } 397 strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 398 result = cwd.length(); 399 } else { --- 20 unchanged lines hidden (view full) --- 420readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 421 int index) 422{ 423 string path; 424 425 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 426 return -EFAULT; 427 | 392 if (!cwd.empty()) { 393 if (cwd.length() >= size) { 394 // Buffer too small 395 return -ERANGE; 396 } 397 strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 398 result = cwd.length(); 399 } else { --- 20 unchanged lines hidden (view full) --- 420readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 421 int index) 422{ 423 string path; 424 425 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 426 return -EFAULT; 427 |
428 // Adjust path for current working directory 429 path = p->fullPath(path); | 428 // Adjust path for cwd and redirection 429 path = p->checkPathRedirect(path); |
430 431 Addr buf_ptr = p->getSyscallArg(tc, index); 432 size_t bufsiz = p->getSyscallArg(tc, index); 433 434 BufferArg buf(buf_ptr, bufsiz); 435 436 int result = -1; 437 if (path != "/proc/self/exe") { --- 48 unchanged lines hidden (view full) --- 486unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 487 int index) 488{ 489 string path; 490 491 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 492 return -EFAULT; 493 | 430 431 Addr buf_ptr = p->getSyscallArg(tc, index); 432 size_t bufsiz = p->getSyscallArg(tc, index); 433 434 BufferArg buf(buf_ptr, bufsiz); 435 436 int result = -1; 437 if (path != "/proc/self/exe") { --- 48 unchanged lines hidden (view full) --- 486unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 487 int index) 488{ 489 string path; 490 491 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 492 return -EFAULT; 493 |
494 path = p->fullPath(path); | 494 path = p->checkPathRedirect(path); |
495 496 int result = unlink(path.c_str()); 497 return (result == -1) ? -errno : result; 498} 499 500SyscallReturn 501linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 502{ 503 string path; 504 string new_path; 505 506 int index = 0; 507 auto &virt_mem = tc->getMemProxy(); 508 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 509 return -EFAULT; 510 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 511 return -EFAULT; 512 | 495 496 int result = unlink(path.c_str()); 497 return (result == -1) ? -errno : result; 498} 499 500SyscallReturn 501linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 502{ 503 string path; 504 string new_path; 505 506 int index = 0; 507 auto &virt_mem = tc->getMemProxy(); 508 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 509 return -EFAULT; 510 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 511 return -EFAULT; 512 |
513 path = p->fullPath(path); 514 new_path = p->fullPath(new_path); | 513 path = p->absolutePath(path, true); 514 new_path = p->absolutePath(new_path, true); |
515 516 int result = link(path.c_str(), new_path.c_str()); 517 return (result == -1) ? -errno : result; 518} 519 520SyscallReturn 521symlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 522{ 523 string path; 524 string new_path; 525 526 int index = 0; 527 auto &virt_mem = tc->getMemProxy(); 528 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 529 return -EFAULT; 530 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 531 return -EFAULT; 532 | 515 516 int result = link(path.c_str(), new_path.c_str()); 517 return (result == -1) ? -errno : result; 518} 519 520SyscallReturn 521symlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 522{ 523 string path; 524 string new_path; 525 526 int index = 0; 527 auto &virt_mem = tc->getMemProxy(); 528 if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index))) 529 return -EFAULT; 530 if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index))) 531 return -EFAULT; 532 |
533 path = p->fullPath(path); 534 new_path = p->fullPath(new_path); | 533 path = p->absolutePath(path, true); 534 new_path = p->absolutePath(new_path, true); |
535 536 int result = symlink(path.c_str(), new_path.c_str()); 537 return (result == -1) ? -errno : result; 538} 539 540SyscallReturn 541mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 542{ | 535 536 int result = symlink(path.c_str(), new_path.c_str()); 537 return (result == -1) ? -errno : result; 538} 539 540SyscallReturn 541mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 542{ |
543 string path; 544 | |
545 int index = 0; | 543 int index = 0; |
544 std::string path; |
|
546 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 547 return -EFAULT; 548 | 545 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 546 return -EFAULT; 547 |
549 // Adjust path for current working directory 550 path = p->fullPath(path); 551 | 548 path = p->checkPathRedirect(path); |
552 mode_t mode = p->getSyscallArg(tc, index); 553 | 549 mode_t mode = p->getSyscallArg(tc, index); 550 |
554 int result = mkdir(path.c_str(), mode); | 551 auto result = mkdir(path.c_str(), mode); |
555 return (result == -1) ? -errno : result; 556} 557 558SyscallReturn 559renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 560{ 561 string old_name; 562 563 int index = 0; 564 if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) 565 return -EFAULT; 566 567 string new_name; 568 569 if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index))) 570 return -EFAULT; 571 | 552 return (result == -1) ? -errno : result; 553} 554 555SyscallReturn 556renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 557{ 558 string old_name; 559 560 int index = 0; 561 if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) 562 return -EFAULT; 563 564 string new_name; 565 566 if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index))) 567 return -EFAULT; 568 |
572 // Adjust path for current working directory 573 old_name = p->fullPath(old_name); 574 new_name = p->fullPath(new_name); | 569 // Adjust path for cwd and redirection 570 old_name = p->checkPathRedirect(old_name); 571 new_name = p->checkPathRedirect(new_name); |
575 576 int64_t result = rename(old_name.c_str(), new_name.c_str()); 577 return (result == -1) ? -errno : result; 578} 579 580SyscallReturn 581truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 582{ 583 string path; 584 585 int index = 0; 586 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 587 return -EFAULT; 588 589 off_t length = p->getSyscallArg(tc, index); 590 | 572 573 int64_t result = rename(old_name.c_str(), new_name.c_str()); 574 return (result == -1) ? -errno : result; 575} 576 577SyscallReturn 578truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 579{ 580 string path; 581 582 int index = 0; 583 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 584 return -EFAULT; 585 586 off_t length = p->getSyscallArg(tc, index); 587 |
591 // Adjust path for current working directory 592 path = p->fullPath(path); | 588 // Adjust path for cwd and redirection 589 path = p->checkPathRedirect(path); |
593 594 int result = truncate(path.c_str(), length); 595 return (result == -1) ? -errno : result; 596} 597 598SyscallReturn 599ftruncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 600{ --- 17 unchanged lines hidden (view full) --- 618 int index = 0; 619 string path; 620 621 if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) 622 return -EFAULT; 623 624 int64_t length = process->getSyscallArg(tc, index, 64); 625 | 590 591 int result = truncate(path.c_str(), length); 592 return (result == -1) ? -errno : result; 593} 594 595SyscallReturn 596ftruncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 597{ --- 17 unchanged lines hidden (view full) --- 615 int index = 0; 616 string path; 617 618 if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) 619 return -EFAULT; 620 621 int64_t length = process->getSyscallArg(tc, index, 64); 622 |
626 // Adjust path for current working directory 627 path = process->fullPath(path); | 623 // Adjust path for cwd and redirection 624 path = process->checkPathRedirect(path); |
628 629#if NO_STAT64 630 int result = truncate(path.c_str(), length); 631#else 632 int result = truncate64(path.c_str(), length); 633#endif 634 return (result == -1) ? -errno : result; 635} --- 39 unchanged lines hidden (view full) --- 675 return -EFAULT; 676 677 /* XXX endianess */ 678 uint32_t owner = p->getSyscallArg(tc, index); 679 uid_t hostOwner = owner; 680 uint32_t group = p->getSyscallArg(tc, index); 681 gid_t hostGroup = group; 682 | 625 626#if NO_STAT64 627 int result = truncate(path.c_str(), length); 628#else 629 int result = truncate64(path.c_str(), length); 630#endif 631 return (result == -1) ? -errno : result; 632} --- 39 unchanged lines hidden (view full) --- 672 return -EFAULT; 673 674 /* XXX endianess */ 675 uint32_t owner = p->getSyscallArg(tc, index); 676 uid_t hostOwner = owner; 677 uint32_t group = p->getSyscallArg(tc, index); 678 gid_t hostGroup = group; 679 |
683 // Adjust path for current working directory 684 path = p->fullPath(path); | 680 // Adjust path for cwd and redirection 681 path = p->checkPathRedirect(path); |
685 686 int result = chown(path.c_str(), hostOwner, hostGroup); 687 return (result == -1) ? -errno : result; 688} 689 690SyscallReturn 691fchownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 692{ --- 370 unchanged lines hidden (view full) --- 1063SyscallReturn 1064accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, 1065 int index) 1066{ 1067 string path; 1068 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1069 return -EFAULT; 1070 | 682 683 int result = chown(path.c_str(), hostOwner, hostGroup); 684 return (result == -1) ? -errno : result; 685} 686 687SyscallReturn 688fchownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 689{ --- 370 unchanged lines hidden (view full) --- 1060SyscallReturn 1061accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, 1062 int index) 1063{ 1064 string path; 1065 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1066 return -EFAULT; 1067 |
1071 // Adjust path for current working directory 1072 path = p->fullPath(path); | 1068 // Adjust path for cwd and redirection 1069 path = p->checkPathRedirect(path); |
1073 1074 mode_t mode = p->getSyscallArg(tc, index); 1075 1076 int result = access(path.c_str(), mode); 1077 return (result == -1) ? -errno : result; 1078} 1079 1080SyscallReturn --- 5 unchanged lines hidden (view full) --- 1086SyscallReturn 1087mknodFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1088{ 1089 int index = 0; 1090 std::string path; 1091 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1092 return -EFAULT; 1093 | 1070 1071 mode_t mode = p->getSyscallArg(tc, index); 1072 1073 int result = access(path.c_str(), mode); 1074 return (result == -1) ? -errno : result; 1075} 1076 1077SyscallReturn --- 5 unchanged lines hidden (view full) --- 1083SyscallReturn 1084mknodFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1085{ 1086 int index = 0; 1087 std::string path; 1088 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1089 return -EFAULT; 1090 |
1094 path = p->fullPath(path); | 1091 path = p->checkPathRedirect(path); |
1095 mode_t mode = p->getSyscallArg(tc, index); 1096 dev_t dev = p->getSyscallArg(tc, index); 1097 1098 auto result = mknod(path.c_str(), mode, dev); 1099 return (result == -1) ? -errno : result; 1100} 1101 1102SyscallReturn 1103chdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1104{ 1105 int index = 0; 1106 std::string path; 1107 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1108 return -EFAULT; 1109 | 1092 mode_t mode = p->getSyscallArg(tc, index); 1093 dev_t dev = p->getSyscallArg(tc, index); 1094 1095 auto result = mknod(path.c_str(), mode, dev); 1096 return (result == -1) ? -errno : result; 1097} 1098 1099SyscallReturn 1100chdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1101{ 1102 int index = 0; 1103 std::string path; 1104 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1105 return -EFAULT; 1106 |
1110 path = p->fullPath(path); | 1107 std::string tgt_cwd; 1108 if (startswith(path, "/")) { 1109 tgt_cwd = path; 1110 } else { 1111 char buf[PATH_MAX]; 1112 tgt_cwd = realpath((p->tgtCwd + "/" + path).c_str(), buf); 1113 } 1114 std::string host_cwd = p->checkPathRedirect(tgt_cwd); |
1111 | 1115 |
1112 auto result = chdir(path.c_str()); 1113 return (result == -1) ? -errno : result; | 1116 int result = chdir(host_cwd.c_str()); 1117 1118 if (result == -1) 1119 return -errno; 1120 1121 p->hostCwd = host_cwd; 1122 p->tgtCwd = tgt_cwd; 1123 return result; |
1114} 1115 1116SyscallReturn 1117rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1118{ 1119 int index = 0; 1120 std::string path; 1121 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1122 return -EFAULT; 1123 | 1124} 1125 1126SyscallReturn 1127rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 1128{ 1129 int index = 0; 1130 std::string path; 1131 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 1132 return -EFAULT; 1133 |
1124 path = p->fullPath(path); | 1134 path = p->checkPathRedirect(path); |
1125 1126 auto result = rmdir(path.c_str()); 1127 return (result == -1) ? -errno : result; 1128} 1129 1130#if defined(SYS_getdents) || defined(SYS_getdents64) 1131template<typename DE, int SYS_NUM> 1132static SyscallReturn --- 594 unchanged lines hidden --- | 1135 1136 auto result = rmdir(path.c_str()); 1137 return (result == -1) ? -errno : result; 1138} 1139 1140#if defined(SYS_getdents) || defined(SYS_getdents64) 1141template<typename DE, int SYS_NUM> 1142static SyscallReturn --- 594 unchanged lines hidden --- |