syscall_emul.cc revision 6701
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{ 556701Sgblack@eecs.umich.edu int index = 0; 566111Ssteve.reinhardt@amd.com DPRINTFR(SyscallVerbose, 576111Ssteve.reinhardt@amd.com "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", 586111Ssteve.reinhardt@amd.com curTick, tc->getCpuPtr()->name(), name, 596701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 606701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 616701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 626701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index)); 63360SN/A 642680Sktlim@umich.edu SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); 65360SN/A 662495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", 672680Sktlim@umich.edu curTick,tc->getCpuPtr()->name(), name, retval.value()); 68360SN/A 691450SN/A if (!(flags & SyscallDesc::SuppressReturnValue)) 705958Sgblack@eecs.umich.edu process->setSyscallReturn(tc, retval); 71360SN/A} 72360SN/A 73360SN/A 741450SN/ASyscallReturn 753114Sgblack@eecs.umich.eduunimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 762680Sktlim@umich.edu ThreadContext *tc) 77360SN/A{ 781969SN/A fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); 792484SN/A 802484SN/A return 1; 81360SN/A} 82360SN/A 83360SN/A 841450SN/ASyscallReturn 853114Sgblack@eecs.umich.eduignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 862680Sktlim@umich.edu ThreadContext *tc) 87360SN/A{ 886701Sgblack@eecs.umich.edu int index = 0; 891969SN/A warn("ignoring syscall %s(%d, %d, ...)", desc->name, 906701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); 91360SN/A 921458SN/A return 0; 93360SN/A} 94360SN/A 95360SN/A 961450SN/ASyscallReturn 973114Sgblack@eecs.umich.eduexitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 982680Sktlim@umich.edu ThreadContext *tc) 99360SN/A{ 1006029Ssteve.reinhardt@amd.com if (process->system->numRunningContexts() == 1) { 1016029Ssteve.reinhardt@amd.com // Last running context... exit simulator 1026701Sgblack@eecs.umich.edu int index = 0; 1035958Sgblack@eecs.umich.edu exitSimLoop("target called exit()", 1046701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1056029Ssteve.reinhardt@amd.com } else { 1066029Ssteve.reinhardt@amd.com // other running threads... just halt this one 1076029Ssteve.reinhardt@amd.com tc->halt(); 1082834Sksewell@umich.edu } 109360SN/A 1101458SN/A return 1; 111360SN/A} 112360SN/A 113360SN/A 1141450SN/ASyscallReturn 1156109Ssanchezd@stanford.eduexitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1166109Ssanchezd@stanford.edu ThreadContext *tc) 1176109Ssanchezd@stanford.edu{ 1186109Ssanchezd@stanford.edu // really should just halt all thread contexts belonging to this 1196109Ssanchezd@stanford.edu // process in case there's another process running... 1206701Sgblack@eecs.umich.edu int index = 0; 1216109Ssanchezd@stanford.edu exitSimLoop("target called exit()", 1226701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1236109Ssanchezd@stanford.edu 1246109Ssanchezd@stanford.edu return 1; 1256109Ssanchezd@stanford.edu} 1266109Ssanchezd@stanford.edu 1276109Ssanchezd@stanford.edu 1286109Ssanchezd@stanford.eduSyscallReturn 1293114Sgblack@eecs.umich.edugetpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 130360SN/A{ 1312107SN/A return (int)VMPageSize; 132360SN/A} 133360SN/A 134360SN/A 1351450SN/ASyscallReturn 1365748SSteve.Reinhardt@amd.combrkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 137360SN/A{ 138360SN/A // change brk addr to first arg 1396701Sgblack@eecs.umich.edu int index = 0; 1406701Sgblack@eecs.umich.edu Addr new_brk = p->getSyscallArg(tc, index); 1415748SSteve.Reinhardt@amd.com 1425748SSteve.Reinhardt@amd.com // in Linux at least, brk(0) returns the current break value 1435748SSteve.Reinhardt@amd.com // (note that the syscall and the glibc function have different behavior) 1445748SSteve.Reinhardt@amd.com if (new_brk == 0) 1455748SSteve.Reinhardt@amd.com return p->brk_point; 1465748SSteve.Reinhardt@amd.com 1475748SSteve.Reinhardt@amd.com if (new_brk > p->brk_point) { 1485748SSteve.Reinhardt@amd.com // might need to allocate some new pages 1492474SN/A for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, 1502474SN/A VMPageSize); !gen.done(); gen.next()) { 1515748SSteve.Reinhardt@amd.com if (!p->pTable->translate(gen.addr())) 1522474SN/A p->pTable->allocate(roundDown(gen.addr(), VMPageSize), 1532474SN/A VMPageSize); 1546687Stjones1@inf.ed.ac.uk 1556687Stjones1@inf.ed.ac.uk // if the address is already there, zero it out 1566687Stjones1@inf.ed.ac.uk else { 1576687Stjones1@inf.ed.ac.uk uint8_t zero = 0; 1586687Stjones1@inf.ed.ac.uk TranslatingPort *tp = tc->getMemPort(); 1596687Stjones1@inf.ed.ac.uk 1606687Stjones1@inf.ed.ac.uk // split non-page aligned accesses 1616687Stjones1@inf.ed.ac.uk Addr next_page = roundUp(gen.addr(), VMPageSize); 1626687Stjones1@inf.ed.ac.uk uint32_t size_needed = next_page - gen.addr(); 1636687Stjones1@inf.ed.ac.uk tp->memsetBlob(gen.addr(), zero, size_needed); 1646687Stjones1@inf.ed.ac.uk if (gen.addr() + VMPageSize > next_page && 1656687Stjones1@inf.ed.ac.uk next_page < new_brk && 1666687Stjones1@inf.ed.ac.uk p->pTable->translate(next_page)) 1676687Stjones1@inf.ed.ac.uk { 1686687Stjones1@inf.ed.ac.uk size_needed = VMPageSize - size_needed; 1696687Stjones1@inf.ed.ac.uk tp->memsetBlob(next_page, zero, size_needed); 1706687Stjones1@inf.ed.ac.uk } 1716687Stjones1@inf.ed.ac.uk } 1722474SN/A } 1731450SN/A } 1745748SSteve.Reinhardt@amd.com 1755748SSteve.Reinhardt@amd.com p->brk_point = new_brk; 1761458SN/A DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); 1771458SN/A return p->brk_point; 178360SN/A} 179360SN/A 180360SN/A 1811450SN/ASyscallReturn 1823114Sgblack@eecs.umich.educloseFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 183360SN/A{ 1846701Sgblack@eecs.umich.edu int index = 0; 1856701Sgblack@eecs.umich.edu int target_fd = p->getSyscallArg(tc, index); 1861970SN/A int status = close(p->sim_fd(target_fd)); 1871970SN/A if (status >= 0) 1881970SN/A p->free_fd(target_fd); 1891970SN/A return status; 190360SN/A} 191360SN/A 192360SN/A 1931450SN/ASyscallReturn 1943114Sgblack@eecs.umich.edureadFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 195360SN/A{ 1966701Sgblack@eecs.umich.edu int index = 0; 1976701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 1986701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 1996701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2006701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 201360SN/A 202360SN/A int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); 203360SN/A 204360SN/A if (bytes_read != -1) 2052680Sktlim@umich.edu bufArg.copyOut(tc->getMemPort()); 206360SN/A 2071458SN/A return bytes_read; 208360SN/A} 209360SN/A 2101450SN/ASyscallReturn 2113114Sgblack@eecs.umich.eduwriteFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 212360SN/A{ 2136701Sgblack@eecs.umich.edu int index = 0; 2146701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2156701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2166701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2176701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 218360SN/A 2192680Sktlim@umich.edu bufArg.copyIn(tc->getMemPort()); 220360SN/A 221360SN/A int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); 222360SN/A 223360SN/A fsync(fd); 224360SN/A 2251458SN/A return bytes_written; 226360SN/A} 227360SN/A 228360SN/A 2291450SN/ASyscallReturn 2303114Sgblack@eecs.umich.edulseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 231360SN/A{ 2326701Sgblack@eecs.umich.edu int index = 0; 2336701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2346701Sgblack@eecs.umich.edu uint64_t offs = p->getSyscallArg(tc, index); 2356701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 236360SN/A 237360SN/A off_t result = lseek(fd, offs, whence); 238360SN/A 2391458SN/A return (result == (off_t)-1) ? -errno : result; 240360SN/A} 241360SN/A 242360SN/A 2431450SN/ASyscallReturn 2444118Sgblack@eecs.umich.edu_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 2454118Sgblack@eecs.umich.edu{ 2466701Sgblack@eecs.umich.edu int index = 0; 2476701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2486701Sgblack@eecs.umich.edu uint64_t offset_high = p->getSyscallArg(tc, index); 2496701Sgblack@eecs.umich.edu uint32_t offset_low = p->getSyscallArg(tc, index); 2506701Sgblack@eecs.umich.edu Addr result_ptr = p->getSyscallArg(tc, index); 2516701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 2524118Sgblack@eecs.umich.edu 2534118Sgblack@eecs.umich.edu uint64_t offset = (offset_high << 32) | offset_low; 2544118Sgblack@eecs.umich.edu 2554118Sgblack@eecs.umich.edu uint64_t result = lseek(fd, offset, whence); 2564118Sgblack@eecs.umich.edu result = TheISA::htog(result); 2574118Sgblack@eecs.umich.edu 2584118Sgblack@eecs.umich.edu if (result == (off_t)-1) { 2594118Sgblack@eecs.umich.edu //The seek failed. 2604118Sgblack@eecs.umich.edu return -errno; 2614118Sgblack@eecs.umich.edu } else { 2626111Ssteve.reinhardt@amd.com // The seek succeeded. 2636111Ssteve.reinhardt@amd.com // Copy "result" to "result_ptr" 2646111Ssteve.reinhardt@amd.com // XXX We'll assume that the size of loff_t is 64 bits on the 2656111Ssteve.reinhardt@amd.com // target platform 2664118Sgblack@eecs.umich.edu BufferArg result_buf(result_ptr, sizeof(result)); 2674118Sgblack@eecs.umich.edu memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 2684118Sgblack@eecs.umich.edu result_buf.copyOut(tc->getMemPort()); 2694118Sgblack@eecs.umich.edu return 0; 2704118Sgblack@eecs.umich.edu } 2714118Sgblack@eecs.umich.edu 2724118Sgblack@eecs.umich.edu 2734118Sgblack@eecs.umich.edu return (result == (off_t)-1) ? -errno : result; 2744118Sgblack@eecs.umich.edu} 2754118Sgblack@eecs.umich.edu 2764118Sgblack@eecs.umich.edu 2774118Sgblack@eecs.umich.eduSyscallReturn 2783114Sgblack@eecs.umich.edumunmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 279360SN/A{ 280360SN/A // given that we don't really implement mmap, munmap is really easy 2811458SN/A return 0; 282360SN/A} 283360SN/A 284360SN/A 285360SN/Aconst char *hostname = "m5.eecs.umich.edu"; 286360SN/A 2871450SN/ASyscallReturn 2883114Sgblack@eecs.umich.edugethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 289360SN/A{ 2906701Sgblack@eecs.umich.edu int index = 0; 2916701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 2926701Sgblack@eecs.umich.edu int name_len = p->getSyscallArg(tc, index); 2936701Sgblack@eecs.umich.edu BufferArg name(bufPtr, name_len); 294360SN/A 295360SN/A strncpy((char *)name.bufferPtr(), hostname, name_len); 296360SN/A 2972680Sktlim@umich.edu name.copyOut(tc->getMemPort()); 298360SN/A 2991458SN/A return 0; 300360SN/A} 301360SN/A 3021450SN/ASyscallReturn 3035513SMichael.Adler@intel.comgetcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3045513SMichael.Adler@intel.com{ 3055513SMichael.Adler@intel.com int result = 0; 3066701Sgblack@eecs.umich.edu int index; 3076701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3086701Sgblack@eecs.umich.edu unsigned long size = p->getSyscallArg(tc, index); 3096701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, size); 3105513SMichael.Adler@intel.com 3115513SMichael.Adler@intel.com // Is current working directory defined? 3125513SMichael.Adler@intel.com string cwd = p->getcwd(); 3135513SMichael.Adler@intel.com if (!cwd.empty()) { 3145513SMichael.Adler@intel.com if (cwd.length() >= size) { 3155513SMichael.Adler@intel.com // Buffer too small 3165513SMichael.Adler@intel.com return -ERANGE; 3175513SMichael.Adler@intel.com } 3185513SMichael.Adler@intel.com strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 3195513SMichael.Adler@intel.com result = cwd.length(); 3205513SMichael.Adler@intel.com } 3215513SMichael.Adler@intel.com else { 3225513SMichael.Adler@intel.com if (getcwd((char *)buf.bufferPtr(), size) != NULL) { 3235513SMichael.Adler@intel.com result = strlen((char *)buf.bufferPtr()); 3245513SMichael.Adler@intel.com } 3255513SMichael.Adler@intel.com else { 3265513SMichael.Adler@intel.com result = -1; 3275513SMichael.Adler@intel.com } 3285513SMichael.Adler@intel.com } 3295513SMichael.Adler@intel.com 3305513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3315513SMichael.Adler@intel.com 3325513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3335513SMichael.Adler@intel.com} 3345513SMichael.Adler@intel.com 3355513SMichael.Adler@intel.com 3365513SMichael.Adler@intel.comSyscallReturn 3375513SMichael.Adler@intel.comreadlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3385513SMichael.Adler@intel.com{ 3395513SMichael.Adler@intel.com string path; 3405513SMichael.Adler@intel.com 3416701Sgblack@eecs.umich.edu int index = 0; 3426701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3435513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3445513SMichael.Adler@intel.com 3455513SMichael.Adler@intel.com // Adjust path for current working directory 3465513SMichael.Adler@intel.com path = p->fullPath(path); 3475513SMichael.Adler@intel.com 3486701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3496701Sgblack@eecs.umich.edu size_t bufsiz = p->getSyscallArg(tc, index); 3506701Sgblack@eecs.umich.edu 3516701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, bufsiz); 3525513SMichael.Adler@intel.com 3535513SMichael.Adler@intel.com int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 3545513SMichael.Adler@intel.com 3555513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3565513SMichael.Adler@intel.com 3575513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3585513SMichael.Adler@intel.com} 3595513SMichael.Adler@intel.com 3605513SMichael.Adler@intel.comSyscallReturn 3613114Sgblack@eecs.umich.eduunlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 362511SN/A{ 3631706SN/A string path; 364360SN/A 3656701Sgblack@eecs.umich.edu int index = 0; 3666701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3671450SN/A return (TheISA::IntReg)-EFAULT; 368511SN/A 3693669Sbinkertn@umich.edu // Adjust path for current working directory 3703669Sbinkertn@umich.edu path = p->fullPath(path); 3713669Sbinkertn@umich.edu 372511SN/A int result = unlink(path.c_str()); 3731458SN/A return (result == -1) ? -errno : result; 374511SN/A} 375511SN/A 3765513SMichael.Adler@intel.com 3775513SMichael.Adler@intel.comSyscallReturn 3785513SMichael.Adler@intel.commkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3795513SMichael.Adler@intel.com{ 3805513SMichael.Adler@intel.com string path; 3815513SMichael.Adler@intel.com 3826701Sgblack@eecs.umich.edu int index = 0; 3836701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3845513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3855513SMichael.Adler@intel.com 3865513SMichael.Adler@intel.com // Adjust path for current working directory 3875513SMichael.Adler@intel.com path = p->fullPath(path); 3885513SMichael.Adler@intel.com 3896701Sgblack@eecs.umich.edu mode_t mode = p->getSyscallArg(tc, index); 3905513SMichael.Adler@intel.com 3915513SMichael.Adler@intel.com int result = mkdir(path.c_str(), mode); 3925513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3935513SMichael.Adler@intel.com} 3945513SMichael.Adler@intel.com 3951450SN/ASyscallReturn 3963114Sgblack@eecs.umich.edurenameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 397511SN/A{ 3981706SN/A string old_name; 399511SN/A 4006701Sgblack@eecs.umich.edu int index = 0; 4016701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index))) 4021458SN/A return -EFAULT; 403511SN/A 4041706SN/A string new_name; 405511SN/A 4066701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index))) 4071458SN/A return -EFAULT; 408511SN/A 4093669Sbinkertn@umich.edu // Adjust path for current working directory 4103669Sbinkertn@umich.edu old_name = p->fullPath(old_name); 4113669Sbinkertn@umich.edu new_name = p->fullPath(new_name); 4123669Sbinkertn@umich.edu 4131706SN/A int64_t result = rename(old_name.c_str(), new_name.c_str()); 4141458SN/A return (result == -1) ? -errno : result; 415511SN/A} 416511SN/A 4171706SN/ASyscallReturn 4183114Sgblack@eecs.umich.edutruncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4191706SN/A{ 4201706SN/A string path; 4211706SN/A 4226701Sgblack@eecs.umich.edu int index = 0; 4236701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4241706SN/A return -EFAULT; 4251706SN/A 4266701Sgblack@eecs.umich.edu off_t length = p->getSyscallArg(tc, index); 4271706SN/A 4283669Sbinkertn@umich.edu // Adjust path for current working directory 4293669Sbinkertn@umich.edu path = p->fullPath(path); 4303669Sbinkertn@umich.edu 4311706SN/A int result = truncate(path.c_str(), length); 4321706SN/A return (result == -1) ? -errno : result; 4331706SN/A} 4341706SN/A 4351706SN/ASyscallReturn 4366111Ssteve.reinhardt@amd.comftruncateFunc(SyscallDesc *desc, int num, 4376111Ssteve.reinhardt@amd.com LiveProcess *process, ThreadContext *tc) 4381706SN/A{ 4396701Sgblack@eecs.umich.edu int index = 0; 4406701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4411706SN/A 4421706SN/A if (fd < 0) 4431706SN/A return -EBADF; 4441706SN/A 4456701Sgblack@eecs.umich.edu off_t length = process->getSyscallArg(tc, index); 4461706SN/A 4471706SN/A int result = ftruncate(fd, length); 4481706SN/A return (result == -1) ? -errno : result; 4491706SN/A} 4501999SN/A 4511999SN/ASyscallReturn 4526685Stjones1@inf.ed.ac.ukftruncate64Func(SyscallDesc *desc, int num, 4536685Stjones1@inf.ed.ac.uk LiveProcess *process, ThreadContext *tc) 4546685Stjones1@inf.ed.ac.uk{ 4556701Sgblack@eecs.umich.edu int index = 0; 4566701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4576685Stjones1@inf.ed.ac.uk 4586685Stjones1@inf.ed.ac.uk if (fd < 0) 4596685Stjones1@inf.ed.ac.uk return -EBADF; 4606685Stjones1@inf.ed.ac.uk 4616701Sgblack@eecs.umich.edu loff_t length = process->getSyscallArg(tc, index, 64); 4626685Stjones1@inf.ed.ac.uk 4636685Stjones1@inf.ed.ac.uk int result = ftruncate64(fd, length); 4646685Stjones1@inf.ed.ac.uk return (result == -1) ? -errno : result; 4656685Stjones1@inf.ed.ac.uk} 4666685Stjones1@inf.ed.ac.uk 4676685Stjones1@inf.ed.ac.ukSyscallReturn 4685513SMichael.Adler@intel.comumaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 4695513SMichael.Adler@intel.com{ 4705513SMichael.Adler@intel.com // Letting the simulated program change the simulator's umask seems like 4715513SMichael.Adler@intel.com // a bad idea. Compromise by just returning the current umask but not 4725513SMichael.Adler@intel.com // changing anything. 4735513SMichael.Adler@intel.com mode_t oldMask = umask(0); 4745513SMichael.Adler@intel.com umask(oldMask); 4755521Snate@binkert.org return (int)oldMask; 4765513SMichael.Adler@intel.com} 4775513SMichael.Adler@intel.com 4785513SMichael.Adler@intel.comSyscallReturn 4793114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4801999SN/A{ 4811999SN/A string path; 4821999SN/A 4836701Sgblack@eecs.umich.edu int index = 0; 4846701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4851999SN/A return -EFAULT; 4861999SN/A 4871999SN/A /* XXX endianess */ 4886701Sgblack@eecs.umich.edu uint32_t owner = p->getSyscallArg(tc, index); 4891999SN/A uid_t hostOwner = owner; 4906701Sgblack@eecs.umich.edu uint32_t group = p->getSyscallArg(tc, index); 4911999SN/A gid_t hostGroup = group; 4921999SN/A 4933669Sbinkertn@umich.edu // Adjust path for current working directory 4943669Sbinkertn@umich.edu path = p->fullPath(path); 4953669Sbinkertn@umich.edu 4961999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 4971999SN/A return (result == -1) ? -errno : result; 4981999SN/A} 4991999SN/A 5001999SN/ASyscallReturn 5013114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5021999SN/A{ 5036701Sgblack@eecs.umich.edu int index = 0; 5046701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5051999SN/A 5061999SN/A if (fd < 0) 5071999SN/A return -EBADF; 5081999SN/A 5091999SN/A /* XXX endianess */ 5106701Sgblack@eecs.umich.edu uint32_t owner = process->getSyscallArg(tc, index); 5111999SN/A uid_t hostOwner = owner; 5126701Sgblack@eecs.umich.edu uint32_t group = process->getSyscallArg(tc, index); 5131999SN/A gid_t hostGroup = group; 5141999SN/A 5151999SN/A int result = fchown(fd, hostOwner, hostGroup); 5161999SN/A return (result == -1) ? -errno : result; 5171999SN/A} 5182093SN/A 5192093SN/A 5202093SN/ASyscallReturn 5213114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5223079Sstever@eecs.umich.edu{ 5236701Sgblack@eecs.umich.edu int index = 0; 5246701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5253079Sstever@eecs.umich.edu if (fd < 0) 5263079Sstever@eecs.umich.edu return -EBADF; 5273079Sstever@eecs.umich.edu 5286701Sgblack@eecs.umich.edu Process::FdMap *fdo = process->sim_fd_obj(fd); 5295282Srstrong@cs.ucsd.edu 5303079Sstever@eecs.umich.edu int result = dup(fd); 5316111Ssteve.reinhardt@amd.com return (result == -1) ? -errno : 5326111Ssteve.reinhardt@amd.com process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); 5333079Sstever@eecs.umich.edu} 5343079Sstever@eecs.umich.edu 5353079Sstever@eecs.umich.edu 5363079Sstever@eecs.umich.eduSyscallReturn 5373114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 5382680Sktlim@umich.edu ThreadContext *tc) 5392093SN/A{ 5406701Sgblack@eecs.umich.edu int index = 0; 5416701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5422093SN/A 5432093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 5442093SN/A return -EBADF; 5452093SN/A 5466701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5472093SN/A switch (cmd) { 5482093SN/A case 0: // F_DUPFD 5492093SN/A // if we really wanted to support this, we'd need to do it 5502093SN/A // in the target fd space. 5512093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 5522093SN/A return -EMFILE; 5532093SN/A 5542093SN/A case 1: // F_GETFD (get close-on-exec flag) 5552093SN/A case 2: // F_SETFD (set close-on-exec flag) 5562093SN/A return 0; 5572093SN/A 5582093SN/A case 3: // F_GETFL (get file flags) 5592093SN/A case 4: // F_SETFL (set file flags) 5602093SN/A // not sure if this is totally valid, but we'll pass it through 5612093SN/A // to the underlying OS 5622093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 5632093SN/A return fcntl(process->sim_fd(fd), cmd); 5642093SN/A // return 0; 5652093SN/A 5662093SN/A case 7: // F_GETLK (get lock) 5672093SN/A case 8: // F_SETLK (set lock) 5682093SN/A case 9: // F_SETLKW (set lock and wait) 5692093SN/A // don't mess with file locking... just act like it's OK 5702093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 5712093SN/A return 0; 5722093SN/A 5732093SN/A default: 5742093SN/A warn("Unknown fcntl command %d\n", cmd); 5752093SN/A return 0; 5762093SN/A } 5772093SN/A} 5782093SN/A 5792238SN/ASyscallReturn 5803114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 5812687Sksewell@umich.edu ThreadContext *tc) 5822687Sksewell@umich.edu{ 5836701Sgblack@eecs.umich.edu int index = 0; 5846701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5852687Sksewell@umich.edu 5862687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 5872687Sksewell@umich.edu return -EBADF; 5882687Sksewell@umich.edu 5896701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5902687Sksewell@umich.edu switch (cmd) { 5912687Sksewell@umich.edu case 33: //F_GETLK64 5922687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 5932687Sksewell@umich.edu return -EMFILE; 5942687Sksewell@umich.edu 5952687Sksewell@umich.edu case 34: // F_SETLK64 5962687Sksewell@umich.edu case 35: // F_SETLKW64 5972687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 5982687Sksewell@umich.edu return -EMFILE; 5992687Sksewell@umich.edu 6002687Sksewell@umich.edu default: 6012687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 6022687Sksewell@umich.edu // to the underlying OS 6032687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 6042687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 6052687Sksewell@umich.edu // return 0; 6062687Sksewell@umich.edu } 6072687Sksewell@umich.edu} 6082687Sksewell@umich.edu 6092687Sksewell@umich.eduSyscallReturn 6103114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6112680Sktlim@umich.edu ThreadContext *tc) 6122238SN/A{ 6132238SN/A int fds[2], sim_fds[2]; 6142238SN/A int pipe_retval = pipe(fds); 6152093SN/A 6162238SN/A if (pipe_retval < 0) { 6172238SN/A // error 6182238SN/A return pipe_retval; 6192238SN/A } 6202238SN/A 6215282Srstrong@cs.ucsd.edu sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 6225282Srstrong@cs.ucsd.edu sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); 6232238SN/A 6245282Srstrong@cs.ucsd.edu process->setReadPipeSource(sim_fds[0], sim_fds[1]); 6252238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 6262238SN/A // the return value of the function, and fd[1] is returned in r20. 6272680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 6282238SN/A return sim_fds[0]; 6292238SN/A} 6302238SN/A 6312238SN/A 6322238SN/ASyscallReturn 6333114Sgblack@eecs.umich.edugetpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6342680Sktlim@umich.edu ThreadContext *tc) 6352238SN/A{ 6362238SN/A // Make up a PID. There's no interprocess communication in 6372238SN/A // fake_syscall mode, so there's no way for a process to know it's 6382238SN/A // not getting a unique value. 6392238SN/A 6403114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 6413114Sgblack@eecs.umich.edu return process->pid(); 6422238SN/A} 6432238SN/A 6442238SN/A 6452238SN/ASyscallReturn 6463114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6472680Sktlim@umich.edu ThreadContext *tc) 6482238SN/A{ 6492238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 6502238SN/A // simulation to be deterministic. 6512238SN/A 6522238SN/A // EUID goes in r20. 6533114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 6545543Ssaidi@eecs.umich.edu return process->uid(); // UID 6552238SN/A} 6562238SN/A 6572238SN/A 6582238SN/ASyscallReturn 6593114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6602680Sktlim@umich.edu ThreadContext *tc) 6612238SN/A{ 6622238SN/A // Get current group ID. EGID goes in r20. 6633114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 6643114Sgblack@eecs.umich.edu return process->gid(); 6652238SN/A} 6662238SN/A 6672238SN/A 6682238SN/ASyscallReturn 6693114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6702680Sktlim@umich.edu ThreadContext *tc) 6712238SN/A{ 6722238SN/A // can't fathom why a benchmark would call this. 6736701Sgblack@eecs.umich.edu int index = 0; 6746701Sgblack@eecs.umich.edu warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 6752238SN/A return 0; 6762238SN/A} 6772238SN/A 6782238SN/ASyscallReturn 6793114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6802680Sktlim@umich.edu ThreadContext *tc) 6812238SN/A{ 6822238SN/A // Make up a PID. There's no interprocess communication in 6832238SN/A // fake_syscall mode, so there's no way for a process to know it's 6842238SN/A // not getting a unique value. 6852238SN/A 6863114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 6873114Sgblack@eecs.umich.edu return process->pid(); 6882238SN/A} 6892238SN/A 6902238SN/ASyscallReturn 6913114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6922680Sktlim@umich.edu ThreadContext *tc) 6932238SN/A{ 6943114Sgblack@eecs.umich.edu return process->ppid(); 6952238SN/A} 6962238SN/A 6972238SN/ASyscallReturn 6983114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6992680Sktlim@umich.edu ThreadContext *tc) 7002238SN/A{ 7015543Ssaidi@eecs.umich.edu return process->uid(); // UID 7022238SN/A} 7032238SN/A 7042238SN/ASyscallReturn 7053114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7062680Sktlim@umich.edu ThreadContext *tc) 7072238SN/A{ 7085543Ssaidi@eecs.umich.edu return process->euid(); // UID 7092238SN/A} 7102238SN/A 7112238SN/ASyscallReturn 7123114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7132680Sktlim@umich.edu ThreadContext *tc) 7142238SN/A{ 7153114Sgblack@eecs.umich.edu return process->gid(); 7162238SN/A} 7172238SN/A 7182238SN/ASyscallReturn 7193114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7202680Sktlim@umich.edu ThreadContext *tc) 7212238SN/A{ 7223114Sgblack@eecs.umich.edu return process->egid(); 7232238SN/A} 7242238SN/A 7252238SN/A 7266109Ssanchezd@stanford.eduSyscallReturn 7276109Ssanchezd@stanford.educloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7286109Ssanchezd@stanford.edu ThreadContext *tc) 7296109Ssanchezd@stanford.edu{ 7306701Sgblack@eecs.umich.edu int index = 0; 7316701Sgblack@eecs.umich.edu IntReg flags = process->getSyscallArg(tc, index); 7326701Sgblack@eecs.umich.edu IntReg newStack = process->getSyscallArg(tc, index); 7336701Sgblack@eecs.umich.edu 7346109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, "In sys_clone:\n"); 7356701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 7366701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); 7376109Ssanchezd@stanford.edu 7386109Ssanchezd@stanford.edu 7396701Sgblack@eecs.umich.edu if (flags != 0x10f00) { 7406111Ssteve.reinhardt@amd.com warn("This sys_clone implementation assumes flags " 7416111Ssteve.reinhardt@amd.com "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD " 7426111Ssteve.reinhardt@amd.com "(0x10f00), and may not work correctly with given flags " 7436701Sgblack@eecs.umich.edu "0x%llx\n", flags); 7446109Ssanchezd@stanford.edu } 7456109Ssanchezd@stanford.edu 7466111Ssteve.reinhardt@amd.com ThreadContext* ctc; // child thread context 7476109Ssanchezd@stanford.edu if ( ( ctc = process->findFreeContext() ) != NULL ) { 7486109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, " Found unallocated thread context\n"); 7496109Ssanchezd@stanford.edu 7506109Ssanchezd@stanford.edu ctc->clearArchRegs(); 7516109Ssanchezd@stanford.edu 7526111Ssteve.reinhardt@amd.com // Arch-specific cloning code 7536109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA 7546111Ssteve.reinhardt@amd.com // Cloning the misc. regs for these archs is enough 7556109Ssanchezd@stanford.edu TheISA::copyMiscRegs(tc, ctc); 7566109Ssanchezd@stanford.edu #elif THE_ISA == SPARC_ISA 7576109Ssanchezd@stanford.edu TheISA::copyRegs(tc, ctc); 7586109Ssanchezd@stanford.edu 7596111Ssteve.reinhardt@amd.com // TODO: Explain what this code actually does :-) 7606109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 6, 0); 7616109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 4, 0); 7626109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2); 7636109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 5, NWindows); 7646337Sgblack@eecs.umich.edu ctc->setMiscReg(MISCREG_CWP, 0); 7656109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 7, 0); 7666109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_TL, 0); 7676109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY); 7686109Ssanchezd@stanford.edu 7696109Ssanchezd@stanford.edu for (int y = 8; y < 32; y++) 7706109Ssanchezd@stanford.edu ctc->setIntReg(y, tc->readIntReg(y)); 7716109Ssanchezd@stanford.edu #else 7726109Ssanchezd@stanford.edu fatal("sys_clone is not implemented for this ISA\n"); 7736109Ssanchezd@stanford.edu #endif 7746109Ssanchezd@stanford.edu 7756111Ssteve.reinhardt@amd.com // Set up stack register 7766701Sgblack@eecs.umich.edu ctc->setIntReg(TheISA::StackPointerReg, newStack); 7776109Ssanchezd@stanford.edu 7786111Ssteve.reinhardt@amd.com // Set up syscall return values in parent and child 7796111Ssteve.reinhardt@amd.com ctc->setIntReg(ReturnValueReg, 0); // return value, child 7806109Ssanchezd@stanford.edu 7816111Ssteve.reinhardt@amd.com // Alpha needs SyscallSuccessReg=0 in child 7826109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA 7836110Ssteve.reinhardt@amd.com ctc->setIntReg(TheISA::SyscallSuccessReg, 0); 7846109Ssanchezd@stanford.edu #endif 7856109Ssanchezd@stanford.edu 7866111Ssteve.reinhardt@amd.com // In SPARC/Linux, clone returns 0 on pseudo-return register if 7876111Ssteve.reinhardt@amd.com // parent, non-zero if child 7886109Ssanchezd@stanford.edu #if THE_ISA == SPARC_ISA 7896109Ssanchezd@stanford.edu tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0); 7906109Ssanchezd@stanford.edu ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1); 7916109Ssanchezd@stanford.edu #endif 7926109Ssanchezd@stanford.edu 7936109Ssanchezd@stanford.edu ctc->setPC(tc->readNextPC()); 7946109Ssanchezd@stanford.edu ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst)); 7956134Sgblack@eecs.umich.edu ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst)); 7966109Ssanchezd@stanford.edu 7976109Ssanchezd@stanford.edu ctc->activate(); 7986109Ssanchezd@stanford.edu 7996109Ssanchezd@stanford.edu // Should return nonzero child TID in parent's syscall return register, 8006109Ssanchezd@stanford.edu // but for our pthread library any non-zero value will work 8016109Ssanchezd@stanford.edu return 1; 8026109Ssanchezd@stanford.edu } else { 8036109Ssanchezd@stanford.edu fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 8046109Ssanchezd@stanford.edu return 0; 8056109Ssanchezd@stanford.edu } 8066109Ssanchezd@stanford.edu} 8076109Ssanchezd@stanford.edu 808