8f3d08cd7ddb9ba52de1ee730a05c1e3b8ae3c5f
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
39 #include "arch/utility.hh"
40 #include "base/chunk_generator.hh"
41 #include "base/trace.hh"
42 #include "config/the_isa.hh"
43 #include "cpu/base.hh"
44 #include "cpu/thread_context.hh"
45 #include "debug/SyscallVerbose.hh"
46 #include "mem/page_table.hh"
47 #include "sim/process.hh"
48 #include "sim/sim_exit.hh"
49 #include "sim/syscall_emul.hh"
50 #include "sim/system.hh"
53 using namespace TheISA
;
56 SyscallDesc::doSyscall(int callnum
, LiveProcess
*process
, ThreadContext
*tc
)
58 if (DTRACE(SyscallVerbose
)) {
60 IntReg arg
[4] M5_VAR_USED
;
62 // we can't just put the calls to getSyscallArg() in the
63 // DPRINTF arg list, because C++ doesn't guarantee their order
64 for (int i
= 0; i
< 4; ++i
)
65 arg
[i
] = process
->getSyscallArg(tc
, index
);
67 DPRINTFNR("%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
68 curTick(), tc
->getCpuPtr()->name(), name
,
69 arg
[0], arg
[1], arg
[2], arg
[3]);
72 SyscallReturn retval
= (*funcPtr
)(this, callnum
, process
, tc
);
74 if (retval
.needsRetry()) {
75 DPRINTFS(SyscallVerbose
, tc
->getCpuPtr(), "syscall %s needs retry\n",
78 DPRINTFS(SyscallVerbose
, tc
->getCpuPtr(), "syscall %s returns %d\n",
79 name
, retval
.encodedValue());
82 if (!(flags
& SyscallDesc::SuppressReturnValue
) && !retval
.needsRetry())
83 process
->setSyscallReturn(tc
, retval
);
88 unimplementedFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
91 fatal("syscall %s (#%d) unimplemented.", desc
->name
, callnum
);
98 ignoreFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
102 warn("ignoring syscall %s(%d, ...)", desc
->name
,
103 process
->getSyscallArg(tc
, index
));
110 ignoreWarnOnceFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
114 warn_once("ignoring syscall %s(%d, ...)", desc
->name
,
115 process
->getSyscallArg(tc
, index
));
122 exitFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
125 if (process
->system
->numRunningContexts() == 1) {
126 // Last running context... exit simulator
128 exitSimLoop("target called exit()",
129 process
->getSyscallArg(tc
, index
) & 0xff);
131 // other running threads... just halt this one
140 exitGroupFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
143 // halt all threads belonging to this process
144 for (auto i
: process
->contextIds
) {
145 process
->system
->getThreadContext(i
)->halt();
148 if (!process
->system
->numRunningContexts()) {
149 // all threads belonged to this process... exit simulator
151 exitSimLoop("target called exit()",
152 process
->getSyscallArg(tc
, index
) & 0xff);
160 getpagesizeFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
162 return (int)PageBytes
;
167 brkFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
169 // change brk addr to first arg
171 Addr new_brk
= p
->getSyscallArg(tc
, index
);
173 // in Linux at least, brk(0) returns the current break value
174 // (note that the syscall and the glibc function have different behavior)
178 if (new_brk
> p
->brk_point
) {
179 // might need to allocate some new pages
180 for (ChunkGenerator
gen(p
->brk_point
, new_brk
- p
->brk_point
,
181 PageBytes
); !gen
.done(); gen
.next()) {
182 if (!p
->pTable
->translate(gen
.addr()))
183 p
->allocateMem(roundDown(gen
.addr(), PageBytes
), PageBytes
);
185 // if the address is already there, zero it out
188 SETranslatingPortProxy
&tp
= tc
->getMemProxy();
190 // split non-page aligned accesses
191 Addr next_page
= roundUp(gen
.addr(), PageBytes
);
192 uint32_t size_needed
= next_page
- gen
.addr();
193 tp
.memsetBlob(gen
.addr(), zero
, size_needed
);
194 if (gen
.addr() + PageBytes
> next_page
&&
195 next_page
< new_brk
&&
196 p
->pTable
->translate(next_page
))
198 size_needed
= PageBytes
- size_needed
;
199 tp
.memsetBlob(next_page
, zero
, size_needed
);
205 p
->brk_point
= new_brk
;
206 DPRINTF(SyscallVerbose
, "Break Point changed to: %#X\n", p
->brk_point
);
212 closeFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
215 int target_fd
= p
->getSyscallArg(tc
, index
);
216 int sim_fd
= p
->sim_fd(target_fd
);
219 status
= close(sim_fd
);
221 p
->free_fd(target_fd
);
227 readFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
230 int fd
= p
->sim_fd(p
->getSyscallArg(tc
, index
));
232 Addr bufPtr
= p
->getSyscallArg(tc
, index
);
233 int nbytes
= p
->getSyscallArg(tc
, index
);
234 BufferArg
bufArg(bufPtr
, nbytes
);
236 int bytes_read
= read(fd
, bufArg
.bufferPtr(), nbytes
);
238 if (bytes_read
!= -1)
239 bufArg
.copyOut(tc
->getMemProxy());
245 writeFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
248 int fd
= p
->sim_fd(p
->getSyscallArg(tc
, index
));
249 Addr bufPtr
= p
->getSyscallArg(tc
, index
);
250 int nbytes
= p
->getSyscallArg(tc
, index
);
251 BufferArg
bufArg(bufPtr
, nbytes
);
253 bufArg
.copyIn(tc
->getMemProxy());
255 int bytes_written
= write(fd
, bufArg
.bufferPtr(), nbytes
);
259 return bytes_written
;
264 lseekFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
267 int fd
= p
->sim_fd(p
->getSyscallArg(tc
, index
));
269 uint64_t offs
= p
->getSyscallArg(tc
, index
);
270 int whence
= p
->getSyscallArg(tc
, index
);
272 off_t result
= lseek(fd
, offs
, whence
);
274 return (result
== (off_t
)-1) ? -errno
: result
;
279 _llseekFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
282 int fd
= p
->sim_fd(p
->getSyscallArg(tc
, index
));
284 uint64_t offset_high
= p
->getSyscallArg(tc
, index
);
285 uint32_t offset_low
= p
->getSyscallArg(tc
, index
);
286 Addr result_ptr
= p
->getSyscallArg(tc
, index
);
287 int whence
= p
->getSyscallArg(tc
, index
);
289 uint64_t offset
= (offset_high
<< 32) | offset_low
;
291 uint64_t result
= lseek(fd
, offset
, whence
);
292 result
= TheISA::htog(result
);
294 if (result
== (off_t
)-1) {
298 // The seek succeeded.
299 // Copy "result" to "result_ptr"
300 // XXX We'll assume that the size of loff_t is 64 bits on the
302 BufferArg
result_buf(result_ptr
, sizeof(result
));
303 memcpy(result_buf
.bufferPtr(), &result
, sizeof(result
));
304 result_buf
.copyOut(tc
->getMemProxy());
311 munmapFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
313 // given that we don't really implement mmap, munmap is really easy
318 const char *hostname
= "m5.eecs.umich.edu";
321 gethostnameFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
324 Addr bufPtr
= p
->getSyscallArg(tc
, index
);
325 int name_len
= p
->getSyscallArg(tc
, index
);
326 BufferArg
name(bufPtr
, name_len
);
328 strncpy((char *)name
.bufferPtr(), hostname
, name_len
);
330 name
.copyOut(tc
->getMemProxy());
336 getcwdFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
340 Addr bufPtr
= p
->getSyscallArg(tc
, index
);
341 unsigned long size
= p
->getSyscallArg(tc
, index
);
342 BufferArg
buf(bufPtr
, size
);
344 // Is current working directory defined?
345 string cwd
= p
->getcwd();
347 if (cwd
.length() >= size
) {
351 strncpy((char *)buf
.bufferPtr(), cwd
.c_str(), size
);
352 result
= cwd
.length();
355 if (getcwd((char *)buf
.bufferPtr(), size
) != NULL
) {
356 result
= strlen((char *)buf
.bufferPtr());
363 buf
.copyOut(tc
->getMemProxy());
365 return (result
== -1) ? -errno
: result
;
368 /// Target open() handler.
370 readlinkFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
373 return readlinkFunc(desc
, callnum
, process
, tc
, 0);
377 readlinkFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
,
382 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
385 // Adjust path for current working directory
386 path
= p
->fullPath(path
);
388 Addr bufPtr
= p
->getSyscallArg(tc
, index
);
389 size_t bufsiz
= p
->getSyscallArg(tc
, index
);
391 BufferArg
buf(bufPtr
, bufsiz
);
393 int result
= readlink(path
.c_str(), (char *)buf
.bufferPtr(), bufsiz
);
395 buf
.copyOut(tc
->getMemProxy());
397 return (result
== -1) ? -errno
: result
;
401 unlinkFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
403 return unlinkHelper(desc
, num
, p
, tc
, 0);
407 unlinkHelper(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
,
412 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
415 // Adjust path for current working directory
416 path
= p
->fullPath(path
);
418 int result
= unlink(path
.c_str());
419 return (result
== -1) ? -errno
: result
;
424 mkdirFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
429 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
432 // Adjust path for current working directory
433 path
= p
->fullPath(path
);
435 mode_t mode
= p
->getSyscallArg(tc
, index
);
437 int result
= mkdir(path
.c_str(), mode
);
438 return (result
== -1) ? -errno
: result
;
442 renameFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
447 if (!tc
->getMemProxy().tryReadString(old_name
, p
->getSyscallArg(tc
, index
)))
452 if (!tc
->getMemProxy().tryReadString(new_name
, p
->getSyscallArg(tc
, index
)))
455 // Adjust path for current working directory
456 old_name
= p
->fullPath(old_name
);
457 new_name
= p
->fullPath(new_name
);
459 int64_t result
= rename(old_name
.c_str(), new_name
.c_str());
460 return (result
== -1) ? -errno
: result
;
464 truncateFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
469 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
472 off_t length
= p
->getSyscallArg(tc
, index
);
474 // Adjust path for current working directory
475 path
= p
->fullPath(path
);
477 int result
= truncate(path
.c_str(), length
);
478 return (result
== -1) ? -errno
: result
;
482 ftruncateFunc(SyscallDesc
*desc
, int num
,
483 LiveProcess
*process
, ThreadContext
*tc
)
486 int fd
= process
->sim_fd(process
->getSyscallArg(tc
, index
));
491 off_t length
= process
->getSyscallArg(tc
, index
);
493 int result
= ftruncate(fd
, length
);
494 return (result
== -1) ? -errno
: result
;
498 truncate64Func(SyscallDesc
*desc
, int num
,
499 LiveProcess
*process
, ThreadContext
*tc
)
504 if (!tc
->getMemProxy().tryReadString(path
, process
->getSyscallArg(tc
, index
)))
507 int64_t length
= process
->getSyscallArg(tc
, index
, 64);
509 // Adjust path for current working directory
510 path
= process
->fullPath(path
);
513 int result
= truncate(path
.c_str(), length
);
515 int result
= truncate64(path
.c_str(), length
);
517 return (result
== -1) ? -errno
: result
;
521 ftruncate64Func(SyscallDesc
*desc
, int num
,
522 LiveProcess
*process
, ThreadContext
*tc
)
525 int fd
= process
->sim_fd(process
->getSyscallArg(tc
, index
));
530 int64_t length
= process
->getSyscallArg(tc
, index
, 64);
533 int result
= ftruncate(fd
, length
);
535 int result
= ftruncate64(fd
, length
);
537 return (result
== -1) ? -errno
: result
;
541 umaskFunc(SyscallDesc
*desc
, int num
, LiveProcess
*process
, ThreadContext
*tc
)
543 // Letting the simulated program change the simulator's umask seems like
544 // a bad idea. Compromise by just returning the current umask but not
545 // changing anything.
546 mode_t oldMask
= umask(0);
552 chownFunc(SyscallDesc
*desc
, int num
, LiveProcess
*p
, ThreadContext
*tc
)
557 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
561 uint32_t owner
= p
->getSyscallArg(tc
, index
);
562 uid_t hostOwner
= owner
;
563 uint32_t group
= p
->getSyscallArg(tc
, index
);
564 gid_t hostGroup
= group
;
566 // Adjust path for current working directory
567 path
= p
->fullPath(path
);
569 int result
= chown(path
.c_str(), hostOwner
, hostGroup
);
570 return (result
== -1) ? -errno
: result
;
574 fchownFunc(SyscallDesc
*desc
, int num
, LiveProcess
*process
, ThreadContext
*tc
)
577 int fd
= process
->sim_fd(process
->getSyscallArg(tc
, index
));
583 uint32_t owner
= process
->getSyscallArg(tc
, index
);
584 uid_t hostOwner
= owner
;
585 uint32_t group
= process
->getSyscallArg(tc
, index
);
586 gid_t hostGroup
= group
;
588 int result
= fchown(fd
, hostOwner
, hostGroup
);
589 return (result
== -1) ? -errno
: result
;
594 dupFunc(SyscallDesc
*desc
, int num
, LiveProcess
*process
, ThreadContext
*tc
)
597 int tgt_fd
= process
->getSyscallArg(tc
, index
);
598 int sim_fd
= process
->sim_fd(tgt_fd
);
602 Process::FdMap
*fdo
= process
->sim_fd_obj(tgt_fd
);
604 int result
= dup(sim_fd
);
605 return (result
== -1) ? -errno
:
606 process
->alloc_fd(result
, fdo
->filename
, fdo
->flags
, fdo
->mode
, false);
611 fcntlFunc(SyscallDesc
*desc
, int num
, LiveProcess
*process
,
615 int fd
= process
->getSyscallArg(tc
, index
);
617 if (fd
< 0 || process
->sim_fd(fd
) < 0)
620 int cmd
= process
->getSyscallArg(tc
, index
);
623 // if we really wanted to support this, we'd need to do it
624 // in the target fd space.
625 warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd
);
628 case 1: // F_GETFD (get close-on-exec flag)
629 case 2: // F_SETFD (set close-on-exec flag)
632 case 3: // F_GETFL (get file flags)
633 case 4: // F_SETFL (set file flags)
634 // not sure if this is totally valid, but we'll pass it through
635 // to the underlying OS
636 warn("fcntl(%d, %d) passed through to host\n", fd
, cmd
);
637 return fcntl(process
->sim_fd(fd
), cmd
);
640 case 7: // F_GETLK (get lock)
641 case 8: // F_SETLK (set lock)
642 case 9: // F_SETLKW (set lock and wait)
643 // don't mess with file locking... just act like it's OK
644 warn("File lock call (fcntl(%d, %d)) ignored.\n", fd
, cmd
);
648 warn("Unknown fcntl command %d\n", cmd
);
654 fcntl64Func(SyscallDesc
*desc
, int num
, LiveProcess
*process
,
658 int fd
= process
->getSyscallArg(tc
, index
);
660 if (fd
< 0 || process
->sim_fd(fd
) < 0)
663 int cmd
= process
->getSyscallArg(tc
, index
);
666 warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd
);
669 case 34: // F_SETLK64
670 case 35: // F_SETLKW64
671 warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd
);
675 // not sure if this is totally valid, but we'll pass it through
676 // to the underlying OS
677 warn("fcntl64(%d, %d) passed through to host\n", fd
, cmd
);
678 return fcntl(process
->sim_fd(fd
), cmd
);
684 pipePseudoFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
687 int fds
[2], sim_fds
[2];
688 int pipe_retval
= pipe(fds
);
690 if (pipe_retval
< 0) {
695 sim_fds
[0] = process
->alloc_fd(fds
[0], "PIPE-READ", O_WRONLY
, -1, true);
696 sim_fds
[1] = process
->alloc_fd(fds
[1], "PIPE-WRITE", O_RDONLY
, -1, true);
698 process
->setReadPipeSource(sim_fds
[0], sim_fds
[1]);
699 // Alpha Linux convention for pipe() is that fd[0] is returned as
700 // the return value of the function, and fd[1] is returned in r20.
701 tc
->setIntReg(SyscallPseudoReturnReg
, sim_fds
[1]);
707 getpidPseudoFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
710 // Make up a PID. There's no interprocess communication in
711 // fake_syscall mode, so there's no way for a process to know it's
712 // not getting a unique value.
714 tc
->setIntReg(SyscallPseudoReturnReg
, process
->ppid());
715 return process
->pid();
720 getuidPseudoFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
723 // Make up a UID and EUID... it shouldn't matter, and we want the
724 // simulation to be deterministic.
727 tc
->setIntReg(SyscallPseudoReturnReg
, process
->euid()); //EUID
728 return process
->uid(); // UID
733 getgidPseudoFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
736 // Get current group ID. EGID goes in r20.
737 tc
->setIntReg(SyscallPseudoReturnReg
, process
->egid()); //EGID
738 return process
->gid();
743 setuidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
746 // can't fathom why a benchmark would call this.
748 warn("Ignoring call to setuid(%d)\n", process
->getSyscallArg(tc
, index
));
753 getpidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
756 // Make up a PID. There's no interprocess communication in
757 // fake_syscall mode, so there's no way for a process to know it's
758 // not getting a unique value.
760 tc
->setIntReg(SyscallPseudoReturnReg
, process
->ppid()); //PID
761 return process
->pid();
765 getppidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
768 return process
->ppid();
772 getuidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
775 return process
->uid(); // UID
779 geteuidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
782 return process
->euid(); // UID
786 getgidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
789 return process
->gid();
793 getegidFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
796 return process
->egid();
801 cloneFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*process
,
805 IntReg flags
= process
->getSyscallArg(tc
, index
);
806 IntReg newStack
= process
->getSyscallArg(tc
, index
);
808 DPRINTF(SyscallVerbose
, "In sys_clone:\n");
809 DPRINTF(SyscallVerbose
, " Flags=%llx\n", flags
);
810 DPRINTF(SyscallVerbose
, " Child stack=%llx\n", newStack
);
813 if (flags
!= 0x10f00) {
814 warn("This sys_clone implementation assumes flags "
815 "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD "
816 "(0x10f00), and may not work correctly with given flags "
820 ThreadContext
* ctc
; // child thread context
821 if ( ( ctc
= process
->findFreeContext() ) != NULL
) {
822 DPRINTF(SyscallVerbose
, " Found unallocated thread context\n");
824 ctc
->clearArchRegs();
826 // Arch-specific cloning code
827 #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA
828 // Cloning the misc. regs for these archs is enough
829 TheISA::copyMiscRegs(tc
, ctc
);
830 #elif THE_ISA == SPARC_ISA
831 TheISA::copyRegs(tc
, ctc
);
833 // TODO: Explain what this code actually does :-)
834 ctc
->setIntReg(NumIntArchRegs
+ 6, 0);
835 ctc
->setIntReg(NumIntArchRegs
+ 4, 0);
836 ctc
->setIntReg(NumIntArchRegs
+ 3, NWindows
- 2);
837 ctc
->setIntReg(NumIntArchRegs
+ 5, NWindows
);
838 ctc
->setMiscReg(MISCREG_CWP
, 0);
839 ctc
->setIntReg(NumIntArchRegs
+ 7, 0);
840 ctc
->setMiscRegNoEffect(MISCREG_TL
, 0);
841 ctc
->setMiscReg(MISCREG_ASI
, ASI_PRIMARY
);
843 for (int y
= 8; y
< 32; y
++)
844 ctc
->setIntReg(y
, tc
->readIntReg(y
));
845 #elif THE_ISA == ARM_ISA
846 TheISA::copyRegs(tc
, ctc
);
848 fatal("sys_clone is not implemented for this ISA\n");
851 // Set up stack register
852 ctc
->setIntReg(TheISA::StackPointerReg
, newStack
);
854 // Set up syscall return values in parent and child
855 ctc
->setIntReg(ReturnValueReg
, 0); // return value, child
857 // Alpha needs SyscallSuccessReg=0 in child
858 #if THE_ISA == ALPHA_ISA
859 ctc
->setIntReg(TheISA::SyscallSuccessReg
, 0);
862 // In SPARC/Linux, clone returns 0 on pseudo-return register if
863 // parent, non-zero if child
864 #if THE_ISA == SPARC_ISA
865 tc
->setIntReg(TheISA::SyscallPseudoReturnReg
, 0);
866 ctc
->setIntReg(TheISA::SyscallPseudoReturnReg
, 1);
869 ctc
->pcState(tc
->nextInstAddr());
873 // Should return nonzero child TID in parent's syscall return register,
874 // but for our pthread library any non-zero value will work
877 fatal("Called sys_clone, but no unallocated thread contexts found!\n");
883 accessFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*p
, ThreadContext
*tc
,
887 if (!tc
->getMemProxy().tryReadString(path
, p
->getSyscallArg(tc
, index
)))
890 // Adjust path for current working directory
891 path
= p
->fullPath(path
);
893 mode_t mode
= p
->getSyscallArg(tc
, index
);
895 int result
= access(path
.c_str(), mode
);
896 return (result
== -1) ? -errno
: result
;
900 accessFunc(SyscallDesc
*desc
, int callnum
, LiveProcess
*p
, ThreadContext
*tc
)
902 return accessFunc(desc
, callnum
, p
, tc
, 0);