syscall_emul.cc revision 6744
1360SN/A/* 21458SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 3360SN/A * All rights reserved. 4360SN/A * 5360SN/A * Redistribution and use in source and binary forms, with or without 6360SN/A * modification, are permitted provided that the following conditions are 7360SN/A * met: redistributions of source code must retain the above copyright 8360SN/A * notice, this list of conditions and the following disclaimer; 9360SN/A * redistributions in binary form must reproduce the above copyright 10360SN/A * notice, this list of conditions and the following disclaimer in the 11360SN/A * documentation and/or other materials provided with the distribution; 12360SN/A * neither the name of the copyright holders nor the names of its 13360SN/A * contributors may be used to endorse or promote products derived from 14360SN/A * this software without specific prior written permission. 15360SN/A * 16360SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17360SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18360SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19360SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20360SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21360SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22360SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23360SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24360SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25360SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26360SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Ali Saidi 30360SN/A */ 31360SN/A 322093SN/A#include <fcntl.h> 33360SN/A#include <unistd.h> 34360SN/A 356712Snate@binkert.org#include <cstdio> 366712Snate@binkert.org#include <iostream> 37360SN/A#include <string> 38360SN/A 39360SN/A#include "sim/syscall_emul.hh" 402474SN/A#include "base/chunk_generator.hh" 41360SN/A#include "base/trace.hh" 426658Snate@binkert.org#include "config/the_isa.hh" 432680Sktlim@umich.edu#include "cpu/thread_context.hh" 441717SN/A#include "cpu/base.hh" 452474SN/A#include "mem/page_table.hh" 46360SN/A#include "sim/process.hh" 476029Ssteve.reinhardt@amd.com#include "sim/system.hh" 482667Sstever@eecs.umich.edu#include "sim/sim_exit.hh" 49360SN/A 50360SN/Ausing namespace std; 512107SN/Ausing namespace TheISA; 52360SN/A 53360SN/Avoid 543114Sgblack@eecs.umich.eduSyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) 55360SN/A{ 566702Sgblack@eecs.umich.edu#if TRACING_ON 576701Sgblack@eecs.umich.edu int index = 0; 586702Sgblack@eecs.umich.edu#endif 596111Ssteve.reinhardt@amd.com DPRINTFR(SyscallVerbose, 606111Ssteve.reinhardt@amd.com "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", 616111Ssteve.reinhardt@amd.com curTick, tc->getCpuPtr()->name(), name, 626701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 636701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 646701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 656701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index)); 66360SN/A 672680Sktlim@umich.edu SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); 68360SN/A 692495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", 702680Sktlim@umich.edu curTick,tc->getCpuPtr()->name(), name, retval.value()); 71360SN/A 721450SN/A if (!(flags & SyscallDesc::SuppressReturnValue)) 735958Sgblack@eecs.umich.edu process->setSyscallReturn(tc, retval); 74360SN/A} 75360SN/A 76360SN/A 771450SN/ASyscallReturn 783114Sgblack@eecs.umich.eduunimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 792680Sktlim@umich.edu ThreadContext *tc) 80360SN/A{ 811969SN/A fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); 822484SN/A 832484SN/A return 1; 84360SN/A} 85360SN/A 86360SN/A 871450SN/ASyscallReturn 883114Sgblack@eecs.umich.eduignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 892680Sktlim@umich.edu ThreadContext *tc) 90360SN/A{ 916701Sgblack@eecs.umich.edu int index = 0; 921969SN/A warn("ignoring syscall %s(%d, %d, ...)", desc->name, 936701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); 94360SN/A 951458SN/A return 0; 96360SN/A} 97360SN/A 98360SN/A 991450SN/ASyscallReturn 1003114Sgblack@eecs.umich.eduexitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1012680Sktlim@umich.edu ThreadContext *tc) 102360SN/A{ 1036029Ssteve.reinhardt@amd.com if (process->system->numRunningContexts() == 1) { 1046029Ssteve.reinhardt@amd.com // Last running context... exit simulator 1056701Sgblack@eecs.umich.edu int index = 0; 1065958Sgblack@eecs.umich.edu exitSimLoop("target called exit()", 1076701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1086029Ssteve.reinhardt@amd.com } else { 1096029Ssteve.reinhardt@amd.com // other running threads... just halt this one 1106029Ssteve.reinhardt@amd.com tc->halt(); 1112834Sksewell@umich.edu } 112360SN/A 1131458SN/A return 1; 114360SN/A} 115360SN/A 116360SN/A 1171450SN/ASyscallReturn 1186109Ssanchezd@stanford.eduexitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1196109Ssanchezd@stanford.edu ThreadContext *tc) 1206109Ssanchezd@stanford.edu{ 1216109Ssanchezd@stanford.edu // really should just halt all thread contexts belonging to this 1226109Ssanchezd@stanford.edu // process in case there's another process running... 1236701Sgblack@eecs.umich.edu int index = 0; 1246109Ssanchezd@stanford.edu exitSimLoop("target called exit()", 1256701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1266109Ssanchezd@stanford.edu 1276109Ssanchezd@stanford.edu return 1; 1286109Ssanchezd@stanford.edu} 1296109Ssanchezd@stanford.edu 1306109Ssanchezd@stanford.edu 1316109Ssanchezd@stanford.eduSyscallReturn 1323114Sgblack@eecs.umich.edugetpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 133360SN/A{ 1342107SN/A return (int)VMPageSize; 135360SN/A} 136360SN/A 137360SN/A 1381450SN/ASyscallReturn 1395748SSteve.Reinhardt@amd.combrkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 140360SN/A{ 141360SN/A // change brk addr to first arg 1426701Sgblack@eecs.umich.edu int index = 0; 1436701Sgblack@eecs.umich.edu Addr new_brk = p->getSyscallArg(tc, index); 1445748SSteve.Reinhardt@amd.com 1455748SSteve.Reinhardt@amd.com // in Linux at least, brk(0) returns the current break value 1465748SSteve.Reinhardt@amd.com // (note that the syscall and the glibc function have different behavior) 1475748SSteve.Reinhardt@amd.com if (new_brk == 0) 1485748SSteve.Reinhardt@amd.com return p->brk_point; 1495748SSteve.Reinhardt@amd.com 1505748SSteve.Reinhardt@amd.com if (new_brk > p->brk_point) { 1515748SSteve.Reinhardt@amd.com // might need to allocate some new pages 1522474SN/A for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, 1532474SN/A VMPageSize); !gen.done(); gen.next()) { 1545748SSteve.Reinhardt@amd.com if (!p->pTable->translate(gen.addr())) 1552474SN/A p->pTable->allocate(roundDown(gen.addr(), VMPageSize), 1562474SN/A VMPageSize); 1576687Stjones1@inf.ed.ac.uk 1586687Stjones1@inf.ed.ac.uk // if the address is already there, zero it out 1596687Stjones1@inf.ed.ac.uk else { 1606687Stjones1@inf.ed.ac.uk uint8_t zero = 0; 1616687Stjones1@inf.ed.ac.uk TranslatingPort *tp = tc->getMemPort(); 1626687Stjones1@inf.ed.ac.uk 1636687Stjones1@inf.ed.ac.uk // split non-page aligned accesses 1646687Stjones1@inf.ed.ac.uk Addr next_page = roundUp(gen.addr(), VMPageSize); 1656687Stjones1@inf.ed.ac.uk uint32_t size_needed = next_page - gen.addr(); 1666687Stjones1@inf.ed.ac.uk tp->memsetBlob(gen.addr(), zero, size_needed); 1676687Stjones1@inf.ed.ac.uk if (gen.addr() + VMPageSize > next_page && 1686687Stjones1@inf.ed.ac.uk next_page < new_brk && 1696687Stjones1@inf.ed.ac.uk p->pTable->translate(next_page)) 1706687Stjones1@inf.ed.ac.uk { 1716687Stjones1@inf.ed.ac.uk size_needed = VMPageSize - size_needed; 1726687Stjones1@inf.ed.ac.uk tp->memsetBlob(next_page, zero, size_needed); 1736687Stjones1@inf.ed.ac.uk } 1746687Stjones1@inf.ed.ac.uk } 1752474SN/A } 1761450SN/A } 1775748SSteve.Reinhardt@amd.com 1785748SSteve.Reinhardt@amd.com p->brk_point = new_brk; 1791458SN/A DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); 1801458SN/A return p->brk_point; 181360SN/A} 182360SN/A 183360SN/A 1841450SN/ASyscallReturn 1853114Sgblack@eecs.umich.educloseFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 186360SN/A{ 1876701Sgblack@eecs.umich.edu int index = 0; 1886701Sgblack@eecs.umich.edu int target_fd = p->getSyscallArg(tc, index); 1891970SN/A int status = close(p->sim_fd(target_fd)); 1901970SN/A if (status >= 0) 1911970SN/A p->free_fd(target_fd); 1921970SN/A return status; 193360SN/A} 194360SN/A 195360SN/A 1961450SN/ASyscallReturn 1973114Sgblack@eecs.umich.edureadFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 198360SN/A{ 1996701Sgblack@eecs.umich.edu int index = 0; 2006701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2016701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2026701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2036701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 204360SN/A 205360SN/A int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); 206360SN/A 207360SN/A if (bytes_read != -1) 2082680Sktlim@umich.edu bufArg.copyOut(tc->getMemPort()); 209360SN/A 2101458SN/A return bytes_read; 211360SN/A} 212360SN/A 2131450SN/ASyscallReturn 2143114Sgblack@eecs.umich.eduwriteFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 215360SN/A{ 2166701Sgblack@eecs.umich.edu int index = 0; 2176701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2186701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2196701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2206701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 221360SN/A 2222680Sktlim@umich.edu bufArg.copyIn(tc->getMemPort()); 223360SN/A 224360SN/A int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); 225360SN/A 226360SN/A fsync(fd); 227360SN/A 2281458SN/A return bytes_written; 229360SN/A} 230360SN/A 231360SN/A 2321450SN/ASyscallReturn 2333114Sgblack@eecs.umich.edulseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 234360SN/A{ 2356701Sgblack@eecs.umich.edu int index = 0; 2366701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2376701Sgblack@eecs.umich.edu uint64_t offs = p->getSyscallArg(tc, index); 2386701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 239360SN/A 240360SN/A off_t result = lseek(fd, offs, whence); 241360SN/A 2421458SN/A return (result == (off_t)-1) ? -errno : result; 243360SN/A} 244360SN/A 245360SN/A 2461450SN/ASyscallReturn 2474118Sgblack@eecs.umich.edu_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 2484118Sgblack@eecs.umich.edu{ 2496701Sgblack@eecs.umich.edu int index = 0; 2506701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2516701Sgblack@eecs.umich.edu uint64_t offset_high = p->getSyscallArg(tc, index); 2526701Sgblack@eecs.umich.edu uint32_t offset_low = p->getSyscallArg(tc, index); 2536701Sgblack@eecs.umich.edu Addr result_ptr = p->getSyscallArg(tc, index); 2546701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 2554118Sgblack@eecs.umich.edu 2564118Sgblack@eecs.umich.edu uint64_t offset = (offset_high << 32) | offset_low; 2574118Sgblack@eecs.umich.edu 2584118Sgblack@eecs.umich.edu uint64_t result = lseek(fd, offset, whence); 2594118Sgblack@eecs.umich.edu result = TheISA::htog(result); 2604118Sgblack@eecs.umich.edu 2614118Sgblack@eecs.umich.edu if (result == (off_t)-1) { 2624118Sgblack@eecs.umich.edu //The seek failed. 2634118Sgblack@eecs.umich.edu return -errno; 2644118Sgblack@eecs.umich.edu } else { 2656111Ssteve.reinhardt@amd.com // The seek succeeded. 2666111Ssteve.reinhardt@amd.com // Copy "result" to "result_ptr" 2676111Ssteve.reinhardt@amd.com // XXX We'll assume that the size of loff_t is 64 bits on the 2686111Ssteve.reinhardt@amd.com // target platform 2694118Sgblack@eecs.umich.edu BufferArg result_buf(result_ptr, sizeof(result)); 2704118Sgblack@eecs.umich.edu memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 2714118Sgblack@eecs.umich.edu result_buf.copyOut(tc->getMemPort()); 2724118Sgblack@eecs.umich.edu return 0; 2734118Sgblack@eecs.umich.edu } 2744118Sgblack@eecs.umich.edu 2754118Sgblack@eecs.umich.edu 2764118Sgblack@eecs.umich.edu return (result == (off_t)-1) ? -errno : result; 2774118Sgblack@eecs.umich.edu} 2784118Sgblack@eecs.umich.edu 2794118Sgblack@eecs.umich.edu 2804118Sgblack@eecs.umich.eduSyscallReturn 2813114Sgblack@eecs.umich.edumunmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 282360SN/A{ 283360SN/A // given that we don't really implement mmap, munmap is really easy 2841458SN/A return 0; 285360SN/A} 286360SN/A 287360SN/A 288360SN/Aconst char *hostname = "m5.eecs.umich.edu"; 289360SN/A 2901450SN/ASyscallReturn 2913114Sgblack@eecs.umich.edugethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 292360SN/A{ 2936701Sgblack@eecs.umich.edu int index = 0; 2946701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2956701Sgblack@eecs.umich.edu int name_len = p->getSyscallArg(tc, index); 2966701Sgblack@eecs.umich.edu BufferArg name(bufPtr, name_len); 297360SN/A 298360SN/A strncpy((char *)name.bufferPtr(), hostname, name_len); 299360SN/A 3002680Sktlim@umich.edu name.copyOut(tc->getMemPort()); 301360SN/A 3021458SN/A return 0; 303360SN/A} 304360SN/A 3051450SN/ASyscallReturn 3065513SMichael.Adler@intel.comgetcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3075513SMichael.Adler@intel.com{ 3085513SMichael.Adler@intel.com int result = 0; 3096731Svince@csl.cornell.edu int index = 0; 3106701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3116701Sgblack@eecs.umich.edu unsigned long size = p->getSyscallArg(tc, index); 3126701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, size); 3135513SMichael.Adler@intel.com 3145513SMichael.Adler@intel.com // Is current working directory defined? 3155513SMichael.Adler@intel.com string cwd = p->getcwd(); 3165513SMichael.Adler@intel.com if (!cwd.empty()) { 3175513SMichael.Adler@intel.com if (cwd.length() >= size) { 3185513SMichael.Adler@intel.com // Buffer too small 3195513SMichael.Adler@intel.com return -ERANGE; 3205513SMichael.Adler@intel.com } 3215513SMichael.Adler@intel.com strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 3225513SMichael.Adler@intel.com result = cwd.length(); 3235513SMichael.Adler@intel.com } 3245513SMichael.Adler@intel.com else { 3255513SMichael.Adler@intel.com if (getcwd((char *)buf.bufferPtr(), size) != NULL) { 3265513SMichael.Adler@intel.com result = strlen((char *)buf.bufferPtr()); 3275513SMichael.Adler@intel.com } 3285513SMichael.Adler@intel.com else { 3295513SMichael.Adler@intel.com result = -1; 3305513SMichael.Adler@intel.com } 3315513SMichael.Adler@intel.com } 3325513SMichael.Adler@intel.com 3335513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3345513SMichael.Adler@intel.com 3355513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3365513SMichael.Adler@intel.com} 3375513SMichael.Adler@intel.com 3385513SMichael.Adler@intel.com 3395513SMichael.Adler@intel.comSyscallReturn 3405513SMichael.Adler@intel.comreadlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3415513SMichael.Adler@intel.com{ 3425513SMichael.Adler@intel.com string path; 3435513SMichael.Adler@intel.com 3446701Sgblack@eecs.umich.edu int index = 0; 3456701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3465513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3475513SMichael.Adler@intel.com 3485513SMichael.Adler@intel.com // Adjust path for current working directory 3495513SMichael.Adler@intel.com path = p->fullPath(path); 3505513SMichael.Adler@intel.com 3516701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3526701Sgblack@eecs.umich.edu size_t bufsiz = p->getSyscallArg(tc, index); 3536701Sgblack@eecs.umich.edu 3546701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, bufsiz); 3555513SMichael.Adler@intel.com 3565513SMichael.Adler@intel.com int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 3575513SMichael.Adler@intel.com 3585513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3595513SMichael.Adler@intel.com 3605513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3615513SMichael.Adler@intel.com} 3625513SMichael.Adler@intel.com 3635513SMichael.Adler@intel.comSyscallReturn 3643114Sgblack@eecs.umich.eduunlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 365511SN/A{ 3661706SN/A string path; 367360SN/A 3686701Sgblack@eecs.umich.edu int index = 0; 3696701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3701450SN/A return (TheISA::IntReg)-EFAULT; 371511SN/A 3723669Sbinkertn@umich.edu // Adjust path for current working directory 3733669Sbinkertn@umich.edu path = p->fullPath(path); 3743669Sbinkertn@umich.edu 375511SN/A int result = unlink(path.c_str()); 3761458SN/A return (result == -1) ? -errno : result; 377511SN/A} 378511SN/A 3795513SMichael.Adler@intel.com 3805513SMichael.Adler@intel.comSyscallReturn 3815513SMichael.Adler@intel.commkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3825513SMichael.Adler@intel.com{ 3835513SMichael.Adler@intel.com string path; 3845513SMichael.Adler@intel.com 3856701Sgblack@eecs.umich.edu int index = 0; 3866701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3875513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3885513SMichael.Adler@intel.com 3895513SMichael.Adler@intel.com // Adjust path for current working directory 3905513SMichael.Adler@intel.com path = p->fullPath(path); 3915513SMichael.Adler@intel.com 3926701Sgblack@eecs.umich.edu mode_t mode = p->getSyscallArg(tc, index); 3935513SMichael.Adler@intel.com 3945513SMichael.Adler@intel.com int result = mkdir(path.c_str(), mode); 3955513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3965513SMichael.Adler@intel.com} 3975513SMichael.Adler@intel.com 3981450SN/ASyscallReturn 3993114Sgblack@eecs.umich.edurenameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 400511SN/A{ 4011706SN/A string old_name; 402511SN/A 4036701Sgblack@eecs.umich.edu int index = 0; 4046701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index))) 4051458SN/A return -EFAULT; 406511SN/A 4071706SN/A string new_name; 408511SN/A 4096701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index))) 4101458SN/A return -EFAULT; 411511SN/A 4123669Sbinkertn@umich.edu // Adjust path for current working directory 4133669Sbinkertn@umich.edu old_name = p->fullPath(old_name); 4143669Sbinkertn@umich.edu new_name = p->fullPath(new_name); 4153669Sbinkertn@umich.edu 4161706SN/A int64_t result = rename(old_name.c_str(), new_name.c_str()); 4171458SN/A return (result == -1) ? -errno : result; 418511SN/A} 419511SN/A 4201706SN/ASyscallReturn 4213114Sgblack@eecs.umich.edutruncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4221706SN/A{ 4231706SN/A string path; 4241706SN/A 4256701Sgblack@eecs.umich.edu int index = 0; 4266701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4271706SN/A return -EFAULT; 4281706SN/A 4296701Sgblack@eecs.umich.edu off_t length = p->getSyscallArg(tc, index); 4301706SN/A 4313669Sbinkertn@umich.edu // Adjust path for current working directory 4323669Sbinkertn@umich.edu path = p->fullPath(path); 4333669Sbinkertn@umich.edu 4341706SN/A int result = truncate(path.c_str(), length); 4351706SN/A return (result == -1) ? -errno : result; 4361706SN/A} 4371706SN/A 4381706SN/ASyscallReturn 4396111Ssteve.reinhardt@amd.comftruncateFunc(SyscallDesc *desc, int num, 4406111Ssteve.reinhardt@amd.com LiveProcess *process, ThreadContext *tc) 4411706SN/A{ 4426701Sgblack@eecs.umich.edu int index = 0; 4436701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4441706SN/A 4451706SN/A if (fd < 0) 4461706SN/A return -EBADF; 4471706SN/A 4486701Sgblack@eecs.umich.edu off_t length = process->getSyscallArg(tc, index); 4491706SN/A 4501706SN/A int result = ftruncate(fd, length); 4511706SN/A return (result == -1) ? -errno : result; 4521706SN/A} 4531999SN/A 4541999SN/ASyscallReturn 4556703Svince@csl.cornell.edutruncate64Func(SyscallDesc *desc, int num, 4566703Svince@csl.cornell.edu LiveProcess *process, ThreadContext *tc) 4576703Svince@csl.cornell.edu{ 4586703Svince@csl.cornell.edu int index = 0; 4596703Svince@csl.cornell.edu string path; 4606703Svince@csl.cornell.edu 4616703Svince@csl.cornell.edu if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, index))) 4626703Svince@csl.cornell.edu return -EFAULT; 4636703Svince@csl.cornell.edu 4646744SAli.Saidi@arm.com int64_t length = process->getSyscallArg(tc, index, 64); 4656703Svince@csl.cornell.edu 4666703Svince@csl.cornell.edu // Adjust path for current working directory 4676703Svince@csl.cornell.edu path = process->fullPath(path); 4686703Svince@csl.cornell.edu 4696744SAli.Saidi@arm.com#if NO_STAT64 4706744SAli.Saidi@arm.com int result = truncate(path.c_str(), length); 4716744SAli.Saidi@arm.com#else 4726703Svince@csl.cornell.edu int result = truncate64(path.c_str(), length); 4736744SAli.Saidi@arm.com#endif 4746703Svince@csl.cornell.edu return (result == -1) ? -errno : result; 4756703Svince@csl.cornell.edu} 4766703Svince@csl.cornell.edu 4776703Svince@csl.cornell.eduSyscallReturn 4786685Stjones1@inf.ed.ac.ukftruncate64Func(SyscallDesc *desc, int num, 4796685Stjones1@inf.ed.ac.uk LiveProcess *process, ThreadContext *tc) 4806685Stjones1@inf.ed.ac.uk{ 4816701Sgblack@eecs.umich.edu int index = 0; 4826701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4836685Stjones1@inf.ed.ac.uk 4846685Stjones1@inf.ed.ac.uk if (fd < 0) 4856685Stjones1@inf.ed.ac.uk return -EBADF; 4866685Stjones1@inf.ed.ac.uk 4876744SAli.Saidi@arm.com int64_t length = process->getSyscallArg(tc, index, 64); 4886685Stjones1@inf.ed.ac.uk 4896744SAli.Saidi@arm.com#if NO_STAT64 4906744SAli.Saidi@arm.com int result = ftruncate(fd, length); 4916744SAli.Saidi@arm.com#else 4926685Stjones1@inf.ed.ac.uk int result = ftruncate64(fd, length); 4936744SAli.Saidi@arm.com#endif 4946685Stjones1@inf.ed.ac.uk return (result == -1) ? -errno : result; 4956685Stjones1@inf.ed.ac.uk} 4966685Stjones1@inf.ed.ac.uk 4976685Stjones1@inf.ed.ac.ukSyscallReturn 4985513SMichael.Adler@intel.comumaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 4995513SMichael.Adler@intel.com{ 5005513SMichael.Adler@intel.com // Letting the simulated program change the simulator's umask seems like 5015513SMichael.Adler@intel.com // a bad idea. Compromise by just returning the current umask but not 5025513SMichael.Adler@intel.com // changing anything. 5035513SMichael.Adler@intel.com mode_t oldMask = umask(0); 5045513SMichael.Adler@intel.com umask(oldMask); 5055521Snate@binkert.org return (int)oldMask; 5065513SMichael.Adler@intel.com} 5075513SMichael.Adler@intel.com 5085513SMichael.Adler@intel.comSyscallReturn 5093114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 5101999SN/A{ 5111999SN/A string path; 5121999SN/A 5136701Sgblack@eecs.umich.edu int index = 0; 5146701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 5151999SN/A return -EFAULT; 5161999SN/A 5171999SN/A /* XXX endianess */ 5186701Sgblack@eecs.umich.edu uint32_t owner = p->getSyscallArg(tc, index); 5191999SN/A uid_t hostOwner = owner; 5206701Sgblack@eecs.umich.edu uint32_t group = p->getSyscallArg(tc, index); 5211999SN/A gid_t hostGroup = group; 5221999SN/A 5233669Sbinkertn@umich.edu // Adjust path for current working directory 5243669Sbinkertn@umich.edu path = p->fullPath(path); 5253669Sbinkertn@umich.edu 5261999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 5271999SN/A return (result == -1) ? -errno : result; 5281999SN/A} 5291999SN/A 5301999SN/ASyscallReturn 5313114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5321999SN/A{ 5336701Sgblack@eecs.umich.edu int index = 0; 5346701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5351999SN/A 5361999SN/A if (fd < 0) 5371999SN/A return -EBADF; 5381999SN/A 5391999SN/A /* XXX endianess */ 5406701Sgblack@eecs.umich.edu uint32_t owner = process->getSyscallArg(tc, index); 5411999SN/A uid_t hostOwner = owner; 5426701Sgblack@eecs.umich.edu uint32_t group = process->getSyscallArg(tc, index); 5431999SN/A gid_t hostGroup = group; 5441999SN/A 5451999SN/A int result = fchown(fd, hostOwner, hostGroup); 5461999SN/A return (result == -1) ? -errno : result; 5471999SN/A} 5482093SN/A 5492093SN/A 5502093SN/ASyscallReturn 5513114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5523079Sstever@eecs.umich.edu{ 5536701Sgblack@eecs.umich.edu int index = 0; 5546701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5553079Sstever@eecs.umich.edu if (fd < 0) 5563079Sstever@eecs.umich.edu return -EBADF; 5573079Sstever@eecs.umich.edu 5586701Sgblack@eecs.umich.edu Process::FdMap *fdo = process->sim_fd_obj(fd); 5595282Srstrong@cs.ucsd.edu 5603079Sstever@eecs.umich.edu int result = dup(fd); 5616111Ssteve.reinhardt@amd.com return (result == -1) ? -errno : 5626111Ssteve.reinhardt@amd.com process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); 5633079Sstever@eecs.umich.edu} 5643079Sstever@eecs.umich.edu 5653079Sstever@eecs.umich.edu 5663079Sstever@eecs.umich.eduSyscallReturn 5673114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 5682680Sktlim@umich.edu ThreadContext *tc) 5692093SN/A{ 5706701Sgblack@eecs.umich.edu int index = 0; 5716701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5722093SN/A 5732093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 5742093SN/A return -EBADF; 5752093SN/A 5766701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5772093SN/A switch (cmd) { 5782093SN/A case 0: // F_DUPFD 5792093SN/A // if we really wanted to support this, we'd need to do it 5802093SN/A // in the target fd space. 5812093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 5822093SN/A return -EMFILE; 5832093SN/A 5842093SN/A case 1: // F_GETFD (get close-on-exec flag) 5852093SN/A case 2: // F_SETFD (set close-on-exec flag) 5862093SN/A return 0; 5872093SN/A 5882093SN/A case 3: // F_GETFL (get file flags) 5892093SN/A case 4: // F_SETFL (set file flags) 5902093SN/A // not sure if this is totally valid, but we'll pass it through 5912093SN/A // to the underlying OS 5922093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 5932093SN/A return fcntl(process->sim_fd(fd), cmd); 5942093SN/A // return 0; 5952093SN/A 5962093SN/A case 7: // F_GETLK (get lock) 5972093SN/A case 8: // F_SETLK (set lock) 5982093SN/A case 9: // F_SETLKW (set lock and wait) 5992093SN/A // don't mess with file locking... just act like it's OK 6002093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 6012093SN/A return 0; 6022093SN/A 6032093SN/A default: 6042093SN/A warn("Unknown fcntl command %d\n", cmd); 6052093SN/A return 0; 6062093SN/A } 6072093SN/A} 6082093SN/A 6092238SN/ASyscallReturn 6103114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 6112687Sksewell@umich.edu ThreadContext *tc) 6122687Sksewell@umich.edu{ 6136701Sgblack@eecs.umich.edu int index = 0; 6146701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 6152687Sksewell@umich.edu 6162687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 6172687Sksewell@umich.edu return -EBADF; 6182687Sksewell@umich.edu 6196701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 6202687Sksewell@umich.edu switch (cmd) { 6212687Sksewell@umich.edu case 33: //F_GETLK64 6222687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 6232687Sksewell@umich.edu return -EMFILE; 6242687Sksewell@umich.edu 6252687Sksewell@umich.edu case 34: // F_SETLK64 6262687Sksewell@umich.edu case 35: // F_SETLKW64 6272687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 6282687Sksewell@umich.edu return -EMFILE; 6292687Sksewell@umich.edu 6302687Sksewell@umich.edu default: 6312687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 6322687Sksewell@umich.edu // to the underlying OS 6332687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 6342687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 6352687Sksewell@umich.edu // return 0; 6362687Sksewell@umich.edu } 6372687Sksewell@umich.edu} 6382687Sksewell@umich.edu 6392687Sksewell@umich.eduSyscallReturn 6403114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6412680Sktlim@umich.edu ThreadContext *tc) 6422238SN/A{ 6432238SN/A int fds[2], sim_fds[2]; 6442238SN/A int pipe_retval = pipe(fds); 6452093SN/A 6462238SN/A if (pipe_retval < 0) { 6472238SN/A // error 6482238SN/A return pipe_retval; 6492238SN/A } 6502238SN/A 6515282Srstrong@cs.ucsd.edu sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 6525282Srstrong@cs.ucsd.edu sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); 6532238SN/A 6545282Srstrong@cs.ucsd.edu process->setReadPipeSource(sim_fds[0], sim_fds[1]); 6552238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 6562238SN/A // the return value of the function, and fd[1] is returned in r20. 6572680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 6582238SN/A return sim_fds[0]; 6592238SN/A} 6602238SN/A 6612238SN/A 6622238SN/ASyscallReturn 6633114Sgblack@eecs.umich.edugetpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6642680Sktlim@umich.edu ThreadContext *tc) 6652238SN/A{ 6662238SN/A // Make up a PID. There's no interprocess communication in 6672238SN/A // fake_syscall mode, so there's no way for a process to know it's 6682238SN/A // not getting a unique value. 6692238SN/A 6703114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 6713114Sgblack@eecs.umich.edu return process->pid(); 6722238SN/A} 6732238SN/A 6742238SN/A 6752238SN/ASyscallReturn 6763114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6772680Sktlim@umich.edu ThreadContext *tc) 6782238SN/A{ 6792238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 6802238SN/A // simulation to be deterministic. 6812238SN/A 6822238SN/A // EUID goes in r20. 6833114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 6845543Ssaidi@eecs.umich.edu return process->uid(); // UID 6852238SN/A} 6862238SN/A 6872238SN/A 6882238SN/ASyscallReturn 6893114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6902680Sktlim@umich.edu ThreadContext *tc) 6912238SN/A{ 6922238SN/A // Get current group ID. EGID goes in r20. 6933114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 6943114Sgblack@eecs.umich.edu return process->gid(); 6952238SN/A} 6962238SN/A 6972238SN/A 6982238SN/ASyscallReturn 6993114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7002680Sktlim@umich.edu ThreadContext *tc) 7012238SN/A{ 7022238SN/A // can't fathom why a benchmark would call this. 7036701Sgblack@eecs.umich.edu int index = 0; 7046701Sgblack@eecs.umich.edu warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 7052238SN/A return 0; 7062238SN/A} 7072238SN/A 7082238SN/ASyscallReturn 7093114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7102680Sktlim@umich.edu ThreadContext *tc) 7112238SN/A{ 7122238SN/A // Make up a PID. There's no interprocess communication in 7132238SN/A // fake_syscall mode, so there's no way for a process to know it's 7142238SN/A // not getting a unique value. 7152238SN/A 7163114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 7173114Sgblack@eecs.umich.edu return process->pid(); 7182238SN/A} 7192238SN/A 7202238SN/ASyscallReturn 7213114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7222680Sktlim@umich.edu ThreadContext *tc) 7232238SN/A{ 7243114Sgblack@eecs.umich.edu return process->ppid(); 7252238SN/A} 7262238SN/A 7272238SN/ASyscallReturn 7283114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7292680Sktlim@umich.edu ThreadContext *tc) 7302238SN/A{ 7315543Ssaidi@eecs.umich.edu return process->uid(); // UID 7322238SN/A} 7332238SN/A 7342238SN/ASyscallReturn 7353114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7362680Sktlim@umich.edu ThreadContext *tc) 7372238SN/A{ 7385543Ssaidi@eecs.umich.edu return process->euid(); // UID 7392238SN/A} 7402238SN/A 7412238SN/ASyscallReturn 7423114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7432680Sktlim@umich.edu ThreadContext *tc) 7442238SN/A{ 7453114Sgblack@eecs.umich.edu return process->gid(); 7462238SN/A} 7472238SN/A 7482238SN/ASyscallReturn 7493114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7502680Sktlim@umich.edu ThreadContext *tc) 7512238SN/A{ 7523114Sgblack@eecs.umich.edu return process->egid(); 7532238SN/A} 7542238SN/A 7552238SN/A 7566109Ssanchezd@stanford.eduSyscallReturn 7576109Ssanchezd@stanford.educloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7586109Ssanchezd@stanford.edu ThreadContext *tc) 7596109Ssanchezd@stanford.edu{ 7606701Sgblack@eecs.umich.edu int index = 0; 7616701Sgblack@eecs.umich.edu IntReg flags = process->getSyscallArg(tc, index); 7626701Sgblack@eecs.umich.edu IntReg newStack = process->getSyscallArg(tc, index); 7636701Sgblack@eecs.umich.edu 7646109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, "In sys_clone:\n"); 7656701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 7666701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); 7676109Ssanchezd@stanford.edu 7686109Ssanchezd@stanford.edu 7696701Sgblack@eecs.umich.edu if (flags != 0x10f00) { 7706111Ssteve.reinhardt@amd.com warn("This sys_clone implementation assumes flags " 7716111Ssteve.reinhardt@amd.com "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD " 7726111Ssteve.reinhardt@amd.com "(0x10f00), and may not work correctly with given flags " 7736701Sgblack@eecs.umich.edu "0x%llx\n", flags); 7746109Ssanchezd@stanford.edu } 7756109Ssanchezd@stanford.edu 7766111Ssteve.reinhardt@amd.com ThreadContext* ctc; // child thread context 7776109Ssanchezd@stanford.edu if ( ( ctc = process->findFreeContext() ) != NULL ) { 7786109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, " Found unallocated thread context\n"); 7796109Ssanchezd@stanford.edu 7806109Ssanchezd@stanford.edu ctc->clearArchRegs(); 7816109Ssanchezd@stanford.edu 7826111Ssteve.reinhardt@amd.com // Arch-specific cloning code 7836109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA 7846111Ssteve.reinhardt@amd.com // Cloning the misc. regs for these archs is enough 7856109Ssanchezd@stanford.edu TheISA::copyMiscRegs(tc, ctc); 7866109Ssanchezd@stanford.edu #elif THE_ISA == SPARC_ISA 7876109Ssanchezd@stanford.edu TheISA::copyRegs(tc, ctc); 7886109Ssanchezd@stanford.edu 7896111Ssteve.reinhardt@amd.com // TODO: Explain what this code actually does :-) 7906109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 6, 0); 7916109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 4, 0); 7926109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2); 7936109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 5, NWindows); 7946337Sgblack@eecs.umich.edu ctc->setMiscReg(MISCREG_CWP, 0); 7956109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 7, 0); 7966109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_TL, 0); 7976109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY); 7986109Ssanchezd@stanford.edu 7996109Ssanchezd@stanford.edu for (int y = 8; y < 32; y++) 8006109Ssanchezd@stanford.edu ctc->setIntReg(y, tc->readIntReg(y)); 8016109Ssanchezd@stanford.edu #else 8026109Ssanchezd@stanford.edu fatal("sys_clone is not implemented for this ISA\n"); 8036109Ssanchezd@stanford.edu #endif 8046109Ssanchezd@stanford.edu 8056111Ssteve.reinhardt@amd.com // Set up stack register 8066701Sgblack@eecs.umich.edu ctc->setIntReg(TheISA::StackPointerReg, newStack); 8076109Ssanchezd@stanford.edu 8086111Ssteve.reinhardt@amd.com // Set up syscall return values in parent and child 8096111Ssteve.reinhardt@amd.com ctc->setIntReg(ReturnValueReg, 0); // return value, child 8106109Ssanchezd@stanford.edu 8116111Ssteve.reinhardt@amd.com // Alpha needs SyscallSuccessReg=0 in child 8126109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA 8136110Ssteve.reinhardt@amd.com ctc->setIntReg(TheISA::SyscallSuccessReg, 0); 8146109Ssanchezd@stanford.edu #endif 8156109Ssanchezd@stanford.edu 8166111Ssteve.reinhardt@amd.com // In SPARC/Linux, clone returns 0 on pseudo-return register if 8176111Ssteve.reinhardt@amd.com // parent, non-zero if child 8186109Ssanchezd@stanford.edu #if THE_ISA == SPARC_ISA 8196109Ssanchezd@stanford.edu tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0); 8206109Ssanchezd@stanford.edu ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1); 8216109Ssanchezd@stanford.edu #endif 8226109Ssanchezd@stanford.edu 8236109Ssanchezd@stanford.edu ctc->setPC(tc->readNextPC()); 8246109Ssanchezd@stanford.edu ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst)); 8256134Sgblack@eecs.umich.edu ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst)); 8266109Ssanchezd@stanford.edu 8276109Ssanchezd@stanford.edu ctc->activate(); 8286109Ssanchezd@stanford.edu 8296109Ssanchezd@stanford.edu // Should return nonzero child TID in parent's syscall return register, 8306109Ssanchezd@stanford.edu // but for our pthread library any non-zero value will work 8316109Ssanchezd@stanford.edu return 1; 8326109Ssanchezd@stanford.edu } else { 8336109Ssanchezd@stanford.edu fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 8346109Ssanchezd@stanford.edu return 0; 8356109Ssanchezd@stanford.edu } 8366109Ssanchezd@stanford.edu} 8376109Ssanchezd@stanford.edu 838