syscall_emul.cc revision 8601
1360SN/A/* 21458SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 3360SN/A * All rights reserved. 4360SN/A * 5360SN/A * Redistribution and use in source and binary forms, with or without 6360SN/A * modification, are permitted provided that the following conditions are 7360SN/A * met: redistributions of source code must retain the above copyright 8360SN/A * notice, this list of conditions and the following disclaimer; 9360SN/A * redistributions in binary form must reproduce the above copyright 10360SN/A * notice, this list of conditions and the following disclaimer in the 11360SN/A * documentation and/or other materials provided with the distribution; 12360SN/A * neither the name of the copyright holders nor the names of its 13360SN/A * contributors may be used to endorse or promote products derived from 14360SN/A * this software without specific prior written permission. 15360SN/A * 16360SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17360SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18360SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19360SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20360SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21360SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22360SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23360SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24360SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25360SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26360SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Ali Saidi 30360SN/A */ 31360SN/A 322093SN/A#include <fcntl.h> 33360SN/A#include <unistd.h> 34360SN/A 356712Snate@binkert.org#include <cstdio> 366712Snate@binkert.org#include <iostream> 37360SN/A#include <string> 38360SN/A 397680Sgblack@eecs.umich.edu#include "arch/utility.hh" 402474SN/A#include "base/chunk_generator.hh" 41360SN/A#include "base/trace.hh" 426658Snate@binkert.org#include "config/the_isa.hh" 438229Snate@binkert.org#include "cpu/base.hh" 442680Sktlim@umich.edu#include "cpu/thread_context.hh" 458232Snate@binkert.org#include "debug/SyscallVerbose.hh" 462474SN/A#include "mem/page_table.hh" 47360SN/A#include "sim/process.hh" 488229Snate@binkert.org#include "sim/sim_exit.hh" 498229Snate@binkert.org#include "sim/syscall_emul.hh" 506029Ssteve.reinhardt@amd.com#include "sim/system.hh" 51360SN/A 52360SN/Ausing namespace std; 532107SN/Ausing namespace TheISA; 54360SN/A 55360SN/Avoid 563114Sgblack@eecs.umich.eduSyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) 57360SN/A{ 586702Sgblack@eecs.umich.edu#if TRACING_ON 596701Sgblack@eecs.umich.edu int index = 0; 606702Sgblack@eecs.umich.edu#endif 616111Ssteve.reinhardt@amd.com DPRINTFR(SyscallVerbose, 626111Ssteve.reinhardt@amd.com "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", 637823Ssteve.reinhardt@amd.com curTick(), tc->getCpuPtr()->name(), name, 646701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 656701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 666701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), 676701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index)); 68360SN/A 692680Sktlim@umich.edu SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); 70360SN/A 712495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", 727823Ssteve.reinhardt@amd.com curTick(),tc->getCpuPtr()->name(), name, retval.value()); 73360SN/A 741450SN/A if (!(flags & SyscallDesc::SuppressReturnValue)) 755958Sgblack@eecs.umich.edu process->setSyscallReturn(tc, retval); 76360SN/A} 77360SN/A 78360SN/A 791450SN/ASyscallReturn 803114Sgblack@eecs.umich.eduunimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 812680Sktlim@umich.edu ThreadContext *tc) 82360SN/A{ 831969SN/A fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); 842484SN/A 852484SN/A return 1; 86360SN/A} 87360SN/A 88360SN/A 891450SN/ASyscallReturn 903114Sgblack@eecs.umich.eduignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 912680Sktlim@umich.edu ThreadContext *tc) 92360SN/A{ 936701Sgblack@eecs.umich.edu int index = 0; 941969SN/A warn("ignoring syscall %s(%d, %d, ...)", desc->name, 956701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); 96360SN/A 971458SN/A return 0; 98360SN/A} 99360SN/A 100360SN/A 1011450SN/ASyscallReturn 1028149SChris.Emmons@ARM.comignoreWarnOnceFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1038149SChris.Emmons@ARM.com ThreadContext *tc) 1048149SChris.Emmons@ARM.com{ 1058149SChris.Emmons@ARM.com int index = 0; 1068149SChris.Emmons@ARM.com warn_once("ignoring syscall %s(%d, %d, ...)", desc->name, 1078149SChris.Emmons@ARM.com process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); 1088149SChris.Emmons@ARM.com 1098149SChris.Emmons@ARM.com return 0; 1108149SChris.Emmons@ARM.com} 1118149SChris.Emmons@ARM.com 1128149SChris.Emmons@ARM.com 1138149SChris.Emmons@ARM.comSyscallReturn 1143114Sgblack@eecs.umich.eduexitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1152680Sktlim@umich.edu ThreadContext *tc) 116360SN/A{ 1176029Ssteve.reinhardt@amd.com if (process->system->numRunningContexts() == 1) { 1186029Ssteve.reinhardt@amd.com // Last running context... exit simulator 1196701Sgblack@eecs.umich.edu int index = 0; 1205958Sgblack@eecs.umich.edu exitSimLoop("target called exit()", 1216701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1226029Ssteve.reinhardt@amd.com } else { 1236029Ssteve.reinhardt@amd.com // other running threads... just halt this one 1246029Ssteve.reinhardt@amd.com tc->halt(); 1252834Sksewell@umich.edu } 126360SN/A 1271458SN/A return 1; 128360SN/A} 129360SN/A 130360SN/A 1311450SN/ASyscallReturn 1326109Ssanchezd@stanford.eduexitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1336109Ssanchezd@stanford.edu ThreadContext *tc) 1346109Ssanchezd@stanford.edu{ 1356109Ssanchezd@stanford.edu // really should just halt all thread contexts belonging to this 1366109Ssanchezd@stanford.edu // process in case there's another process running... 1376701Sgblack@eecs.umich.edu int index = 0; 1386109Ssanchezd@stanford.edu exitSimLoop("target called exit()", 1396701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index) & 0xff); 1406109Ssanchezd@stanford.edu 1416109Ssanchezd@stanford.edu return 1; 1426109Ssanchezd@stanford.edu} 1436109Ssanchezd@stanford.edu 1446109Ssanchezd@stanford.edu 1456109Ssanchezd@stanford.eduSyscallReturn 1463114Sgblack@eecs.umich.edugetpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 147360SN/A{ 1482107SN/A return (int)VMPageSize; 149360SN/A} 150360SN/A 151360SN/A 1521450SN/ASyscallReturn 1535748SSteve.Reinhardt@amd.combrkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 154360SN/A{ 155360SN/A // change brk addr to first arg 1566701Sgblack@eecs.umich.edu int index = 0; 1576701Sgblack@eecs.umich.edu Addr new_brk = p->getSyscallArg(tc, index); 1585748SSteve.Reinhardt@amd.com 1595748SSteve.Reinhardt@amd.com // in Linux at least, brk(0) returns the current break value 1605748SSteve.Reinhardt@amd.com // (note that the syscall and the glibc function have different behavior) 1615748SSteve.Reinhardt@amd.com if (new_brk == 0) 1625748SSteve.Reinhardt@amd.com return p->brk_point; 1635748SSteve.Reinhardt@amd.com 1645748SSteve.Reinhardt@amd.com if (new_brk > p->brk_point) { 1655748SSteve.Reinhardt@amd.com // might need to allocate some new pages 1662474SN/A for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, 1672474SN/A VMPageSize); !gen.done(); gen.next()) { 1685748SSteve.Reinhardt@amd.com if (!p->pTable->translate(gen.addr())) 1698601Ssteve.reinhardt@amd.com p->allocateMem(roundDown(gen.addr(), VMPageSize), VMPageSize); 1706687Stjones1@inf.ed.ac.uk 1716687Stjones1@inf.ed.ac.uk // if the address is already there, zero it out 1726687Stjones1@inf.ed.ac.uk else { 1736687Stjones1@inf.ed.ac.uk uint8_t zero = 0; 1746687Stjones1@inf.ed.ac.uk TranslatingPort *tp = tc->getMemPort(); 1756687Stjones1@inf.ed.ac.uk 1766687Stjones1@inf.ed.ac.uk // split non-page aligned accesses 1776687Stjones1@inf.ed.ac.uk Addr next_page = roundUp(gen.addr(), VMPageSize); 1786687Stjones1@inf.ed.ac.uk uint32_t size_needed = next_page - gen.addr(); 1796687Stjones1@inf.ed.ac.uk tp->memsetBlob(gen.addr(), zero, size_needed); 1806687Stjones1@inf.ed.ac.uk if (gen.addr() + VMPageSize > next_page && 1816687Stjones1@inf.ed.ac.uk next_page < new_brk && 1826687Stjones1@inf.ed.ac.uk p->pTable->translate(next_page)) 1836687Stjones1@inf.ed.ac.uk { 1846687Stjones1@inf.ed.ac.uk size_needed = VMPageSize - size_needed; 1856687Stjones1@inf.ed.ac.uk tp->memsetBlob(next_page, zero, size_needed); 1866687Stjones1@inf.ed.ac.uk } 1876687Stjones1@inf.ed.ac.uk } 1882474SN/A } 1891450SN/A } 1905748SSteve.Reinhardt@amd.com 1915748SSteve.Reinhardt@amd.com p->brk_point = new_brk; 1921458SN/A DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); 1931458SN/A return p->brk_point; 194360SN/A} 195360SN/A 196360SN/A 1971450SN/ASyscallReturn 1983114Sgblack@eecs.umich.educloseFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 199360SN/A{ 2006701Sgblack@eecs.umich.edu int index = 0; 2016701Sgblack@eecs.umich.edu int target_fd = p->getSyscallArg(tc, index); 2027508Stjones1@inf.ed.ac.uk int sim_fd = p->sim_fd(target_fd); 2037508Stjones1@inf.ed.ac.uk int status = 0; 2047508Stjones1@inf.ed.ac.uk if (sim_fd > 2) 2057508Stjones1@inf.ed.ac.uk status = close(sim_fd); 2061970SN/A if (status >= 0) 2071970SN/A p->free_fd(target_fd); 2081970SN/A return status; 209360SN/A} 210360SN/A 211360SN/A 2121450SN/ASyscallReturn 2133114Sgblack@eecs.umich.edureadFunc(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 221360SN/A int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); 222360SN/A 223360SN/A if (bytes_read != -1) 2242680Sktlim@umich.edu bufArg.copyOut(tc->getMemPort()); 225360SN/A 2261458SN/A return bytes_read; 227360SN/A} 228360SN/A 2291450SN/ASyscallReturn 2303114Sgblack@eecs.umich.eduwriteFunc(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 Addr bufPtr = p->getSyscallArg(tc, index); 2356701Sgblack@eecs.umich.edu int nbytes = p->getSyscallArg(tc, index); 2366701Sgblack@eecs.umich.edu BufferArg bufArg(bufPtr, nbytes); 237360SN/A 2382680Sktlim@umich.edu bufArg.copyIn(tc->getMemPort()); 239360SN/A 240360SN/A int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); 241360SN/A 242360SN/A fsync(fd); 243360SN/A 2441458SN/A return bytes_written; 245360SN/A} 246360SN/A 247360SN/A 2481450SN/ASyscallReturn 2493114Sgblack@eecs.umich.edulseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 250360SN/A{ 2516701Sgblack@eecs.umich.edu int index = 0; 2526701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2536701Sgblack@eecs.umich.edu uint64_t offs = p->getSyscallArg(tc, index); 2546701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 255360SN/A 256360SN/A off_t result = lseek(fd, offs, whence); 257360SN/A 2581458SN/A return (result == (off_t)-1) ? -errno : result; 259360SN/A} 260360SN/A 261360SN/A 2621450SN/ASyscallReturn 2634118Sgblack@eecs.umich.edu_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 2644118Sgblack@eecs.umich.edu{ 2656701Sgblack@eecs.umich.edu int index = 0; 2666701Sgblack@eecs.umich.edu int fd = p->sim_fd(p->getSyscallArg(tc, index)); 2676701Sgblack@eecs.umich.edu uint64_t offset_high = p->getSyscallArg(tc, index); 2686701Sgblack@eecs.umich.edu uint32_t offset_low = p->getSyscallArg(tc, index); 2696701Sgblack@eecs.umich.edu Addr result_ptr = p->getSyscallArg(tc, index); 2706701Sgblack@eecs.umich.edu int whence = p->getSyscallArg(tc, index); 2714118Sgblack@eecs.umich.edu 2724118Sgblack@eecs.umich.edu uint64_t offset = (offset_high << 32) | offset_low; 2734118Sgblack@eecs.umich.edu 2744118Sgblack@eecs.umich.edu uint64_t result = lseek(fd, offset, whence); 2754118Sgblack@eecs.umich.edu result = TheISA::htog(result); 2764118Sgblack@eecs.umich.edu 2774118Sgblack@eecs.umich.edu if (result == (off_t)-1) { 2784118Sgblack@eecs.umich.edu //The seek failed. 2794118Sgblack@eecs.umich.edu return -errno; 2804118Sgblack@eecs.umich.edu } else { 2816111Ssteve.reinhardt@amd.com // The seek succeeded. 2826111Ssteve.reinhardt@amd.com // Copy "result" to "result_ptr" 2836111Ssteve.reinhardt@amd.com // XXX We'll assume that the size of loff_t is 64 bits on the 2846111Ssteve.reinhardt@amd.com // target platform 2854118Sgblack@eecs.umich.edu BufferArg result_buf(result_ptr, sizeof(result)); 2864118Sgblack@eecs.umich.edu memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 2874118Sgblack@eecs.umich.edu result_buf.copyOut(tc->getMemPort()); 2884118Sgblack@eecs.umich.edu return 0; 2894118Sgblack@eecs.umich.edu } 2904118Sgblack@eecs.umich.edu 2914118Sgblack@eecs.umich.edu 2924118Sgblack@eecs.umich.edu return (result == (off_t)-1) ? -errno : result; 2934118Sgblack@eecs.umich.edu} 2944118Sgblack@eecs.umich.edu 2954118Sgblack@eecs.umich.edu 2964118Sgblack@eecs.umich.eduSyscallReturn 2973114Sgblack@eecs.umich.edumunmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 298360SN/A{ 299360SN/A // given that we don't really implement mmap, munmap is really easy 3001458SN/A return 0; 301360SN/A} 302360SN/A 303360SN/A 304360SN/Aconst char *hostname = "m5.eecs.umich.edu"; 305360SN/A 3061450SN/ASyscallReturn 3073114Sgblack@eecs.umich.edugethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 308360SN/A{ 3096701Sgblack@eecs.umich.edu int index = 0; 3106701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3116701Sgblack@eecs.umich.edu int name_len = p->getSyscallArg(tc, index); 3126701Sgblack@eecs.umich.edu BufferArg name(bufPtr, name_len); 313360SN/A 314360SN/A strncpy((char *)name.bufferPtr(), hostname, name_len); 315360SN/A 3162680Sktlim@umich.edu name.copyOut(tc->getMemPort()); 317360SN/A 3181458SN/A return 0; 319360SN/A} 320360SN/A 3211450SN/ASyscallReturn 3225513SMichael.Adler@intel.comgetcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3235513SMichael.Adler@intel.com{ 3245513SMichael.Adler@intel.com int result = 0; 3256731Svince@csl.cornell.edu int index = 0; 3266701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3276701Sgblack@eecs.umich.edu unsigned long size = p->getSyscallArg(tc, index); 3286701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, size); 3295513SMichael.Adler@intel.com 3305513SMichael.Adler@intel.com // Is current working directory defined? 3315513SMichael.Adler@intel.com string cwd = p->getcwd(); 3325513SMichael.Adler@intel.com if (!cwd.empty()) { 3335513SMichael.Adler@intel.com if (cwd.length() >= size) { 3345513SMichael.Adler@intel.com // Buffer too small 3355513SMichael.Adler@intel.com return -ERANGE; 3365513SMichael.Adler@intel.com } 3375513SMichael.Adler@intel.com strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); 3385513SMichael.Adler@intel.com result = cwd.length(); 3395513SMichael.Adler@intel.com } 3405513SMichael.Adler@intel.com else { 3415513SMichael.Adler@intel.com if (getcwd((char *)buf.bufferPtr(), size) != NULL) { 3425513SMichael.Adler@intel.com result = strlen((char *)buf.bufferPtr()); 3435513SMichael.Adler@intel.com } 3445513SMichael.Adler@intel.com else { 3455513SMichael.Adler@intel.com result = -1; 3465513SMichael.Adler@intel.com } 3475513SMichael.Adler@intel.com } 3485513SMichael.Adler@intel.com 3495513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3505513SMichael.Adler@intel.com 3515513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3525513SMichael.Adler@intel.com} 3535513SMichael.Adler@intel.com 3545513SMichael.Adler@intel.com 3555513SMichael.Adler@intel.comSyscallReturn 3565513SMichael.Adler@intel.comreadlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3575513SMichael.Adler@intel.com{ 3585513SMichael.Adler@intel.com string path; 3595513SMichael.Adler@intel.com 3606701Sgblack@eecs.umich.edu int index = 0; 3616701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3625513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 3635513SMichael.Adler@intel.com 3645513SMichael.Adler@intel.com // Adjust path for current working directory 3655513SMichael.Adler@intel.com path = p->fullPath(path); 3665513SMichael.Adler@intel.com 3676701Sgblack@eecs.umich.edu Addr bufPtr = p->getSyscallArg(tc, index); 3686701Sgblack@eecs.umich.edu size_t bufsiz = p->getSyscallArg(tc, index); 3696701Sgblack@eecs.umich.edu 3706701Sgblack@eecs.umich.edu BufferArg buf(bufPtr, bufsiz); 3715513SMichael.Adler@intel.com 3725513SMichael.Adler@intel.com int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 3735513SMichael.Adler@intel.com 3745513SMichael.Adler@intel.com buf.copyOut(tc->getMemPort()); 3755513SMichael.Adler@intel.com 3765513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 3775513SMichael.Adler@intel.com} 3785513SMichael.Adler@intel.com 3795513SMichael.Adler@intel.comSyscallReturn 3803114Sgblack@eecs.umich.eduunlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 381511SN/A{ 3821706SN/A string path; 383360SN/A 3846701Sgblack@eecs.umich.edu int index = 0; 3856701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 3861450SN/A return (TheISA::IntReg)-EFAULT; 387511SN/A 3883669Sbinkertn@umich.edu // Adjust path for current working directory 3893669Sbinkertn@umich.edu path = p->fullPath(path); 3903669Sbinkertn@umich.edu 391511SN/A int result = unlink(path.c_str()); 3921458SN/A return (result == -1) ? -errno : result; 393511SN/A} 394511SN/A 3955513SMichael.Adler@intel.com 3965513SMichael.Adler@intel.comSyscallReturn 3975513SMichael.Adler@intel.commkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3985513SMichael.Adler@intel.com{ 3995513SMichael.Adler@intel.com string path; 4005513SMichael.Adler@intel.com 4016701Sgblack@eecs.umich.edu int index = 0; 4026701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4035513SMichael.Adler@intel.com return (TheISA::IntReg)-EFAULT; 4045513SMichael.Adler@intel.com 4055513SMichael.Adler@intel.com // Adjust path for current working directory 4065513SMichael.Adler@intel.com path = p->fullPath(path); 4075513SMichael.Adler@intel.com 4086701Sgblack@eecs.umich.edu mode_t mode = p->getSyscallArg(tc, index); 4095513SMichael.Adler@intel.com 4105513SMichael.Adler@intel.com int result = mkdir(path.c_str(), mode); 4115513SMichael.Adler@intel.com return (result == -1) ? -errno : result; 4125513SMichael.Adler@intel.com} 4135513SMichael.Adler@intel.com 4141450SN/ASyscallReturn 4153114Sgblack@eecs.umich.edurenameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 416511SN/A{ 4171706SN/A string old_name; 418511SN/A 4196701Sgblack@eecs.umich.edu int index = 0; 4206701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index))) 4211458SN/A return -EFAULT; 422511SN/A 4231706SN/A string new_name; 424511SN/A 4256701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index))) 4261458SN/A return -EFAULT; 427511SN/A 4283669Sbinkertn@umich.edu // Adjust path for current working directory 4293669Sbinkertn@umich.edu old_name = p->fullPath(old_name); 4303669Sbinkertn@umich.edu new_name = p->fullPath(new_name); 4313669Sbinkertn@umich.edu 4321706SN/A int64_t result = rename(old_name.c_str(), new_name.c_str()); 4331458SN/A return (result == -1) ? -errno : result; 434511SN/A} 435511SN/A 4361706SN/ASyscallReturn 4373114Sgblack@eecs.umich.edutruncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 4381706SN/A{ 4391706SN/A string path; 4401706SN/A 4416701Sgblack@eecs.umich.edu int index = 0; 4426701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 4431706SN/A return -EFAULT; 4441706SN/A 4456701Sgblack@eecs.umich.edu off_t length = p->getSyscallArg(tc, index); 4461706SN/A 4473669Sbinkertn@umich.edu // Adjust path for current working directory 4483669Sbinkertn@umich.edu path = p->fullPath(path); 4493669Sbinkertn@umich.edu 4501706SN/A int result = truncate(path.c_str(), length); 4511706SN/A return (result == -1) ? -errno : result; 4521706SN/A} 4531706SN/A 4541706SN/ASyscallReturn 4556111Ssteve.reinhardt@amd.comftruncateFunc(SyscallDesc *desc, int num, 4566111Ssteve.reinhardt@amd.com LiveProcess *process, ThreadContext *tc) 4571706SN/A{ 4586701Sgblack@eecs.umich.edu int index = 0; 4596701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4601706SN/A 4611706SN/A if (fd < 0) 4621706SN/A return -EBADF; 4631706SN/A 4646701Sgblack@eecs.umich.edu off_t length = process->getSyscallArg(tc, index); 4651706SN/A 4661706SN/A int result = ftruncate(fd, length); 4671706SN/A return (result == -1) ? -errno : result; 4681706SN/A} 4691999SN/A 4701999SN/ASyscallReturn 4716703Svince@csl.cornell.edutruncate64Func(SyscallDesc *desc, int num, 4726703Svince@csl.cornell.edu LiveProcess *process, ThreadContext *tc) 4736703Svince@csl.cornell.edu{ 4746703Svince@csl.cornell.edu int index = 0; 4756703Svince@csl.cornell.edu string path; 4766703Svince@csl.cornell.edu 4776703Svince@csl.cornell.edu if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, index))) 4786703Svince@csl.cornell.edu return -EFAULT; 4796703Svince@csl.cornell.edu 4806744SAli.Saidi@arm.com int64_t length = process->getSyscallArg(tc, index, 64); 4816703Svince@csl.cornell.edu 4826703Svince@csl.cornell.edu // Adjust path for current working directory 4836703Svince@csl.cornell.edu path = process->fullPath(path); 4846703Svince@csl.cornell.edu 4856744SAli.Saidi@arm.com#if NO_STAT64 4866744SAli.Saidi@arm.com int result = truncate(path.c_str(), length); 4876744SAli.Saidi@arm.com#else 4886703Svince@csl.cornell.edu int result = truncate64(path.c_str(), length); 4896744SAli.Saidi@arm.com#endif 4906703Svince@csl.cornell.edu return (result == -1) ? -errno : result; 4916703Svince@csl.cornell.edu} 4926703Svince@csl.cornell.edu 4936703Svince@csl.cornell.eduSyscallReturn 4946685Stjones1@inf.ed.ac.ukftruncate64Func(SyscallDesc *desc, int num, 4956685Stjones1@inf.ed.ac.uk LiveProcess *process, ThreadContext *tc) 4966685Stjones1@inf.ed.ac.uk{ 4976701Sgblack@eecs.umich.edu int index = 0; 4986701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 4996685Stjones1@inf.ed.ac.uk 5006685Stjones1@inf.ed.ac.uk if (fd < 0) 5016685Stjones1@inf.ed.ac.uk return -EBADF; 5026685Stjones1@inf.ed.ac.uk 5036744SAli.Saidi@arm.com int64_t length = process->getSyscallArg(tc, index, 64); 5046685Stjones1@inf.ed.ac.uk 5056744SAli.Saidi@arm.com#if NO_STAT64 5066744SAli.Saidi@arm.com int result = ftruncate(fd, length); 5076744SAli.Saidi@arm.com#else 5086685Stjones1@inf.ed.ac.uk int result = ftruncate64(fd, length); 5096744SAli.Saidi@arm.com#endif 5106685Stjones1@inf.ed.ac.uk return (result == -1) ? -errno : result; 5116685Stjones1@inf.ed.ac.uk} 5126685Stjones1@inf.ed.ac.uk 5136685Stjones1@inf.ed.ac.ukSyscallReturn 5145513SMichael.Adler@intel.comumaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5155513SMichael.Adler@intel.com{ 5165513SMichael.Adler@intel.com // Letting the simulated program change the simulator's umask seems like 5175513SMichael.Adler@intel.com // a bad idea. Compromise by just returning the current umask but not 5185513SMichael.Adler@intel.com // changing anything. 5195513SMichael.Adler@intel.com mode_t oldMask = umask(0); 5205513SMichael.Adler@intel.com umask(oldMask); 5215521Snate@binkert.org return (int)oldMask; 5225513SMichael.Adler@intel.com} 5235513SMichael.Adler@intel.com 5245513SMichael.Adler@intel.comSyscallReturn 5253114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 5261999SN/A{ 5271999SN/A string path; 5281999SN/A 5296701Sgblack@eecs.umich.edu int index = 0; 5306701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index))) 5311999SN/A return -EFAULT; 5321999SN/A 5331999SN/A /* XXX endianess */ 5346701Sgblack@eecs.umich.edu uint32_t owner = p->getSyscallArg(tc, index); 5351999SN/A uid_t hostOwner = owner; 5366701Sgblack@eecs.umich.edu uint32_t group = p->getSyscallArg(tc, index); 5371999SN/A gid_t hostGroup = group; 5381999SN/A 5393669Sbinkertn@umich.edu // Adjust path for current working directory 5403669Sbinkertn@umich.edu path = p->fullPath(path); 5413669Sbinkertn@umich.edu 5421999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 5431999SN/A return (result == -1) ? -errno : result; 5441999SN/A} 5451999SN/A 5461999SN/ASyscallReturn 5473114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5481999SN/A{ 5496701Sgblack@eecs.umich.edu int index = 0; 5506701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5511999SN/A 5521999SN/A if (fd < 0) 5531999SN/A return -EBADF; 5541999SN/A 5551999SN/A /* XXX endianess */ 5566701Sgblack@eecs.umich.edu uint32_t owner = process->getSyscallArg(tc, index); 5571999SN/A uid_t hostOwner = owner; 5586701Sgblack@eecs.umich.edu uint32_t group = process->getSyscallArg(tc, index); 5591999SN/A gid_t hostGroup = group; 5601999SN/A 5611999SN/A int result = fchown(fd, hostOwner, hostGroup); 5621999SN/A return (result == -1) ? -errno : result; 5631999SN/A} 5642093SN/A 5652093SN/A 5662093SN/ASyscallReturn 5673114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 5683079Sstever@eecs.umich.edu{ 5696701Sgblack@eecs.umich.edu int index = 0; 5706701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 5713079Sstever@eecs.umich.edu if (fd < 0) 5723079Sstever@eecs.umich.edu return -EBADF; 5733079Sstever@eecs.umich.edu 5746701Sgblack@eecs.umich.edu Process::FdMap *fdo = process->sim_fd_obj(fd); 5755282Srstrong@cs.ucsd.edu 5763079Sstever@eecs.umich.edu int result = dup(fd); 5776111Ssteve.reinhardt@amd.com return (result == -1) ? -errno : 5786111Ssteve.reinhardt@amd.com process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); 5793079Sstever@eecs.umich.edu} 5803079Sstever@eecs.umich.edu 5813079Sstever@eecs.umich.edu 5823079Sstever@eecs.umich.eduSyscallReturn 5833114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 5842680Sktlim@umich.edu ThreadContext *tc) 5852093SN/A{ 5866701Sgblack@eecs.umich.edu int index = 0; 5876701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 5882093SN/A 5892093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 5902093SN/A return -EBADF; 5912093SN/A 5926701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 5932093SN/A switch (cmd) { 5942093SN/A case 0: // F_DUPFD 5952093SN/A // if we really wanted to support this, we'd need to do it 5962093SN/A // in the target fd space. 5972093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 5982093SN/A return -EMFILE; 5992093SN/A 6002093SN/A case 1: // F_GETFD (get close-on-exec flag) 6012093SN/A case 2: // F_SETFD (set close-on-exec flag) 6022093SN/A return 0; 6032093SN/A 6042093SN/A case 3: // F_GETFL (get file flags) 6052093SN/A case 4: // F_SETFL (set file flags) 6062093SN/A // not sure if this is totally valid, but we'll pass it through 6072093SN/A // to the underlying OS 6082093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 6092093SN/A return fcntl(process->sim_fd(fd), cmd); 6102093SN/A // return 0; 6112093SN/A 6122093SN/A case 7: // F_GETLK (get lock) 6132093SN/A case 8: // F_SETLK (set lock) 6142093SN/A case 9: // F_SETLKW (set lock and wait) 6152093SN/A // don't mess with file locking... just act like it's OK 6162093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 6172093SN/A return 0; 6182093SN/A 6192093SN/A default: 6202093SN/A warn("Unknown fcntl command %d\n", cmd); 6212093SN/A return 0; 6222093SN/A } 6232093SN/A} 6242093SN/A 6252238SN/ASyscallReturn 6263114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 6272687Sksewell@umich.edu ThreadContext *tc) 6282687Sksewell@umich.edu{ 6296701Sgblack@eecs.umich.edu int index = 0; 6306701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 6312687Sksewell@umich.edu 6322687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 6332687Sksewell@umich.edu return -EBADF; 6342687Sksewell@umich.edu 6356701Sgblack@eecs.umich.edu int cmd = process->getSyscallArg(tc, index); 6362687Sksewell@umich.edu switch (cmd) { 6372687Sksewell@umich.edu case 33: //F_GETLK64 6382687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 6392687Sksewell@umich.edu return -EMFILE; 6402687Sksewell@umich.edu 6412687Sksewell@umich.edu case 34: // F_SETLK64 6422687Sksewell@umich.edu case 35: // F_SETLKW64 6432687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 6442687Sksewell@umich.edu return -EMFILE; 6452687Sksewell@umich.edu 6462687Sksewell@umich.edu default: 6472687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 6482687Sksewell@umich.edu // to the underlying OS 6492687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 6502687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 6512687Sksewell@umich.edu // return 0; 6522687Sksewell@umich.edu } 6532687Sksewell@umich.edu} 6542687Sksewell@umich.edu 6552687Sksewell@umich.eduSyscallReturn 6563114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6572680Sktlim@umich.edu ThreadContext *tc) 6582238SN/A{ 6592238SN/A int fds[2], sim_fds[2]; 6602238SN/A int pipe_retval = pipe(fds); 6612093SN/A 6622238SN/A if (pipe_retval < 0) { 6632238SN/A // error 6642238SN/A return pipe_retval; 6652238SN/A } 6662238SN/A 6675282Srstrong@cs.ucsd.edu sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); 6685282Srstrong@cs.ucsd.edu sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); 6692238SN/A 6705282Srstrong@cs.ucsd.edu process->setReadPipeSource(sim_fds[0], sim_fds[1]); 6712238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 6722238SN/A // the return value of the function, and fd[1] is returned in r20. 6732680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 6742238SN/A return sim_fds[0]; 6752238SN/A} 6762238SN/A 6772238SN/A 6782238SN/ASyscallReturn 6793114Sgblack@eecs.umich.edugetpidPseudoFunc(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()); 6873114Sgblack@eecs.umich.edu return process->pid(); 6882238SN/A} 6892238SN/A 6902238SN/A 6912238SN/ASyscallReturn 6923114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6932680Sktlim@umich.edu ThreadContext *tc) 6942238SN/A{ 6952238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 6962238SN/A // simulation to be deterministic. 6972238SN/A 6982238SN/A // EUID goes in r20. 6993114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 7005543Ssaidi@eecs.umich.edu return process->uid(); // UID 7012238SN/A} 7022238SN/A 7032238SN/A 7042238SN/ASyscallReturn 7053114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7062680Sktlim@umich.edu ThreadContext *tc) 7072238SN/A{ 7082238SN/A // Get current group ID. EGID goes in r20. 7093114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 7103114Sgblack@eecs.umich.edu return process->gid(); 7112238SN/A} 7122238SN/A 7132238SN/A 7142238SN/ASyscallReturn 7153114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7162680Sktlim@umich.edu ThreadContext *tc) 7172238SN/A{ 7182238SN/A // can't fathom why a benchmark would call this. 7196701Sgblack@eecs.umich.edu int index = 0; 7206701Sgblack@eecs.umich.edu warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 7212238SN/A return 0; 7222238SN/A} 7232238SN/A 7242238SN/ASyscallReturn 7253114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7262680Sktlim@umich.edu ThreadContext *tc) 7272238SN/A{ 7282238SN/A // Make up a PID. There's no interprocess communication in 7292238SN/A // fake_syscall mode, so there's no way for a process to know it's 7302238SN/A // not getting a unique value. 7312238SN/A 7323114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 7333114Sgblack@eecs.umich.edu return process->pid(); 7342238SN/A} 7352238SN/A 7362238SN/ASyscallReturn 7373114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7382680Sktlim@umich.edu ThreadContext *tc) 7392238SN/A{ 7403114Sgblack@eecs.umich.edu return process->ppid(); 7412238SN/A} 7422238SN/A 7432238SN/ASyscallReturn 7443114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7452680Sktlim@umich.edu ThreadContext *tc) 7462238SN/A{ 7475543Ssaidi@eecs.umich.edu return process->uid(); // UID 7482238SN/A} 7492238SN/A 7502238SN/ASyscallReturn 7513114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7522680Sktlim@umich.edu ThreadContext *tc) 7532238SN/A{ 7545543Ssaidi@eecs.umich.edu return process->euid(); // UID 7552238SN/A} 7562238SN/A 7572238SN/ASyscallReturn 7583114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7592680Sktlim@umich.edu ThreadContext *tc) 7602238SN/A{ 7613114Sgblack@eecs.umich.edu return process->gid(); 7622238SN/A} 7632238SN/A 7642238SN/ASyscallReturn 7653114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7662680Sktlim@umich.edu ThreadContext *tc) 7672238SN/A{ 7683114Sgblack@eecs.umich.edu return process->egid(); 7692238SN/A} 7702238SN/A 7712238SN/A 7726109Ssanchezd@stanford.eduSyscallReturn 7736109Ssanchezd@stanford.educloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7746109Ssanchezd@stanford.edu ThreadContext *tc) 7756109Ssanchezd@stanford.edu{ 7766701Sgblack@eecs.umich.edu int index = 0; 7776701Sgblack@eecs.umich.edu IntReg flags = process->getSyscallArg(tc, index); 7786701Sgblack@eecs.umich.edu IntReg newStack = process->getSyscallArg(tc, index); 7796701Sgblack@eecs.umich.edu 7806109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, "In sys_clone:\n"); 7816701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 7826701Sgblack@eecs.umich.edu DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); 7836109Ssanchezd@stanford.edu 7846109Ssanchezd@stanford.edu 7856701Sgblack@eecs.umich.edu if (flags != 0x10f00) { 7866111Ssteve.reinhardt@amd.com warn("This sys_clone implementation assumes flags " 7876111Ssteve.reinhardt@amd.com "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD " 7886111Ssteve.reinhardt@amd.com "(0x10f00), and may not work correctly with given flags " 7896701Sgblack@eecs.umich.edu "0x%llx\n", flags); 7906109Ssanchezd@stanford.edu } 7916109Ssanchezd@stanford.edu 7926111Ssteve.reinhardt@amd.com ThreadContext* ctc; // child thread context 7936109Ssanchezd@stanford.edu if ( ( ctc = process->findFreeContext() ) != NULL ) { 7946109Ssanchezd@stanford.edu DPRINTF(SyscallVerbose, " Found unallocated thread context\n"); 7956109Ssanchezd@stanford.edu 7966109Ssanchezd@stanford.edu ctc->clearArchRegs(); 7976109Ssanchezd@stanford.edu 7986111Ssteve.reinhardt@amd.com // Arch-specific cloning code 7996109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA 8006111Ssteve.reinhardt@amd.com // Cloning the misc. regs for these archs is enough 8016109Ssanchezd@stanford.edu TheISA::copyMiscRegs(tc, ctc); 8026109Ssanchezd@stanford.edu #elif THE_ISA == SPARC_ISA 8036109Ssanchezd@stanford.edu TheISA::copyRegs(tc, ctc); 8046109Ssanchezd@stanford.edu 8056111Ssteve.reinhardt@amd.com // TODO: Explain what this code actually does :-) 8066109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 6, 0); 8076109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 4, 0); 8086109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2); 8096109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 5, NWindows); 8106337Sgblack@eecs.umich.edu ctc->setMiscReg(MISCREG_CWP, 0); 8116109Ssanchezd@stanford.edu ctc->setIntReg(NumIntArchRegs + 7, 0); 8126109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_TL, 0); 8136109Ssanchezd@stanford.edu ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY); 8146109Ssanchezd@stanford.edu 8156109Ssanchezd@stanford.edu for (int y = 8; y < 32; y++) 8166109Ssanchezd@stanford.edu ctc->setIntReg(y, tc->readIntReg(y)); 8178149SChris.Emmons@ARM.com #elif THE_ISA == ARM_ISA 8188149SChris.Emmons@ARM.com TheISA::copyRegs(tc, ctc); 8196109Ssanchezd@stanford.edu #else 8206109Ssanchezd@stanford.edu fatal("sys_clone is not implemented for this ISA\n"); 8216109Ssanchezd@stanford.edu #endif 8226109Ssanchezd@stanford.edu 8236111Ssteve.reinhardt@amd.com // Set up stack register 8246701Sgblack@eecs.umich.edu ctc->setIntReg(TheISA::StackPointerReg, newStack); 8256109Ssanchezd@stanford.edu 8266111Ssteve.reinhardt@amd.com // Set up syscall return values in parent and child 8276111Ssteve.reinhardt@amd.com ctc->setIntReg(ReturnValueReg, 0); // return value, child 8286109Ssanchezd@stanford.edu 8296111Ssteve.reinhardt@amd.com // Alpha needs SyscallSuccessReg=0 in child 8306109Ssanchezd@stanford.edu #if THE_ISA == ALPHA_ISA 8316110Ssteve.reinhardt@amd.com ctc->setIntReg(TheISA::SyscallSuccessReg, 0); 8326109Ssanchezd@stanford.edu #endif 8336109Ssanchezd@stanford.edu 8346111Ssteve.reinhardt@amd.com // In SPARC/Linux, clone returns 0 on pseudo-return register if 8356111Ssteve.reinhardt@amd.com // parent, non-zero if child 8366109Ssanchezd@stanford.edu #if THE_ISA == SPARC_ISA 8376109Ssanchezd@stanford.edu tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0); 8386109Ssanchezd@stanford.edu ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1); 8396109Ssanchezd@stanford.edu #endif 8406109Ssanchezd@stanford.edu 8417720Sgblack@eecs.umich.edu ctc->pcState(tc->nextInstAddr()); 8426109Ssanchezd@stanford.edu 8436109Ssanchezd@stanford.edu ctc->activate(); 8446109Ssanchezd@stanford.edu 8456109Ssanchezd@stanford.edu // Should return nonzero child TID in parent's syscall return register, 8466109Ssanchezd@stanford.edu // but for our pthread library any non-zero value will work 8476109Ssanchezd@stanford.edu return 1; 8486109Ssanchezd@stanford.edu } else { 8496109Ssanchezd@stanford.edu fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 8506109Ssanchezd@stanford.edu return 0; 8516109Ssanchezd@stanford.edu } 8526109Ssanchezd@stanford.edu} 8536109Ssanchezd@stanford.edu 854