syscall_emul.cc revision 6702
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 4546685Stjones1@inf.ed.ac.ukftruncate64Func(SyscallDesc *desc, int num, 4556685Stjones1@inf.ed.ac.uk LiveProcess *process, ThreadContext *tc) 4566685Stjones1@inf.ed.ac.uk{ 4576701Sgblack@eecs.umich.edu int index = 0; 4586701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4596685Stjones1@inf.ed.ac.uk 4606685Stjones1@inf.ed.ac.uk if (fd < 0) 4616685Stjones1@inf.ed.ac.uk return -EBADF; 4626685Stjones1@inf.ed.ac.uk 4636701Sgblack@eecs.umich.edu loff_t length = process->getSyscallArg(tc, index, 64); 4646685Stjones1@inf.ed.ac.uk 4656685Stjones1@inf.ed.ac.uk int result = ftruncate64(fd, length); 4666685Stjones1@inf.ed.ac.uk return (result == -1) ? -errno : result; 4676685Stjones1@inf.ed.ac.uk} 4686685Stjones1@inf.ed.ac.uk 4696685Stjones1@inf.ed.ac.ukSyscallReturn 4705513SMichael.Adler@intel.comumaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 4715513SMichael.Adler@intel.com{ 4725513SMichael.Adler@intel.com // Letting the simulated program change the simulator's umask seems like 4735513SMichael.Adler@intel.com // a bad idea. Compromise by just returning the current umask but not 4745513SMichael.Adler@intel.com // changing anything. 4755513SMichael.Adler@intel.com mode_t oldMask = umask(0); 4765513SMichael.Adler@intel.com umask(oldMask); 4775521Snate@binkert.org return (int)oldMask; 4785513SMichael.Adler@intel.com} 4795513SMichael.Adler@intel.com 4805513SMichael.Adler@intel.comSyscallReturn 4813114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4821999SN/A{ 4831999SN/A string path; 4841999SN/A 4856701Sgblack@eecs.umich.edu int index = 0; 4866701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4871999SN/A return -EFAULT; 4881999SN/A 4891999SN/A /* XXX endianess */ 4906701Sgblack@eecs.umich.edu uint32_t owner = p->getSyscallArg(tc, index); 4911999SN/A uid_t hostOwner = owner; 4926701Sgblack@eecs.umich.edu uint32_t group = p->getSyscallArg(tc, index); 4931999SN/A gid_t hostGroup = group; 4941999SN/A 4953669Sbinkertn@umich.edu // Adjust path for current working directory 4963669Sbinkertn@umich.edu path = p->fullPath(path); 4973669Sbinkertn@umich.edu 4981999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 4991999SN/A return (result == -1) ? -errno : result; 5001999SN/A} 5011999SN/A 5021999SN/ASyscallReturn 5033114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5041999SN/A{ 5056701Sgblack@eecs.umich.edu int index = 0; 5066701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5071999SN/A 5081999SN/A if (fd < 0) 5091999SN/A return -EBADF; 5101999SN/A 5111999SN/A /* XXX endianess */ 5126701Sgblack@eecs.umich.edu uint32_t owner = process->getSyscallArg(tc, index); 5131999SN/A uid_t hostOwner = owner; 5146701Sgblack@eecs.umich.edu uint32_t group = process->getSyscallArg(tc, index); 5151999SN/A gid_t hostGroup = group; 5161999SN/A 5171999SN/A int result = fchown(fd, hostOwner, hostGroup); 5181999SN/A return (result == -1) ? -errno : result; 5191999SN/A} 5202093SN/A 5212093SN/A 5222093SN/ASyscallReturn 5233114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5243079Sstever@eecs.umich.edu{ 5256701Sgblack@eecs.umich.edu int index = 0; 5266701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5273079Sstever@eecs.umich.edu if (fd < 0) 5283079Sstever@eecs.umich.edu return -EBADF; 5293079Sstever@eecs.umich.edu 5306701Sgblack@eecs.umich.edu Process::FdMap *fdo = process->sim_fd_obj(fd); 5315282Srstrong@cs.ucsd.edu 5323079Sstever@eecs.umich.edu int result = dup(fd); 5336111Ssteve.reinhardt@amd.com return (result == -1) ? -errno : 5346111Ssteve.reinhardt@amd.com process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); 5353079Sstever@eecs.umich.edu} 5363079Sstever@eecs.umich.edu 5373079Sstever@eecs.umich.edu 5383079Sstever@eecs.umich.eduSyscallReturn 5393114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 5402680Sktlim@umich.edu ThreadContext *tc) 5412093SN/A{ 5426701Sgblack@eecs.umich.edu int index = 0; 5436701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5442093SN/A 5452093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 5462093SN/A return -EBADF; 5472093SN/A 5486701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5492093SN/A switch (cmd) { 5502093SN/A case 0: // F_DUPFD 5512093SN/A // if we really wanted to support this, we'd need to do it 5522093SN/A // in the target fd space. 5532093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 5542093SN/A return -EMFILE; 5552093SN/A 5562093SN/A case 1: // F_GETFD (get close-on-exec flag) 5572093SN/A case 2: // F_SETFD (set close-on-exec flag) 5582093SN/A return 0; 5592093SN/A 5602093SN/A case 3: // F_GETFL (get file flags) 5612093SN/A case 4: // F_SETFL (set file flags) 5622093SN/A // not sure if this is totally valid, but we'll pass it through 5632093SN/A // to the underlying OS 5642093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 5652093SN/A return fcntl(process->sim_fd(fd), cmd); 5662093SN/A // return 0; 5672093SN/A 5682093SN/A case 7: // F_GETLK (get lock) 5692093SN/A case 8: // F_SETLK (set lock) 5702093SN/A case 9: // F_SETLKW (set lock and wait) 5712093SN/A // don't mess with file locking... just act like it's OK 5722093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 5732093SN/A return 0; 5742093SN/A 5752093SN/A default: 5762093SN/A warn("Unknown fcntl command %d\n", cmd); 5772093SN/A return 0; 5782093SN/A } 5792093SN/A} 5802093SN/A 5812238SN/ASyscallReturn 5823114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 5832687Sksewell@umich.edu ThreadContext *tc) 5842687Sksewell@umich.edu{ 5856701Sgblack@eecs.umich.edu int index = 0; 5866701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5872687Sksewell@umich.edu 5882687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 5892687Sksewell@umich.edu return -EBADF; 5902687Sksewell@umich.edu 5916701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5922687Sksewell@umich.edu switch (cmd) { 5932687Sksewell@umich.edu case 33: //F_GETLK64 5942687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 5952687Sksewell@umich.edu return -EMFILE; 5962687Sksewell@umich.edu 5972687Sksewell@umich.edu case 34: // F_SETLK64 5982687Sksewell@umich.edu case 35: // F_SETLKW64 5992687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 6002687Sksewell@umich.edu return -EMFILE; 6012687Sksewell@umich.edu 6022687Sksewell@umich.edu default: 6032687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 6042687Sksewell@umich.edu // to the underlying OS 6052687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 6062687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 6072687Sksewell@umich.edu // return 0; 6082687Sksewell@umich.edu } 6092687Sksewell@umich.edu} 6102687Sksewell@umich.edu 6112687Sksewell@umich.eduSyscallReturn 6123114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6132680Sktlim@umich.edu ThreadContext *tc) 6142238SN/A{ 6152238SN/A int fds[2], sim_fds[2]; 6162238SN/A int pipe_retval = pipe(fds); 6172093SN/A 6182238SN/A if (pipe_retval < 0) { 6192238SN/A // error 6202238SN/A return pipe_retval; 6212238SN/A } 6222238SN/A 6235282Srstrong@cs.ucsd.edu sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 6245282Srstrong@cs.ucsd.edu sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); 6252238SN/A 6265282Srstrong@cs.ucsd.edu process->setReadPipeSource(sim_fds[0], sim_fds[1]); 6272238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 6282238SN/A // the return value of the function, and fd[1] is returned in r20. 6292680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 6302238SN/A return sim_fds[0]; 6312238SN/A} 6322238SN/A 6332238SN/A 6342238SN/ASyscallReturn 6353114Sgblack@eecs.umich.edugetpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6362680Sktlim@umich.edu ThreadContext *tc) 6372238SN/A{ 6382238SN/A // Make up a PID. There's no interprocess communication in 6392238SN/A // fake_syscall mode, so there's no way for a process to know it's 6402238SN/A // not getting a unique value. 6412238SN/A 6423114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 6433114Sgblack@eecs.umich.edu return process->pid(); 6442238SN/A} 6452238SN/A 6462238SN/A 6472238SN/ASyscallReturn 6483114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6492680Sktlim@umich.edu ThreadContext *tc) 6502238SN/A{ 6512238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 6522238SN/A // simulation to be deterministic. 6532238SN/A 6542238SN/A // EUID goes in r20. 6553114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 6565543Ssaidi@eecs.umich.edu return process->uid(); // UID 6572238SN/A} 6582238SN/A 6592238SN/A 6602238SN/ASyscallReturn 6613114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6622680Sktlim@umich.edu ThreadContext *tc) 6632238SN/A{ 6642238SN/A // Get current group ID. EGID goes in r20. 6653114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 6663114Sgblack@eecs.umich.edu return process->gid(); 6672238SN/A} 6682238SN/A 6692238SN/A 6702238SN/ASyscallReturn 6713114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6722680Sktlim@umich.edu ThreadContext *tc) 6732238SN/A{ 6742238SN/A // can't fathom why a benchmark would call this. 6756701Sgblack@eecs.umich.edu int index = 0; 6766701Sgblack@eecs.umich.edu warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 6772238SN/A return 0; 6782238SN/A} 6792238SN/A 6802238SN/ASyscallReturn 6813114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6822680Sktlim@umich.edu ThreadContext *tc) 6832238SN/A{ 6842238SN/A // Make up a PID. There's no interprocess communication in 6852238SN/A // fake_syscall mode, so there's no way for a process to know it's 6862238SN/A // not getting a unique value. 6872238SN/A 6883114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 6893114Sgblack@eecs.umich.edu return process->pid(); 6902238SN/A} 6912238SN/A 6922238SN/ASyscallReturn 6933114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6942680Sktlim@umich.edu ThreadContext *tc) 6952238SN/A{ 6963114Sgblack@eecs.umich.edu return process->ppid(); 6972238SN/A} 6982238SN/A 6992238SN/ASyscallReturn 7003114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7012680Sktlim@umich.edu ThreadContext *tc) 7022238SN/A{ 7035543Ssaidi@eecs.umich.edu return process->uid(); // UID 7042238SN/A} 7052238SN/A 7062238SN/ASyscallReturn 7073114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7082680Sktlim@umich.edu ThreadContext *tc) 7092238SN/A{ 7105543Ssaidi@eecs.umich.edu return process->euid(); // UID 7112238SN/A} 7122238SN/A 7132238SN/ASyscallReturn 7143114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7152680Sktlim@umich.edu ThreadContext *tc) 7162238SN/A{ 7173114Sgblack@eecs.umich.edu return process->gid(); 7182238SN/A} 7192238SN/A 7202238SN/ASyscallReturn 7213114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7222680Sktlim@umich.edu ThreadContext *tc) 7232238SN/A{ 7243114Sgblack@eecs.umich.edu return process->egid(); 7252238SN/A} 7262238SN/A 7272238SN/A 7286109Ssanchezd@stanford.eduSyscallReturn 7296109Ssanchezd@stanford.educloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7306109Ssanchezd@stanford.edu ThreadContext *tc) 7316109Ssanchezd@stanford.edu{ 7326701Sgblack@eecs.umich.edu int index = 0; 7336701Sgblack@eecs.umich.edu IntReg flags = process->getSyscallArg(tc, index); 7346701Sgblack@eecs.umich.edu IntReg newStack = process->getSyscallArg(tc, index); 7356701Sgblack@eecs.umich.edu 7366109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, "In sys_clone:\n"); 7376701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 7386701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); 7396109Ssanchezd@stanford.edu 7406109Ssanchezd@stanford.edu 7416701Sgblack@eecs.umich.edu if (flags != 0x10f00) { 7426111Ssteve.reinhardt@amd.com warn("This sys_clone implementation assumes flags " 7436111Ssteve.reinhardt@amd.com "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD " 7446111Ssteve.reinhardt@amd.com "(0x10f00), and may not work correctly with given flags " 7456701Sgblack@eecs.umich.edu "0x%llx\n", flags); 7466109Ssanchezd@stanford.edu } 7476109Ssanchezd@stanford.edu 7486111Ssteve.reinhardt@amd.com ThreadContext* ctc; // child thread context 7496109Ssanchezd@stanford.edu if ( ( ctc = process->findFreeContext() ) != NULL ) { 7506109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, " Found unallocated thread context\n"); 7516109Ssanchezd@stanford.edu 7526109Ssanchezd@stanford.edu ctc->clearArchRegs(); 7536109Ssanchezd@stanford.edu 7546111Ssteve.reinhardt@amd.com // Arch-specific cloning code 7556109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA 7566111Ssteve.reinhardt@amd.com // Cloning the misc. regs for these archs is enough 7576109Ssanchezd@stanford.edu TheISA::copyMiscRegs(tc, ctc); 7586109Ssanchezd@stanford.edu #elif THE_ISA == SPARC_ISA 7596109Ssanchezd@stanford.edu TheISA::copyRegs(tc, ctc); 7606109Ssanchezd@stanford.edu 7616111Ssteve.reinhardt@amd.com // TODO: Explain what this code actually does :-) 7626109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 6, 0); 7636109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 4, 0); 7646109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2); 7656109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 5, NWindows); 7666337Sgblack@eecs.umich.edu ctc->setMiscReg(MISCREG_CWP, 0); 7676109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 7, 0); 7686109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_TL, 0); 7696109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY); 7706109Ssanchezd@stanford.edu 7716109Ssanchezd@stanford.edu for (int y = 8; y < 32; y++) 7726109Ssanchezd@stanford.edu ctc->setIntReg(y, tc->readIntReg(y)); 7736109Ssanchezd@stanford.edu #else 7746109Ssanchezd@stanford.edu fatal("sys_clone is not implemented for this ISA\n"); 7756109Ssanchezd@stanford.edu #endif 7766109Ssanchezd@stanford.edu 7776111Ssteve.reinhardt@amd.com // Set up stack register 7786701Sgblack@eecs.umich.edu ctc->setIntReg(TheISA::StackPointerReg, newStack); 7796109Ssanchezd@stanford.edu 7806111Ssteve.reinhardt@amd.com // Set up syscall return values in parent and child 7816111Ssteve.reinhardt@amd.com ctc->setIntReg(ReturnValueReg, 0); // return value, child 7826109Ssanchezd@stanford.edu 7836111Ssteve.reinhardt@amd.com // Alpha needs SyscallSuccessReg=0 in child 7846109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA 7856110Ssteve.reinhardt@amd.com ctc->setIntReg(TheISA::SyscallSuccessReg, 0); 7866109Ssanchezd@stanford.edu #endif 7876109Ssanchezd@stanford.edu 7886111Ssteve.reinhardt@amd.com // In SPARC/Linux, clone returns 0 on pseudo-return register if 7896111Ssteve.reinhardt@amd.com // parent, non-zero if child 7906109Ssanchezd@stanford.edu #if THE_ISA == SPARC_ISA 7916109Ssanchezd@stanford.edu tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0); 7926109Ssanchezd@stanford.edu ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1); 7936109Ssanchezd@stanford.edu #endif 7946109Ssanchezd@stanford.edu 7956109Ssanchezd@stanford.edu ctc->setPC(tc->readNextPC()); 7966109Ssanchezd@stanford.edu ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst)); 7976134Sgblack@eecs.umich.edu ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst)); 7986109Ssanchezd@stanford.edu 7996109Ssanchezd@stanford.edu ctc->activate(); 8006109Ssanchezd@stanford.edu 8016109Ssanchezd@stanford.edu // Should return nonzero child TID in parent's syscall return register, 8026109Ssanchezd@stanford.edu // but for our pthread library any non-zero value will work 8036109Ssanchezd@stanford.edu return 1; 8046109Ssanchezd@stanford.edu } else { 8056109Ssanchezd@stanford.edu fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 8066109Ssanchezd@stanford.edu return 0; 8076109Ssanchezd@stanford.edu } 8086109Ssanchezd@stanford.edu} 8096109Ssanchezd@stanford.edu 810