syscall_emul.cc revision 6703
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 35360SN/A#include <string> 36360SN/A#include <iostream> 37360SN/A 38360SN/A#include "sim/syscall_emul.hh" 392474SN/A#include "base/chunk_generator.hh" 40360SN/A#include "base/trace.hh" 416658Snate@binkert.org#include "config/the_isa.hh" 422680Sktlim@umich.edu#include "cpu/thread_context.hh" 431717SN/A#include "cpu/base.hh" 442474SN/A#include "mem/page_table.hh" 45360SN/A#include "sim/process.hh" 466029Ssteve.reinhardt@amd.com#include "sim/system.hh" 472667Sstever@eecs.umich.edu#include "sim/sim_exit.hh" 48360SN/A 49360SN/Ausing namespace std; 502107SN/Ausing namespace TheISA; 51360SN/A 52360SN/Avoid 533114Sgblack@eecs.umich.eduSyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) 54360SN/A{ 556702Sgblack@eecs.umich.edu#if TRACING_ON 566701Sgblack@eecs.umich.edu int index = 0; 576702Sgblack@eecs.umich.edu#endif 586111Ssteve.reinhardt@amd.com DPRINTFR(SyscallVerbose, 596111Ssteve.reinhardt@amd.com "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", 606111Ssteve.reinhardt@amd.com curTick, tc->getCpuPtr()->name(), name, 616701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 626701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 636701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 646701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index)); 65360SN/A 662680Sktlim@umich.edu SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); 67360SN/A 682495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", 692680Sktlim@umich.edu curTick,tc->getCpuPtr()->name(), name, retval.value()); 70360SN/A 711450SN/A if (!(flags & SyscallDesc::SuppressReturnValue)) 725958Sgblack@eecs.umich.edu process->setSyscallReturn(tc, retval); 73360SN/A} 74360SN/A 75360SN/A 761450SN/ASyscallReturn 773114Sgblack@eecs.umich.eduunimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 782680Sktlim@umich.edu ThreadContext *tc) 79360SN/A{ 801969SN/A fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); 812484SN/A 822484SN/A return 1; 83360SN/A} 84360SN/A 85360SN/A 861450SN/ASyscallReturn 873114Sgblack@eecs.umich.eduignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 882680Sktlim@umich.edu ThreadContext *tc) 89360SN/A{ 906701Sgblack@eecs.umich.edu int index = 0; 911969SN/A warn("ignoring syscall %s(%d, %d, ...)", desc->name, 926701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); 93360SN/A 941458SN/A return 0; 95360SN/A} 96360SN/A 97360SN/A 981450SN/ASyscallReturn 993114Sgblack@eecs.umich.eduexitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1002680Sktlim@umich.edu ThreadContext *tc) 101360SN/A{ 1026029Ssteve.reinhardt@amd.com if (process->system->numRunningContexts() == 1) { 1036029Ssteve.reinhardt@amd.com // Last running context... exit simulator 1046701Sgblack@eecs.umich.edu int index = 0; 1055958Sgblack@eecs.umich.edu exitSimLoop("target called exit()", 1066701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1076029Ssteve.reinhardt@amd.com } else { 1086029Ssteve.reinhardt@amd.com // other running threads... just halt this one 1096029Ssteve.reinhardt@amd.com tc->halt(); 1102834Sksewell@umich.edu } 111360SN/A 1121458SN/A return 1; 113360SN/A} 114360SN/A 115360SN/A 1161450SN/ASyscallReturn 1176109Ssanchezd@stanford.eduexitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1186109Ssanchezd@stanford.edu ThreadContext *tc) 1196109Ssanchezd@stanford.edu{ 1206109Ssanchezd@stanford.edu // really should just halt all thread contexts belonging to this 1216109Ssanchezd@stanford.edu // process in case there's another process running... 1226701Sgblack@eecs.umich.edu int index = 0; 1236109Ssanchezd@stanford.edu exitSimLoop("target called exit()", 1246701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1256109Ssanchezd@stanford.edu 1266109Ssanchezd@stanford.edu return 1; 1276109Ssanchezd@stanford.edu} 1286109Ssanchezd@stanford.edu 1296109Ssanchezd@stanford.edu 1306109Ssanchezd@stanford.eduSyscallReturn 1313114Sgblack@eecs.umich.edugetpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 132360SN/A{ 1332107SN/A return (int)VMPageSize; 134360SN/A} 135360SN/A 136360SN/A 1371450SN/ASyscallReturn 1385748SSteve.Reinhardt@amd.combrkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 139360SN/A{ 140360SN/A // change brk addr to first arg 1416701Sgblack@eecs.umich.edu int index = 0; 1426701Sgblack@eecs.umich.edu Addr new_brk = p->getSyscallArg(tc, index); 1435748SSteve.Reinhardt@amd.com 1445748SSteve.Reinhardt@amd.com // in Linux at least, brk(0) returns the current break value 1455748SSteve.Reinhardt@amd.com // (note that the syscall and the glibc function have different behavior) 1465748SSteve.Reinhardt@amd.com if (new_brk == 0) 1475748SSteve.Reinhardt@amd.com return p->brk_point; 1485748SSteve.Reinhardt@amd.com 1495748SSteve.Reinhardt@amd.com if (new_brk > p->brk_point) { 1505748SSteve.Reinhardt@amd.com // might need to allocate some new pages 1512474SN/A for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, 1522474SN/A VMPageSize); !gen.done(); gen.next()) { 1535748SSteve.Reinhardt@amd.com if (!p->pTable->translate(gen.addr())) 1542474SN/A p->pTable->allocate(roundDown(gen.addr(), VMPageSize), 1552474SN/A VMPageSize); 1566687Stjones1@inf.ed.ac.uk 1576687Stjones1@inf.ed.ac.uk // if the address is already there, zero it out 1586687Stjones1@inf.ed.ac.uk else { 1596687Stjones1@inf.ed.ac.uk uint8_t zero = 0; 1606687Stjones1@inf.ed.ac.uk TranslatingPort *tp = tc->getMemPort(); 1616687Stjones1@inf.ed.ac.uk 1626687Stjones1@inf.ed.ac.uk // split non-page aligned accesses 1636687Stjones1@inf.ed.ac.uk Addr next_page = roundUp(gen.addr(), VMPageSize); 1646687Stjones1@inf.ed.ac.uk uint32_t size_needed = next_page - gen.addr(); 1656687Stjones1@inf.ed.ac.uk tp->memsetBlob(gen.addr(), zero, size_needed); 1666687Stjones1@inf.ed.ac.uk if (gen.addr() + VMPageSize > next_page && 1676687Stjones1@inf.ed.ac.uk next_page < new_brk && 1686687Stjones1@inf.ed.ac.uk p->pTable->translate(next_page)) 1696687Stjones1@inf.ed.ac.uk { 1706687Stjones1@inf.ed.ac.uk size_needed = VMPageSize - size_needed; 1716687Stjones1@inf.ed.ac.uk tp->memsetBlob(next_page, zero, size_needed); 1726687Stjones1@inf.ed.ac.uk } 1736687Stjones1@inf.ed.ac.uk } 1742474SN/A } 1751450SN/A } 1765748SSteve.Reinhardt@amd.com 1775748SSteve.Reinhardt@amd.com p->brk_point = new_brk; 1781458SN/A DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); 1791458SN/A return p->brk_point; 180360SN/A} 181360SN/A 182360SN/A 1831450SN/ASyscallReturn 1843114Sgblack@eecs.umich.educloseFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 185360SN/A{ 1866701Sgblack@eecs.umich.edu int index = 0; 1876701Sgblack@eecs.umich.edu int target_fd = p->getSyscallArg(tc, index); 1881970SN/A int status = close(p->sim_fd(target_fd)); 1891970SN/A if (status >= 0) 1901970SN/A p->free_fd(target_fd); 1911970SN/A return status; 192360SN/A} 193360SN/A 194360SN/A 1951450SN/ASyscallReturn 1963114Sgblack@eecs.umich.edureadFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 197360SN/A{ 1986701Sgblack@eecs.umich.edu int index = 0; 1996701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2006701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2016701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2026701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 203360SN/A 204360SN/A int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); 205360SN/A 206360SN/A if (bytes_read != -1) 2072680Sktlim@umich.edu bufArg.copyOut(tc->getMemPort()); 208360SN/A 2091458SN/A return bytes_read; 210360SN/A} 211360SN/A 2121450SN/ASyscallReturn 2133114Sgblack@eecs.umich.eduwriteFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 214360SN/A{ 2156701Sgblack@eecs.umich.edu int index = 0; 2166701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2176701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2186701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2196701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 220360SN/A 2212680Sktlim@umich.edu bufArg.copyIn(tc->getMemPort()); 222360SN/A 223360SN/A int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); 224360SN/A 225360SN/A fsync(fd); 226360SN/A 2271458SN/A return bytes_written; 228360SN/A} 229360SN/A 230360SN/A 2311450SN/ASyscallReturn 2323114Sgblack@eecs.umich.edulseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 233360SN/A{ 2346701Sgblack@eecs.umich.edu int index = 0; 2356701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2366701Sgblack@eecs.umich.edu uint64_t offs = p->getSyscallArg(tc, index); 2376701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 238360SN/A 239360SN/A off_t result = lseek(fd, offs, whence); 240360SN/A 2411458SN/A return (result == (off_t)-1) ? -errno : result; 242360SN/A} 243360SN/A 244360SN/A 2451450SN/ASyscallReturn 2464118Sgblack@eecs.umich.edu_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 2474118Sgblack@eecs.umich.edu{ 2486701Sgblack@eecs.umich.edu int index = 0; 2496701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2506701Sgblack@eecs.umich.edu uint64_t offset_high = p->getSyscallArg(tc, index); 2516701Sgblack@eecs.umich.edu uint32_t offset_low = p->getSyscallArg(tc, index); 2526701Sgblack@eecs.umich.edu Addr result_ptr = p->getSyscallArg(tc, index); 2536701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 2544118Sgblack@eecs.umich.edu 2554118Sgblack@eecs.umich.edu uint64_t offset = (offset_high << 32) | offset_low; 2564118Sgblack@eecs.umich.edu 2574118Sgblack@eecs.umich.edu uint64_t result = lseek(fd, offset, whence); 2584118Sgblack@eecs.umich.edu result = TheISA::htog(result); 2594118Sgblack@eecs.umich.edu 2604118Sgblack@eecs.umich.edu if (result == (off_t)-1) { 2614118Sgblack@eecs.umich.edu //The seek failed. 2624118Sgblack@eecs.umich.edu return -errno; 2634118Sgblack@eecs.umich.edu } else { 2646111Ssteve.reinhardt@amd.com // The seek succeeded. 2656111Ssteve.reinhardt@amd.com // Copy "result" to "result_ptr" 2666111Ssteve.reinhardt@amd.com // XXX We'll assume that the size of loff_t is 64 bits on the 2676111Ssteve.reinhardt@amd.com // target platform 2684118Sgblack@eecs.umich.edu BufferArg result_buf(result_ptr, sizeof(result)); 2694118Sgblack@eecs.umich.edu memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 2704118Sgblack@eecs.umich.edu result_buf.copyOut(tc->getMemPort()); 2714118Sgblack@eecs.umich.edu return 0; 2724118Sgblack@eecs.umich.edu } 2734118Sgblack@eecs.umich.edu 2744118Sgblack@eecs.umich.edu 2754118Sgblack@eecs.umich.edu return (result == (off_t)-1) ? -errno : result; 2764118Sgblack@eecs.umich.edu} 2774118Sgblack@eecs.umich.edu 2784118Sgblack@eecs.umich.edu 2794118Sgblack@eecs.umich.eduSyscallReturn 2803114Sgblack@eecs.umich.edumunmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 281360SN/A{ 282360SN/A // given that we don't really implement mmap, munmap is really easy 2831458SN/A return 0; 284360SN/A} 285360SN/A 286360SN/A 287360SN/Aconst char *hostname = "m5.eecs.umich.edu"; 288360SN/A 2891450SN/ASyscallReturn 2903114Sgblack@eecs.umich.edugethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 291360SN/A{ 2926701Sgblack@eecs.umich.edu int index = 0; 2936701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2946701Sgblack@eecs.umich.edu int name_len = p->getSyscallArg(tc, index); 2956701Sgblack@eecs.umich.edu BufferArg name(bufPtr, name_len); 296360SN/A 297360SN/A strncpy((char *)name.bufferPtr(), hostname, name_len); 298360SN/A 2992680Sktlim@umich.edu name.copyOut(tc->getMemPort()); 300360SN/A 3011458SN/A return 0; 302360SN/A} 303360SN/A 3041450SN/ASyscallReturn 3055513SMichael.Adler@intel.comgetcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3065513SMichael.Adler@intel.com{ 3075513SMichael.Adler@intel.com int result = 0; 3086701Sgblack@eecs.umich.edu int index; 3096701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3106701Sgblack@eecs.umich.edu unsigned long size = p->getSyscallArg(tc, index); 3116701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, size); 3125513SMichael.Adler@intel.com 3135513SMichael.Adler@intel.com // Is current working directory defined? 3145513SMichael.Adler@intel.com string cwd = p->getcwd(); 3155513SMichael.Adler@intel.com if (!cwd.empty()) { 3165513SMichael.Adler@intel.com if (cwd.length() >= size) { 3175513SMichael.Adler@intel.com // Buffer too small 3185513SMichael.Adler@intel.com return -ERANGE; 3195513SMichael.Adler@intel.com } 3205513SMichael.Adler@intel.com strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 3215513SMichael.Adler@intel.com result = cwd.length(); 3225513SMichael.Adler@intel.com } 3235513SMichael.Adler@intel.com else { 3245513SMichael.Adler@intel.com if (getcwd((char *)buf.bufferPtr(), size) != NULL) { 3255513SMichael.Adler@intel.com result = strlen((char *)buf.bufferPtr()); 3265513SMichael.Adler@intel.com } 3275513SMichael.Adler@intel.com else { 3285513SMichael.Adler@intel.com result = -1; 3295513SMichael.Adler@intel.com } 3305513SMichael.Adler@intel.com } 3315513SMichael.Adler@intel.com 3325513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3335513SMichael.Adler@intel.com 3345513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3355513SMichael.Adler@intel.com} 3365513SMichael.Adler@intel.com 3375513SMichael.Adler@intel.com 3385513SMichael.Adler@intel.comSyscallReturn 3395513SMichael.Adler@intel.comreadlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3405513SMichael.Adler@intel.com{ 3415513SMichael.Adler@intel.com string path; 3425513SMichael.Adler@intel.com 3436701Sgblack@eecs.umich.edu int index = 0; 3446701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3455513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3465513SMichael.Adler@intel.com 3475513SMichael.Adler@intel.com // Adjust path for current working directory 3485513SMichael.Adler@intel.com path = p->fullPath(path); 3495513SMichael.Adler@intel.com 3506701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3516701Sgblack@eecs.umich.edu size_t bufsiz = p->getSyscallArg(tc, index); 3526701Sgblack@eecs.umich.edu 3536701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, bufsiz); 3545513SMichael.Adler@intel.com 3555513SMichael.Adler@intel.com int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 3565513SMichael.Adler@intel.com 3575513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3585513SMichael.Adler@intel.com 3595513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3605513SMichael.Adler@intel.com} 3615513SMichael.Adler@intel.com 3625513SMichael.Adler@intel.comSyscallReturn 3633114Sgblack@eecs.umich.eduunlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 364511SN/A{ 3651706SN/A string path; 366360SN/A 3676701Sgblack@eecs.umich.edu int index = 0; 3686701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3691450SN/A return (TheISA::IntReg)-EFAULT; 370511SN/A 3713669Sbinkertn@umich.edu // Adjust path for current working directory 3723669Sbinkertn@umich.edu path = p->fullPath(path); 3733669Sbinkertn@umich.edu 374511SN/A int result = unlink(path.c_str()); 3751458SN/A return (result == -1) ? -errno : result; 376511SN/A} 377511SN/A 3785513SMichael.Adler@intel.com 3795513SMichael.Adler@intel.comSyscallReturn 3805513SMichael.Adler@intel.commkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3815513SMichael.Adler@intel.com{ 3825513SMichael.Adler@intel.com string path; 3835513SMichael.Adler@intel.com 3846701Sgblack@eecs.umich.edu int index = 0; 3856701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3865513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3875513SMichael.Adler@intel.com 3885513SMichael.Adler@intel.com // Adjust path for current working directory 3895513SMichael.Adler@intel.com path = p->fullPath(path); 3905513SMichael.Adler@intel.com 3916701Sgblack@eecs.umich.edu mode_t mode = p->getSyscallArg(tc, index); 3925513SMichael.Adler@intel.com 3935513SMichael.Adler@intel.com int result = mkdir(path.c_str(), mode); 3945513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3955513SMichael.Adler@intel.com} 3965513SMichael.Adler@intel.com 3971450SN/ASyscallReturn 3983114Sgblack@eecs.umich.edurenameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 399511SN/A{ 4001706SN/A string old_name; 401511SN/A 4026701Sgblack@eecs.umich.edu int index = 0; 4036701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index))) 4041458SN/A return -EFAULT; 405511SN/A 4061706SN/A string new_name; 407511SN/A 4086701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index))) 4091458SN/A return -EFAULT; 410511SN/A 4113669Sbinkertn@umich.edu // Adjust path for current working directory 4123669Sbinkertn@umich.edu old_name = p->fullPath(old_name); 4133669Sbinkertn@umich.edu new_name = p->fullPath(new_name); 4143669Sbinkertn@umich.edu 4151706SN/A int64_t result = rename(old_name.c_str(), new_name.c_str()); 4161458SN/A return (result == -1) ? -errno : result; 417511SN/A} 418511SN/A 4191706SN/ASyscallReturn 4203114Sgblack@eecs.umich.edutruncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4211706SN/A{ 4221706SN/A string path; 4231706SN/A 4246701Sgblack@eecs.umich.edu int index = 0; 4256701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4261706SN/A return -EFAULT; 4271706SN/A 4286701Sgblack@eecs.umich.edu off_t length = p->getSyscallArg(tc, index); 4291706SN/A 4303669Sbinkertn@umich.edu // Adjust path for current working directory 4313669Sbinkertn@umich.edu path = p->fullPath(path); 4323669Sbinkertn@umich.edu 4331706SN/A int result = truncate(path.c_str(), length); 4341706SN/A return (result == -1) ? -errno : result; 4351706SN/A} 4361706SN/A 4371706SN/ASyscallReturn 4386111Ssteve.reinhardt@amd.comftruncateFunc(SyscallDesc *desc, int num, 4396111Ssteve.reinhardt@amd.com LiveProcess *process, ThreadContext *tc) 4401706SN/A{ 4416701Sgblack@eecs.umich.edu int index = 0; 4426701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4431706SN/A 4441706SN/A if (fd < 0) 4451706SN/A return -EBADF; 4461706SN/A 4476701Sgblack@eecs.umich.edu off_t length = process->getSyscallArg(tc, index); 4481706SN/A 4491706SN/A int result = ftruncate(fd, length); 4501706SN/A return (result == -1) ? -errno : result; 4511706SN/A} 4521999SN/A 4531999SN/ASyscallReturn 4546703Svince@csl.cornell.edutruncate64Func(SyscallDesc *desc, int num, 4556703Svince@csl.cornell.edu LiveProcess *process, ThreadContext *tc) 4566703Svince@csl.cornell.edu{ 4576703Svince@csl.cornell.edu int index = 0; 4586703Svince@csl.cornell.edu string path; 4596703Svince@csl.cornell.edu 4606703Svince@csl.cornell.edu if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, index))) 4616703Svince@csl.cornell.edu return -EFAULT; 4626703Svince@csl.cornell.edu 4636703Svince@csl.cornell.edu loff_t length = process->getSyscallArg(tc, index, 64); 4646703Svince@csl.cornell.edu 4656703Svince@csl.cornell.edu // Adjust path for current working directory 4666703Svince@csl.cornell.edu path = process->fullPath(path); 4676703Svince@csl.cornell.edu 4686703Svince@csl.cornell.edu int result = truncate64(path.c_str(), length); 4696703Svince@csl.cornell.edu return (result == -1) ? -errno : result; 4706703Svince@csl.cornell.edu} 4716703Svince@csl.cornell.edu 4726703Svince@csl.cornell.eduSyscallReturn 4736685Stjones1@inf.ed.ac.ukftruncate64Func(SyscallDesc *desc, int num, 4746685Stjones1@inf.ed.ac.uk LiveProcess *process, ThreadContext *tc) 4756685Stjones1@inf.ed.ac.uk{ 4766701Sgblack@eecs.umich.edu int index = 0; 4776701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4786685Stjones1@inf.ed.ac.uk 4796685Stjones1@inf.ed.ac.uk if (fd < 0) 4806685Stjones1@inf.ed.ac.uk return -EBADF; 4816685Stjones1@inf.ed.ac.uk 4826701Sgblack@eecs.umich.edu loff_t length = process->getSyscallArg(tc, index, 64); 4836685Stjones1@inf.ed.ac.uk 4846685Stjones1@inf.ed.ac.uk int result = ftruncate64(fd, length); 4856685Stjones1@inf.ed.ac.uk return (result == -1) ? -errno : result; 4866685Stjones1@inf.ed.ac.uk} 4876685Stjones1@inf.ed.ac.uk 4886685Stjones1@inf.ed.ac.ukSyscallReturn 4895513SMichael.Adler@intel.comumaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 4905513SMichael.Adler@intel.com{ 4915513SMichael.Adler@intel.com // Letting the simulated program change the simulator's umask seems like 4925513SMichael.Adler@intel.com // a bad idea. Compromise by just returning the current umask but not 4935513SMichael.Adler@intel.com // changing anything. 4945513SMichael.Adler@intel.com mode_t oldMask = umask(0); 4955513SMichael.Adler@intel.com umask(oldMask); 4965521Snate@binkert.org return (int)oldMask; 4975513SMichael.Adler@intel.com} 4985513SMichael.Adler@intel.com 4995513SMichael.Adler@intel.comSyscallReturn 5003114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 5011999SN/A{ 5021999SN/A string path; 5031999SN/A 5046701Sgblack@eecs.umich.edu int index = 0; 5056701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 5061999SN/A return -EFAULT; 5071999SN/A 5081999SN/A /* XXX endianess */ 5096701Sgblack@eecs.umich.edu uint32_t owner = p->getSyscallArg(tc, index); 5101999SN/A uid_t hostOwner = owner; 5116701Sgblack@eecs.umich.edu uint32_t group = p->getSyscallArg(tc, index); 5121999SN/A gid_t hostGroup = group; 5131999SN/A 5143669Sbinkertn@umich.edu // Adjust path for current working directory 5153669Sbinkertn@umich.edu path = p->fullPath(path); 5163669Sbinkertn@umich.edu 5171999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 5181999SN/A return (result == -1) ? -errno : result; 5191999SN/A} 5201999SN/A 5211999SN/ASyscallReturn 5223114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5231999SN/A{ 5246701Sgblack@eecs.umich.edu int index = 0; 5256701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5261999SN/A 5271999SN/A if (fd < 0) 5281999SN/A return -EBADF; 5291999SN/A 5301999SN/A /* XXX endianess */ 5316701Sgblack@eecs.umich.edu uint32_t owner = process->getSyscallArg(tc, index); 5321999SN/A uid_t hostOwner = owner; 5336701Sgblack@eecs.umich.edu uint32_t group = process->getSyscallArg(tc, index); 5341999SN/A gid_t hostGroup = group; 5351999SN/A 5361999SN/A int result = fchown(fd, hostOwner, hostGroup); 5371999SN/A return (result == -1) ? -errno : result; 5381999SN/A} 5392093SN/A 5402093SN/A 5412093SN/ASyscallReturn 5423114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5433079Sstever@eecs.umich.edu{ 5446701Sgblack@eecs.umich.edu int index = 0; 5456701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5463079Sstever@eecs.umich.edu if (fd < 0) 5473079Sstever@eecs.umich.edu return -EBADF; 5483079Sstever@eecs.umich.edu 5496701Sgblack@eecs.umich.edu Process::FdMap *fdo = process->sim_fd_obj(fd); 5505282Srstrong@cs.ucsd.edu 5513079Sstever@eecs.umich.edu int result = dup(fd); 5526111Ssteve.reinhardt@amd.com return (result == -1) ? -errno : 5536111Ssteve.reinhardt@amd.com process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); 5543079Sstever@eecs.umich.edu} 5553079Sstever@eecs.umich.edu 5563079Sstever@eecs.umich.edu 5573079Sstever@eecs.umich.eduSyscallReturn 5583114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 5592680Sktlim@umich.edu ThreadContext *tc) 5602093SN/A{ 5616701Sgblack@eecs.umich.edu int index = 0; 5626701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5632093SN/A 5642093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 5652093SN/A return -EBADF; 5662093SN/A 5676701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5682093SN/A switch (cmd) { 5692093SN/A case 0: // F_DUPFD 5702093SN/A // if we really wanted to support this, we'd need to do it 5712093SN/A // in the target fd space. 5722093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 5732093SN/A return -EMFILE; 5742093SN/A 5752093SN/A case 1: // F_GETFD (get close-on-exec flag) 5762093SN/A case 2: // F_SETFD (set close-on-exec flag) 5772093SN/A return 0; 5782093SN/A 5792093SN/A case 3: // F_GETFL (get file flags) 5802093SN/A case 4: // F_SETFL (set file flags) 5812093SN/A // not sure if this is totally valid, but we'll pass it through 5822093SN/A // to the underlying OS 5832093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 5842093SN/A return fcntl(process->sim_fd(fd), cmd); 5852093SN/A // return 0; 5862093SN/A 5872093SN/A case 7: // F_GETLK (get lock) 5882093SN/A case 8: // F_SETLK (set lock) 5892093SN/A case 9: // F_SETLKW (set lock and wait) 5902093SN/A // don't mess with file locking... just act like it's OK 5912093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 5922093SN/A return 0; 5932093SN/A 5942093SN/A default: 5952093SN/A warn("Unknown fcntl command %d\n", cmd); 5962093SN/A return 0; 5972093SN/A } 5982093SN/A} 5992093SN/A 6002238SN/ASyscallReturn 6013114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 6022687Sksewell@umich.edu ThreadContext *tc) 6032687Sksewell@umich.edu{ 6046701Sgblack@eecs.umich.edu int index = 0; 6056701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 6062687Sksewell@umich.edu 6072687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 6082687Sksewell@umich.edu return -EBADF; 6092687Sksewell@umich.edu 6106701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 6112687Sksewell@umich.edu switch (cmd) { 6122687Sksewell@umich.edu case 33: //F_GETLK64 6132687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 6142687Sksewell@umich.edu return -EMFILE; 6152687Sksewell@umich.edu 6162687Sksewell@umich.edu case 34: // F_SETLK64 6172687Sksewell@umich.edu case 35: // F_SETLKW64 6182687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 6192687Sksewell@umich.edu return -EMFILE; 6202687Sksewell@umich.edu 6212687Sksewell@umich.edu default: 6222687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 6232687Sksewell@umich.edu // to the underlying OS 6242687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 6252687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 6262687Sksewell@umich.edu // return 0; 6272687Sksewell@umich.edu } 6282687Sksewell@umich.edu} 6292687Sksewell@umich.edu 6302687Sksewell@umich.eduSyscallReturn 6313114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6322680Sktlim@umich.edu ThreadContext *tc) 6332238SN/A{ 6342238SN/A int fds[2], sim_fds[2]; 6352238SN/A int pipe_retval = pipe(fds); 6362093SN/A 6372238SN/A if (pipe_retval < 0) { 6382238SN/A // error 6392238SN/A return pipe_retval; 6402238SN/A } 6412238SN/A 6425282Srstrong@cs.ucsd.edu sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 6435282Srstrong@cs.ucsd.edu sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); 6442238SN/A 6455282Srstrong@cs.ucsd.edu process->setReadPipeSource(sim_fds[0], sim_fds[1]); 6462238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 6472238SN/A // the return value of the function, and fd[1] is returned in r20. 6482680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 6492238SN/A return sim_fds[0]; 6502238SN/A} 6512238SN/A 6522238SN/A 6532238SN/ASyscallReturn 6543114Sgblack@eecs.umich.edugetpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6552680Sktlim@umich.edu ThreadContext *tc) 6562238SN/A{ 6572238SN/A // Make up a PID. There's no interprocess communication in 6582238SN/A // fake_syscall mode, so there's no way for a process to know it's 6592238SN/A // not getting a unique value. 6602238SN/A 6613114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 6623114Sgblack@eecs.umich.edu return process->pid(); 6632238SN/A} 6642238SN/A 6652238SN/A 6662238SN/ASyscallReturn 6673114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6682680Sktlim@umich.edu ThreadContext *tc) 6692238SN/A{ 6702238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 6712238SN/A // simulation to be deterministic. 6722238SN/A 6732238SN/A // EUID goes in r20. 6743114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 6755543Ssaidi@eecs.umich.edu return process->uid(); // UID 6762238SN/A} 6772238SN/A 6782238SN/A 6792238SN/ASyscallReturn 6803114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6812680Sktlim@umich.edu ThreadContext *tc) 6822238SN/A{ 6832238SN/A // Get current group ID. EGID goes in r20. 6843114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 6853114Sgblack@eecs.umich.edu return process->gid(); 6862238SN/A} 6872238SN/A 6882238SN/A 6892238SN/ASyscallReturn 6903114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6912680Sktlim@umich.edu ThreadContext *tc) 6922238SN/A{ 6932238SN/A // can't fathom why a benchmark would call this. 6946701Sgblack@eecs.umich.edu int index = 0; 6956701Sgblack@eecs.umich.edu warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 6962238SN/A return 0; 6972238SN/A} 6982238SN/A 6992238SN/ASyscallReturn 7003114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7012680Sktlim@umich.edu ThreadContext *tc) 7022238SN/A{ 7032238SN/A // Make up a PID. There's no interprocess communication in 7042238SN/A // fake_syscall mode, so there's no way for a process to know it's 7052238SN/A // not getting a unique value. 7062238SN/A 7073114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 7083114Sgblack@eecs.umich.edu return process->pid(); 7092238SN/A} 7102238SN/A 7112238SN/ASyscallReturn 7123114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7132680Sktlim@umich.edu ThreadContext *tc) 7142238SN/A{ 7153114Sgblack@eecs.umich.edu return process->ppid(); 7162238SN/A} 7172238SN/A 7182238SN/ASyscallReturn 7193114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7202680Sktlim@umich.edu ThreadContext *tc) 7212238SN/A{ 7225543Ssaidi@eecs.umich.edu return process->uid(); // UID 7232238SN/A} 7242238SN/A 7252238SN/ASyscallReturn 7263114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7272680Sktlim@umich.edu ThreadContext *tc) 7282238SN/A{ 7295543Ssaidi@eecs.umich.edu return process->euid(); // UID 7302238SN/A} 7312238SN/A 7322238SN/ASyscallReturn 7333114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7342680Sktlim@umich.edu ThreadContext *tc) 7352238SN/A{ 7363114Sgblack@eecs.umich.edu return process->gid(); 7372238SN/A} 7382238SN/A 7392238SN/ASyscallReturn 7403114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7412680Sktlim@umich.edu ThreadContext *tc) 7422238SN/A{ 7433114Sgblack@eecs.umich.edu return process->egid(); 7442238SN/A} 7452238SN/A 7462238SN/A 7476109Ssanchezd@stanford.eduSyscallReturn 7486109Ssanchezd@stanford.educloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7496109Ssanchezd@stanford.edu ThreadContext *tc) 7506109Ssanchezd@stanford.edu{ 7516701Sgblack@eecs.umich.edu int index = 0; 7526701Sgblack@eecs.umich.edu IntReg flags = process->getSyscallArg(tc, index); 7536701Sgblack@eecs.umich.edu IntReg newStack = process->getSyscallArg(tc, index); 7546701Sgblack@eecs.umich.edu 7556109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, "In sys_clone:\n"); 7566701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 7576701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); 7586109Ssanchezd@stanford.edu 7596109Ssanchezd@stanford.edu 7606701Sgblack@eecs.umich.edu if (flags != 0x10f00) { 7616111Ssteve.reinhardt@amd.com warn("This sys_clone implementation assumes flags " 7626111Ssteve.reinhardt@amd.com "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD " 7636111Ssteve.reinhardt@amd.com "(0x10f00), and may not work correctly with given flags " 7646701Sgblack@eecs.umich.edu "0x%llx\n", flags); 7656109Ssanchezd@stanford.edu } 7666109Ssanchezd@stanford.edu 7676111Ssteve.reinhardt@amd.com ThreadContext* ctc; // child thread context 7686109Ssanchezd@stanford.edu if ( ( ctc = process->findFreeContext() ) != NULL ) { 7696109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, " Found unallocated thread context\n"); 7706109Ssanchezd@stanford.edu 7716109Ssanchezd@stanford.edu ctc->clearArchRegs(); 7726109Ssanchezd@stanford.edu 7736111Ssteve.reinhardt@amd.com // Arch-specific cloning code 7746109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA 7756111Ssteve.reinhardt@amd.com // Cloning the misc. regs for these archs is enough 7766109Ssanchezd@stanford.edu TheISA::copyMiscRegs(tc, ctc); 7776109Ssanchezd@stanford.edu #elif THE_ISA == SPARC_ISA 7786109Ssanchezd@stanford.edu TheISA::copyRegs(tc, ctc); 7796109Ssanchezd@stanford.edu 7806111Ssteve.reinhardt@amd.com // TODO: Explain what this code actually does :-) 7816109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 6, 0); 7826109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 4, 0); 7836109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2); 7846109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 5, NWindows); 7856337Sgblack@eecs.umich.edu ctc->setMiscReg(MISCREG_CWP, 0); 7866109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 7, 0); 7876109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_TL, 0); 7886109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY); 7896109Ssanchezd@stanford.edu 7906109Ssanchezd@stanford.edu for (int y = 8; y < 32; y++) 7916109Ssanchezd@stanford.edu ctc->setIntReg(y, tc->readIntReg(y)); 7926109Ssanchezd@stanford.edu #else 7936109Ssanchezd@stanford.edu fatal("sys_clone is not implemented for this ISA\n"); 7946109Ssanchezd@stanford.edu #endif 7956109Ssanchezd@stanford.edu 7966111Ssteve.reinhardt@amd.com // Set up stack register 7976701Sgblack@eecs.umich.edu ctc->setIntReg(TheISA::StackPointerReg, newStack); 7986109Ssanchezd@stanford.edu 7996111Ssteve.reinhardt@amd.com // Set up syscall return values in parent and child 8006111Ssteve.reinhardt@amd.com ctc->setIntReg(ReturnValueReg, 0); // return value, child 8016109Ssanchezd@stanford.edu 8026111Ssteve.reinhardt@amd.com // Alpha needs SyscallSuccessReg=0 in child 8036109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA 8046110Ssteve.reinhardt@amd.com ctc->setIntReg(TheISA::SyscallSuccessReg, 0); 8056109Ssanchezd@stanford.edu #endif 8066109Ssanchezd@stanford.edu 8076111Ssteve.reinhardt@amd.com // In SPARC/Linux, clone returns 0 on pseudo-return register if 8086111Ssteve.reinhardt@amd.com // parent, non-zero if child 8096109Ssanchezd@stanford.edu #if THE_ISA == SPARC_ISA 8106109Ssanchezd@stanford.edu tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0); 8116109Ssanchezd@stanford.edu ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1); 8126109Ssanchezd@stanford.edu #endif 8136109Ssanchezd@stanford.edu 8146109Ssanchezd@stanford.edu ctc->setPC(tc->readNextPC()); 8156109Ssanchezd@stanford.edu ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst)); 8166134Sgblack@eecs.umich.edu ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst)); 8176109Ssanchezd@stanford.edu 8186109Ssanchezd@stanford.edu ctc->activate(); 8196109Ssanchezd@stanford.edu 8206109Ssanchezd@stanford.edu // Should return nonzero child TID in parent's syscall return register, 8216109Ssanchezd@stanford.edu // but for our pthread library any non-zero value will work 8226109Ssanchezd@stanford.edu return 1; 8236109Ssanchezd@stanford.edu } else { 8246109Ssanchezd@stanford.edu fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 8256109Ssanchezd@stanford.edu return 0; 8266109Ssanchezd@stanford.edu } 8276109Ssanchezd@stanford.edu} 8286109Ssanchezd@stanford.edu 829