syscall_emul.hh revision 8766
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 * Kevin Lim 30360SN/A */ 31360SN/A 321354SN/A#ifndef __SIM_SYSCALL_EMUL_HH__ 331354SN/A#define __SIM_SYSCALL_EMUL_HH__ 34360SN/A 352764Sstever@eecs.umich.edu#define NO_STAT64 (defined(__APPLE__) || defined(__OpenBSD__) || \ 362764Sstever@eecs.umich.edu defined(__FreeBSD__) || defined(__CYGWIN__)) 372064SN/A 38360SN/A/// 39360SN/A/// @file syscall_emul.hh 40360SN/A/// 41360SN/A/// This file defines objects used to emulate syscalls from the target 42360SN/A/// application on the host machine. 43360SN/A 441809SN/A#ifdef __CYGWIN32__ 455543Ssaidi@eecs.umich.edu#include <sys/fcntl.h> // for O_BINARY 461809SN/A#endif 473113Sgblack@eecs.umich.edu#include <sys/stat.h> 488229Snate@binkert.org#include <sys/time.h> 498229Snate@binkert.org#include <sys/uio.h> 503113Sgblack@eecs.umich.edu#include <fcntl.h> 517075Snate@binkert.org 528229Snate@binkert.org#include <cerrno> 537075Snate@binkert.org#include <string> 54360SN/A 552474SN/A#include "base/chunk_generator.hh" 565543Ssaidi@eecs.umich.edu#include "base/intmath.hh" // for RoundUp 572462SN/A#include "base/misc.hh" 581354SN/A#include "base/trace.hh" 596216Snate@binkert.org#include "base/types.hh" 606658Snate@binkert.org#include "config/the_isa.hh" 612474SN/A#include "cpu/base.hh" 622680Sktlim@umich.edu#include "cpu/thread_context.hh" 638232Snate@binkert.org#include "debug/SyscallVerbose.hh" 648229Snate@binkert.org#include "mem/page_table.hh" 652474SN/A#include "mem/translating_port.hh" 667678Sgblack@eecs.umich.edu#include "sim/byteswap.hh" 678229Snate@binkert.org#include "sim/process.hh" 688766Sgblack@eecs.umich.edu#include "sim/syscallreturn.hh" 696640Svince@csl.cornell.edu#include "sim/system.hh" 70360SN/A 71360SN/A/// 72360SN/A/// System call descriptor. 73360SN/A/// 74360SN/Aclass SyscallDesc { 75360SN/A 76360SN/A public: 77360SN/A 78378SN/A /// Typedef for target syscall handler functions. 791450SN/A typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num, 803114Sgblack@eecs.umich.edu LiveProcess *, ThreadContext *); 81360SN/A 825543Ssaidi@eecs.umich.edu const char *name; //!< Syscall name (e.g., "open"). 835543Ssaidi@eecs.umich.edu FuncPtr funcPtr; //!< Pointer to emulation function. 845543Ssaidi@eecs.umich.edu int flags; //!< Flags (see Flags enum). 85360SN/A 86360SN/A /// Flag values for controlling syscall behavior. 87360SN/A enum Flags { 88360SN/A /// Don't set return regs according to funcPtr return value. 89360SN/A /// Used for syscalls with non-standard return conventions 902680Sktlim@umich.edu /// that explicitly set the ThreadContext regs (e.g., 91360SN/A /// sigreturn). 92360SN/A SuppressReturnValue = 1 93360SN/A }; 94360SN/A 95360SN/A /// Constructor. 96360SN/A SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0) 97360SN/A : name(_name), funcPtr(_funcPtr), flags(_flags) 98360SN/A { 99360SN/A } 100360SN/A 101360SN/A /// Emulate the syscall. Public interface for calling through funcPtr. 1023114Sgblack@eecs.umich.edu void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc); 103360SN/A}; 104360SN/A 105360SN/A 106360SN/Aclass BaseBufferArg { 107360SN/A 108360SN/A public: 109360SN/A 110360SN/A BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size) 111360SN/A { 112360SN/A bufPtr = new uint8_t[size]; 113360SN/A // clear out buffer: in case we only partially populate this, 114360SN/A // and then do a copyOut(), we want to make sure we don't 115360SN/A // introduce any random junk into the simulated address space 116360SN/A memset(bufPtr, 0, size); 117360SN/A } 118360SN/A 119360SN/A virtual ~BaseBufferArg() { delete [] bufPtr; } 120360SN/A 121360SN/A // 122360SN/A // copy data into simulator space (read from target memory) 123360SN/A // 1242400SN/A virtual bool copyIn(TranslatingPort *memport) 125360SN/A { 1262461SN/A memport->readBlob(addr, bufPtr, size); 1275543Ssaidi@eecs.umich.edu return true; // no EFAULT detection for now 128360SN/A } 129360SN/A 130360SN/A // 131360SN/A // copy data out of simulator space (write to target memory) 132360SN/A // 1332400SN/A virtual bool copyOut(TranslatingPort *memport) 134360SN/A { 1352461SN/A memport->writeBlob(addr, bufPtr, size); 1365543Ssaidi@eecs.umich.edu return true; // no EFAULT detection for now 137360SN/A } 138360SN/A 139360SN/A protected: 140360SN/A Addr addr; 141360SN/A int size; 142360SN/A uint8_t *bufPtr; 143360SN/A}; 144360SN/A 145360SN/A 146360SN/Aclass BufferArg : public BaseBufferArg 147360SN/A{ 148360SN/A public: 149360SN/A BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { } 1505543Ssaidi@eecs.umich.edu void *bufferPtr() { return bufPtr; } 151360SN/A}; 152360SN/A 153360SN/Atemplate <class T> 154360SN/Aclass TypedBufferArg : public BaseBufferArg 155360SN/A{ 156360SN/A public: 157360SN/A // user can optionally specify a specific number of bytes to 158360SN/A // allocate to deal with those structs that have variable-size 159360SN/A // arrays at the end 160360SN/A TypedBufferArg(Addr _addr, int _size = sizeof(T)) 161360SN/A : BaseBufferArg(_addr, _size) 162360SN/A { } 163360SN/A 164360SN/A // type case 165360SN/A operator T*() { return (T *)bufPtr; } 166360SN/A 167360SN/A // dereference operators 1685543Ssaidi@eecs.umich.edu T &operator*() { return *((T *)bufPtr); } 1695543Ssaidi@eecs.umich.edu T* operator->() { return (T *)bufPtr; } 170502SN/A T &operator[](int i) { return ((T *)bufPtr)[i]; } 171360SN/A}; 172360SN/A 173360SN/A////////////////////////////////////////////////////////////////////// 174360SN/A// 175360SN/A// The following emulation functions are generic enough that they 176360SN/A// don't need to be recompiled for different emulated OS's. They are 177360SN/A// defined in sim/syscall_emul.cc. 178360SN/A// 179360SN/A////////////////////////////////////////////////////////////////////// 180360SN/A 181360SN/A 182378SN/A/// Handler for unimplemented syscalls that we haven't thought about. 1831706SN/ASyscallReturn unimplementedFunc(SyscallDesc *desc, int num, 1843114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 185378SN/A 186378SN/A/// Handler for unimplemented syscalls that we never intend to 187378SN/A/// implement (signal handling, etc.) and should not affect the correct 188378SN/A/// behavior of the program. Print a warning only if the appropriate 189378SN/A/// trace flag is enabled. Return success to the target program. 1901706SN/ASyscallReturn ignoreFunc(SyscallDesc *desc, int num, 1913114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 1928149SChris.Emmons@ARM.comSyscallReturn ignoreWarnOnceFunc(SyscallDesc *desc, int num, 1938149SChris.Emmons@ARM.com LiveProcess *p, ThreadContext *tc); 194360SN/A 1956109Ssanchezd@stanford.edu/// Target exit() handler: terminate current context. 1961706SN/ASyscallReturn exitFunc(SyscallDesc *desc, int num, 1973114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 198378SN/A 1996109Ssanchezd@stanford.edu/// Target exit_group() handler: terminate simulation. (exit all threads) 2006109Ssanchezd@stanford.eduSyscallReturn exitGroupFunc(SyscallDesc *desc, int num, 2016109Ssanchezd@stanford.edu LiveProcess *p, ThreadContext *tc); 2026109Ssanchezd@stanford.edu 203378SN/A/// Target getpagesize() handler. 2041706SN/ASyscallReturn getpagesizeFunc(SyscallDesc *desc, int num, 2053114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 206378SN/A 2075748SSteve.Reinhardt@amd.com/// Target brk() handler: set brk address. 2085748SSteve.Reinhardt@amd.comSyscallReturn brkFunc(SyscallDesc *desc, int num, 2095748SSteve.Reinhardt@amd.com LiveProcess *p, ThreadContext *tc); 210378SN/A 211378SN/A/// Target close() handler. 2121706SN/ASyscallReturn closeFunc(SyscallDesc *desc, int num, 2133114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 214378SN/A 215378SN/A/// Target read() handler. 2161706SN/ASyscallReturn readFunc(SyscallDesc *desc, int num, 2173114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 218378SN/A 219378SN/A/// Target write() handler. 2201706SN/ASyscallReturn writeFunc(SyscallDesc *desc, int num, 2213114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 222378SN/A 223378SN/A/// Target lseek() handler. 2241706SN/ASyscallReturn lseekFunc(SyscallDesc *desc, int num, 2253114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 226378SN/A 2274118Sgblack@eecs.umich.edu/// Target _llseek() handler. 2284118Sgblack@eecs.umich.eduSyscallReturn _llseekFunc(SyscallDesc *desc, int num, 2294118Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2304118Sgblack@eecs.umich.edu 231378SN/A/// Target munmap() handler. 2321706SN/ASyscallReturn munmapFunc(SyscallDesc *desc, int num, 2333114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 234378SN/A 235378SN/A/// Target gethostname() handler. 2361706SN/ASyscallReturn gethostnameFunc(SyscallDesc *desc, int num, 2373114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 238360SN/A 2395513SMichael.Adler@intel.com/// Target getcwd() handler. 2405513SMichael.Adler@intel.comSyscallReturn getcwdFunc(SyscallDesc *desc, int num, 2415513SMichael.Adler@intel.com LiveProcess *p, ThreadContext *tc); 2425513SMichael.Adler@intel.com 2435513SMichael.Adler@intel.com/// Target unlink() handler. 2445513SMichael.Adler@intel.comSyscallReturn readlinkFunc(SyscallDesc *desc, int num, 2455513SMichael.Adler@intel.com LiveProcess *p, ThreadContext *tc); 2465513SMichael.Adler@intel.com 247511SN/A/// Target unlink() handler. 2481706SN/ASyscallReturn unlinkFunc(SyscallDesc *desc, int num, 2493114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 250511SN/A 2515513SMichael.Adler@intel.com/// Target mkdir() handler. 2525513SMichael.Adler@intel.comSyscallReturn mkdirFunc(SyscallDesc *desc, int num, 2535513SMichael.Adler@intel.com LiveProcess *p, ThreadContext *tc); 2545513SMichael.Adler@intel.com 255511SN/A/// Target rename() handler. 2561706SN/ASyscallReturn renameFunc(SyscallDesc *desc, int num, 2573114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2581706SN/A 2591706SN/A 2601706SN/A/// Target truncate() handler. 2611706SN/ASyscallReturn truncateFunc(SyscallDesc *desc, int num, 2623114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2631706SN/A 2641706SN/A 2651706SN/A/// Target ftruncate() handler. 2661706SN/ASyscallReturn ftruncateFunc(SyscallDesc *desc, int num, 2673114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2681706SN/A 269511SN/A 2706703Svince@csl.cornell.edu/// Target truncate64() handler. 2716703Svince@csl.cornell.eduSyscallReturn truncate64Func(SyscallDesc *desc, int num, 2726703Svince@csl.cornell.edu LiveProcess *p, ThreadContext *tc); 2736703Svince@csl.cornell.edu 2746685Stjones1@inf.ed.ac.uk/// Target ftruncate64() handler. 2756685Stjones1@inf.ed.ac.ukSyscallReturn ftruncate64Func(SyscallDesc *desc, int num, 2766685Stjones1@inf.ed.ac.uk LiveProcess *p, ThreadContext *tc); 2776685Stjones1@inf.ed.ac.uk 2786685Stjones1@inf.ed.ac.uk 2795513SMichael.Adler@intel.com/// Target umask() handler. 2805513SMichael.Adler@intel.comSyscallReturn umaskFunc(SyscallDesc *desc, int num, 2815513SMichael.Adler@intel.com LiveProcess *p, ThreadContext *tc); 2825513SMichael.Adler@intel.com 2835513SMichael.Adler@intel.com 2841999SN/A/// Target chown() handler. 2851999SN/ASyscallReturn chownFunc(SyscallDesc *desc, int num, 2863114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2871999SN/A 2881999SN/A 2891999SN/A/// Target fchown() handler. 2901999SN/ASyscallReturn fchownFunc(SyscallDesc *desc, int num, 2913114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 2921999SN/A 2933079Sstever@eecs.umich.edu/// Target dup() handler. 2943079Sstever@eecs.umich.eduSyscallReturn dupFunc(SyscallDesc *desc, int num, 2953114Sgblack@eecs.umich.edu LiveProcess *process, ThreadContext *tc); 2963079Sstever@eecs.umich.edu 2972093SN/A/// Target fnctl() handler. 2982093SN/ASyscallReturn fcntlFunc(SyscallDesc *desc, int num, 2993114Sgblack@eecs.umich.edu LiveProcess *process, ThreadContext *tc); 3002093SN/A 3012687Sksewell@umich.edu/// Target fcntl64() handler. 3022687Sksewell@umich.eduSyscallReturn fcntl64Func(SyscallDesc *desc, int num, 3033114Sgblack@eecs.umich.edu LiveProcess *process, ThreadContext *tc); 3042687Sksewell@umich.edu 3052238SN/A/// Target setuid() handler. 3062238SN/ASyscallReturn setuidFunc(SyscallDesc *desc, int num, 3073114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3082238SN/A 3092238SN/A/// Target getpid() handler. 3102238SN/ASyscallReturn getpidFunc(SyscallDesc *desc, int num, 3113114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3122238SN/A 3132238SN/A/// Target getuid() handler. 3142238SN/ASyscallReturn getuidFunc(SyscallDesc *desc, int num, 3153114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3162238SN/A 3172238SN/A/// Target getgid() handler. 3182238SN/ASyscallReturn getgidFunc(SyscallDesc *desc, int num, 3193114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3202238SN/A 3212238SN/A/// Target getppid() handler. 3222238SN/ASyscallReturn getppidFunc(SyscallDesc *desc, int num, 3233114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3242238SN/A 3252238SN/A/// Target geteuid() handler. 3262238SN/ASyscallReturn geteuidFunc(SyscallDesc *desc, int num, 3273114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3282238SN/A 3292238SN/A/// Target getegid() handler. 3302238SN/ASyscallReturn getegidFunc(SyscallDesc *desc, int num, 3313114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3322238SN/A 3336109Ssanchezd@stanford.edu/// Target clone() handler. 3346109Ssanchezd@stanford.eduSyscallReturn cloneFunc(SyscallDesc *desc, int num, 3356109Ssanchezd@stanford.edu LiveProcess *p, ThreadContext *tc); 3362238SN/A 3372238SN/A 3382238SN/A/// Pseudo Funcs - These functions use a different return convension, 3392238SN/A/// returning a second value in a register other than the normal return register 3402238SN/ASyscallReturn pipePseudoFunc(SyscallDesc *desc, int num, 3413114Sgblack@eecs.umich.edu LiveProcess *process, ThreadContext *tc); 3422238SN/A 3432238SN/A/// Target getpidPseudo() handler. 3442238SN/ASyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num, 3453114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3462238SN/A 3472238SN/A/// Target getuidPseudo() handler. 3482238SN/ASyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num, 3493114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3502238SN/A 3512238SN/A/// Target getgidPseudo() handler. 3522238SN/ASyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num, 3533114Sgblack@eecs.umich.edu LiveProcess *p, ThreadContext *tc); 3542238SN/A 3552238SN/A 3561354SN/A/// A readable name for 1,000,000, for converting microseconds to seconds. 3571354SN/Aconst int one_million = 1000000; 3581354SN/A 3591354SN/A/// Approximate seconds since the epoch (1/1/1970). About a billion, 3601354SN/A/// by my reckoning. We want to keep this a constant (not use the 3611354SN/A/// real-world time) to keep simulations repeatable. 3621354SN/Aconst unsigned seconds_since_epoch = 1000000000; 3631354SN/A 3641354SN/A/// Helper function to convert current elapsed time to seconds and 3651354SN/A/// microseconds. 3661354SN/Atemplate <class T1, class T2> 3671354SN/Avoid 3681354SN/AgetElapsedTime(T1 &sec, T2 &usec) 3691354SN/A{ 3707823Ssteve.reinhardt@amd.com int elapsed_usecs = curTick() / SimClock::Int::us; 3711354SN/A sec = elapsed_usecs / one_million; 3721354SN/A usec = elapsed_usecs % one_million; 3731354SN/A} 3741354SN/A 375360SN/A////////////////////////////////////////////////////////////////////// 376360SN/A// 377360SN/A// The following emulation functions are generic, but need to be 378360SN/A// templated to account for differences in types, constants, etc. 379360SN/A// 380360SN/A////////////////////////////////////////////////////////////////////// 381360SN/A 3823113Sgblack@eecs.umich.edu#if NO_STAT64 3833113Sgblack@eecs.umich.edu typedef struct stat hst_stat; 3843113Sgblack@eecs.umich.edu typedef struct stat hst_stat64; 3853113Sgblack@eecs.umich.edu#else 3863113Sgblack@eecs.umich.edu typedef struct stat hst_stat; 3873113Sgblack@eecs.umich.edu typedef struct stat64 hst_stat64; 3883113Sgblack@eecs.umich.edu#endif 3893113Sgblack@eecs.umich.edu 3903113Sgblack@eecs.umich.edu//// Helper function to convert a host stat buffer to a target stat 3913113Sgblack@eecs.umich.edu//// buffer. Also copies the target buffer out to the simulated 3923113Sgblack@eecs.umich.edu//// memory space. Used by stat(), fstat(), and lstat(). 3933113Sgblack@eecs.umich.edu 3943113Sgblack@eecs.umich.edutemplate <typename target_stat, typename host_stat> 3953113Sgblack@eecs.umich.edustatic void 3963113Sgblack@eecs.umich.educonvertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false) 3973113Sgblack@eecs.umich.edu{ 3984189Sgblack@eecs.umich.edu using namespace TheISA; 3994189Sgblack@eecs.umich.edu 4003113Sgblack@eecs.umich.edu if (fakeTTY) 4013113Sgblack@eecs.umich.edu tgt->st_dev = 0xA; 4023113Sgblack@eecs.umich.edu else 4033113Sgblack@eecs.umich.edu tgt->st_dev = host->st_dev; 4043113Sgblack@eecs.umich.edu tgt->st_dev = htog(tgt->st_dev); 4053113Sgblack@eecs.umich.edu tgt->st_ino = host->st_ino; 4063113Sgblack@eecs.umich.edu tgt->st_ino = htog(tgt->st_ino); 4073277Sgblack@eecs.umich.edu tgt->st_mode = host->st_mode; 4085515SMichael.Adler@intel.com if (fakeTTY) { 4095515SMichael.Adler@intel.com // Claim to be a character device 4105515SMichael.Adler@intel.com tgt->st_mode &= ~S_IFMT; // Clear S_IFMT 4115515SMichael.Adler@intel.com tgt->st_mode |= S_IFCHR; // Set S_IFCHR 4125515SMichael.Adler@intel.com } 4133277Sgblack@eecs.umich.edu tgt->st_mode = htog(tgt->st_mode); 4143277Sgblack@eecs.umich.edu tgt->st_nlink = host->st_nlink; 4153277Sgblack@eecs.umich.edu tgt->st_nlink = htog(tgt->st_nlink); 4163277Sgblack@eecs.umich.edu tgt->st_uid = host->st_uid; 4173277Sgblack@eecs.umich.edu tgt->st_uid = htog(tgt->st_uid); 4183277Sgblack@eecs.umich.edu tgt->st_gid = host->st_gid; 4193277Sgblack@eecs.umich.edu tgt->st_gid = htog(tgt->st_gid); 4203113Sgblack@eecs.umich.edu if (fakeTTY) 4213113Sgblack@eecs.umich.edu tgt->st_rdev = 0x880d; 4223113Sgblack@eecs.umich.edu else 4233113Sgblack@eecs.umich.edu tgt->st_rdev = host->st_rdev; 4243113Sgblack@eecs.umich.edu tgt->st_rdev = htog(tgt->st_rdev); 4253113Sgblack@eecs.umich.edu tgt->st_size = host->st_size; 4263113Sgblack@eecs.umich.edu tgt->st_size = htog(tgt->st_size); 4273114Sgblack@eecs.umich.edu tgt->st_atimeX = host->st_atime; 4283113Sgblack@eecs.umich.edu tgt->st_atimeX = htog(tgt->st_atimeX); 4293114Sgblack@eecs.umich.edu tgt->st_mtimeX = host->st_mtime; 4303113Sgblack@eecs.umich.edu tgt->st_mtimeX = htog(tgt->st_mtimeX); 4313114Sgblack@eecs.umich.edu tgt->st_ctimeX = host->st_ctime; 4323113Sgblack@eecs.umich.edu tgt->st_ctimeX = htog(tgt->st_ctimeX); 4334061Sgblack@eecs.umich.edu // Force the block size to be 8k. This helps to ensure buffered io works 4344061Sgblack@eecs.umich.edu // consistently across different hosts. 4354061Sgblack@eecs.umich.edu tgt->st_blksize = 0x2000; 4363113Sgblack@eecs.umich.edu tgt->st_blksize = htog(tgt->st_blksize); 4373113Sgblack@eecs.umich.edu tgt->st_blocks = host->st_blocks; 4383113Sgblack@eecs.umich.edu tgt->st_blocks = htog(tgt->st_blocks); 4393113Sgblack@eecs.umich.edu} 4403113Sgblack@eecs.umich.edu 4413113Sgblack@eecs.umich.edu// Same for stat64 4423113Sgblack@eecs.umich.edu 4433113Sgblack@eecs.umich.edutemplate <typename target_stat, typename host_stat64> 4443113Sgblack@eecs.umich.edustatic void 4453113Sgblack@eecs.umich.educonvertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false) 4463113Sgblack@eecs.umich.edu{ 4474189Sgblack@eecs.umich.edu using namespace TheISA; 4484189Sgblack@eecs.umich.edu 4493113Sgblack@eecs.umich.edu convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY); 4503113Sgblack@eecs.umich.edu#if defined(STAT_HAVE_NSEC) 4513113Sgblack@eecs.umich.edu tgt->st_atime_nsec = host->st_atime_nsec; 4523113Sgblack@eecs.umich.edu tgt->st_atime_nsec = htog(tgt->st_atime_nsec); 4533113Sgblack@eecs.umich.edu tgt->st_mtime_nsec = host->st_mtime_nsec; 4543113Sgblack@eecs.umich.edu tgt->st_mtime_nsec = htog(tgt->st_mtime_nsec); 4553113Sgblack@eecs.umich.edu tgt->st_ctime_nsec = host->st_ctime_nsec; 4563113Sgblack@eecs.umich.edu tgt->st_ctime_nsec = htog(tgt->st_ctime_nsec); 4573113Sgblack@eecs.umich.edu#else 4583113Sgblack@eecs.umich.edu tgt->st_atime_nsec = 0; 4593113Sgblack@eecs.umich.edu tgt->st_mtime_nsec = 0; 4603113Sgblack@eecs.umich.edu tgt->st_ctime_nsec = 0; 4613113Sgblack@eecs.umich.edu#endif 4623113Sgblack@eecs.umich.edu} 4633113Sgblack@eecs.umich.edu 4643113Sgblack@eecs.umich.edu//Here are a couple convenience functions 4653113Sgblack@eecs.umich.edutemplate<class OS> 4663113Sgblack@eecs.umich.edustatic void 4673113Sgblack@eecs.umich.educopyOutStatBuf(TranslatingPort * mem, Addr addr, 4683113Sgblack@eecs.umich.edu hst_stat *host, bool fakeTTY = false) 4693113Sgblack@eecs.umich.edu{ 4703113Sgblack@eecs.umich.edu typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf; 4713113Sgblack@eecs.umich.edu tgt_stat_buf tgt(addr); 4723113Sgblack@eecs.umich.edu convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY); 4733113Sgblack@eecs.umich.edu tgt.copyOut(mem); 4743113Sgblack@eecs.umich.edu} 4753113Sgblack@eecs.umich.edu 4763113Sgblack@eecs.umich.edutemplate<class OS> 4773113Sgblack@eecs.umich.edustatic void 4783113Sgblack@eecs.umich.educopyOutStat64Buf(TranslatingPort * mem, Addr addr, 4793113Sgblack@eecs.umich.edu hst_stat64 *host, bool fakeTTY = false) 4803113Sgblack@eecs.umich.edu{ 4813113Sgblack@eecs.umich.edu typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf; 4823113Sgblack@eecs.umich.edu tgt_stat_buf tgt(addr); 4836686Stjones1@inf.ed.ac.uk convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY); 4843113Sgblack@eecs.umich.edu tgt.copyOut(mem); 4853113Sgblack@eecs.umich.edu} 4863113Sgblack@eecs.umich.edu 487378SN/A/// Target ioctl() handler. For the most part, programs call ioctl() 488378SN/A/// only to find out if their stdout is a tty, to determine whether to 489378SN/A/// do line or block buffering. 490360SN/Atemplate <class OS> 4911450SN/ASyscallReturn 4923114Sgblack@eecs.umich.eduioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4932680Sktlim@umich.edu ThreadContext *tc) 494360SN/A{ 4956701Sgblack@eecs.umich.edu int index = 0; 4966701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 4976701Sgblack@eecs.umich.edu unsigned req = process->getSyscallArg(tc, index); 498360SN/A 4991969SN/A DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req); 500360SN/A 501360SN/A if (fd < 0 || process->sim_fd(fd) < 0) { 502360SN/A // doesn't map to any simulator fd: not a valid target fd 5031458SN/A return -EBADF; 504360SN/A } 505360SN/A 506360SN/A switch (req) { 5074131Sbinkertn@umich.edu case OS::TIOCISATTY_: 5084131Sbinkertn@umich.edu case OS::TIOCGETP_: 5094131Sbinkertn@umich.edu case OS::TIOCSETP_: 5104131Sbinkertn@umich.edu case OS::TIOCSETN_: 5114131Sbinkertn@umich.edu case OS::TIOCSETC_: 5124131Sbinkertn@umich.edu case OS::TIOCGETC_: 5134131Sbinkertn@umich.edu case OS::TIOCGETS_: 5144131Sbinkertn@umich.edu case OS::TIOCGETA_: 5156689Stjones1@inf.ed.ac.uk case OS::TCSETAW_: 5161458SN/A return -ENOTTY; 517360SN/A 518360SN/A default: 5197720Sgblack@eecs.umich.edu fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n", 5207720Sgblack@eecs.umich.edu fd, req, tc->pcState()); 521360SN/A } 522360SN/A} 523360SN/A 524378SN/A/// Target open() handler. 525360SN/Atemplate <class OS> 5261450SN/ASyscallReturn 5273114Sgblack@eecs.umich.eduopenFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5282680Sktlim@umich.edu ThreadContext *tc) 529360SN/A{ 530360SN/A std::string path; 531360SN/A 5326701Sgblack@eecs.umich.edu int index = 0; 5336701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 5346701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) 5351458SN/A return -EFAULT; 536360SN/A 537360SN/A if (path == "/dev/sysdev0") { 538360SN/A // This is a memory-mapped high-resolution timer device on Alpha. 539360SN/A // We don't support it, so just punt. 5401706SN/A warn("Ignoring open(%s, ...)\n", path); 5411458SN/A return -ENOENT; 542360SN/A } 543360SN/A 5446701Sgblack@eecs.umich.edu int tgtFlags = process->getSyscallArg(tc, index); 5456701Sgblack@eecs.umich.edu int mode = process->getSyscallArg(tc, index); 546360SN/A int hostFlags = 0; 547360SN/A 548360SN/A // translate open flags 549360SN/A for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) { 550360SN/A if (tgtFlags & OS::openFlagTable[i].tgtFlag) { 551360SN/A tgtFlags &= ~OS::openFlagTable[i].tgtFlag; 552360SN/A hostFlags |= OS::openFlagTable[i].hostFlag; 553360SN/A } 554360SN/A } 555360SN/A 556360SN/A // any target flags left? 557360SN/A if (tgtFlags != 0) 5581706SN/A warn("Syscall: open: cannot decode flags 0x%x", tgtFlags); 559360SN/A 560360SN/A#ifdef __CYGWIN32__ 561360SN/A hostFlags |= O_BINARY; 562360SN/A#endif 563360SN/A 5643669Sbinkertn@umich.edu // Adjust path for current working directory 5653669Sbinkertn@umich.edu path = process->fullPath(path); 5663669Sbinkertn@umich.edu 5671706SN/A DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str()); 5681706SN/A 5695795Ssaidi@eecs.umich.edu int fd; 5705795Ssaidi@eecs.umich.edu if (!path.compare(0, 6, "/proc/") || !path.compare(0, 8, "/system/") || 5715795Ssaidi@eecs.umich.edu !path.compare(0, 10, "/platform/") || !path.compare(0, 5, "/sys/")) { 5725795Ssaidi@eecs.umich.edu // It's a proc/sys entery and requires special handling 5735795Ssaidi@eecs.umich.edu fd = OS::openSpecialFile(path, process, tc); 5745795Ssaidi@eecs.umich.edu return (fd == -1) ? -1 : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false); 5755795Ssaidi@eecs.umich.edu } else { 5765795Ssaidi@eecs.umich.edu // open the file 5775795Ssaidi@eecs.umich.edu fd = open(path.c_str(), hostFlags, mode); 5785795Ssaidi@eecs.umich.edu return (fd == -1) ? -errno : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false); 5795795Ssaidi@eecs.umich.edu } 580360SN/A 581360SN/A} 582360SN/A 5836640Svince@csl.cornell.edu/// Target sysinfo() handler. 5846640Svince@csl.cornell.edutemplate <class OS> 5856640Svince@csl.cornell.eduSyscallReturn 5866640Svince@csl.cornell.edusysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5876640Svince@csl.cornell.edu ThreadContext *tc) 5886640Svince@csl.cornell.edu{ 5896640Svince@csl.cornell.edu 5906701Sgblack@eecs.umich.edu int index = 0; 5916701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::tgt_sysinfo> 5926701Sgblack@eecs.umich.edu sysinfo(process->getSyscallArg(tc, index)); 5936640Svince@csl.cornell.edu 5946701Sgblack@eecs.umich.edu sysinfo->uptime=seconds_since_epoch; 5956701Sgblack@eecs.umich.edu sysinfo->totalram=process->system->memSize(); 5966640Svince@csl.cornell.edu 5976701Sgblack@eecs.umich.edu sysinfo.copyOut(tc->getMemPort()); 5986640Svince@csl.cornell.edu 5996701Sgblack@eecs.umich.edu return 0; 6006640Svince@csl.cornell.edu} 601360SN/A 6021999SN/A/// Target chmod() handler. 6031999SN/Atemplate <class OS> 6041999SN/ASyscallReturn 6053114Sgblack@eecs.umich.educhmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6062680Sktlim@umich.edu ThreadContext *tc) 6071999SN/A{ 6081999SN/A std::string path; 6091999SN/A 6106701Sgblack@eecs.umich.edu int index = 0; 6116701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 6126701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 6131999SN/A return -EFAULT; 6146701Sgblack@eecs.umich.edu } 6151999SN/A 6166701Sgblack@eecs.umich.edu uint32_t mode = process->getSyscallArg(tc, index); 6171999SN/A mode_t hostMode = 0; 6181999SN/A 6191999SN/A // XXX translate mode flags via OS::something??? 6201999SN/A hostMode = mode; 6211999SN/A 6223669Sbinkertn@umich.edu // Adjust path for current working directory 6233669Sbinkertn@umich.edu path = process->fullPath(path); 6243669Sbinkertn@umich.edu 6251999SN/A // do the chmod 6261999SN/A int result = chmod(path.c_str(), hostMode); 6271999SN/A if (result < 0) 6282218SN/A return -errno; 6291999SN/A 6301999SN/A return 0; 6311999SN/A} 6321999SN/A 6331999SN/A 6341999SN/A/// Target fchmod() handler. 6351999SN/Atemplate <class OS> 6361999SN/ASyscallReturn 6373114Sgblack@eecs.umich.edufchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 6382680Sktlim@umich.edu ThreadContext *tc) 6391999SN/A{ 6406701Sgblack@eecs.umich.edu int index = 0; 6416701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 6421999SN/A if (fd < 0 || process->sim_fd(fd) < 0) { 6431999SN/A // doesn't map to any simulator fd: not a valid target fd 6441999SN/A return -EBADF; 6451999SN/A } 6461999SN/A 6476701Sgblack@eecs.umich.edu uint32_t mode = process->getSyscallArg(tc, index); 6481999SN/A mode_t hostMode = 0; 6491999SN/A 6501999SN/A // XXX translate mode flags via OS::someting??? 6511999SN/A hostMode = mode; 6521999SN/A 6531999SN/A // do the fchmod 6541999SN/A int result = fchmod(process->sim_fd(fd), hostMode); 6551999SN/A if (result < 0) 6562218SN/A return -errno; 6571999SN/A 6581999SN/A return 0; 6591999SN/A} 6601999SN/A 6615877Shsul@eecs.umich.edu/// Target mremap() handler. 6625877Shsul@eecs.umich.edutemplate <class OS> 6635877Shsul@eecs.umich.eduSyscallReturn 6645877Shsul@eecs.umich.edumremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) 6655877Shsul@eecs.umich.edu{ 6666701Sgblack@eecs.umich.edu int index = 0; 6676701Sgblack@eecs.umich.edu Addr start = process->getSyscallArg(tc, index); 6686701Sgblack@eecs.umich.edu uint64_t old_length = process->getSyscallArg(tc, index); 6696701Sgblack@eecs.umich.edu uint64_t new_length = process->getSyscallArg(tc, index); 6706701Sgblack@eecs.umich.edu uint64_t flags = process->getSyscallArg(tc, index); 6715877Shsul@eecs.umich.edu 6725877Shsul@eecs.umich.edu if ((start % TheISA::VMPageSize != 0) || 6735877Shsul@eecs.umich.edu (new_length % TheISA::VMPageSize != 0)) { 6745877Shsul@eecs.umich.edu warn("mremap failing: arguments not page aligned"); 6755877Shsul@eecs.umich.edu return -EINVAL; 6765877Shsul@eecs.umich.edu } 6775877Shsul@eecs.umich.edu 6785877Shsul@eecs.umich.edu if (new_length > old_length) { 6795877Shsul@eecs.umich.edu if ((start + old_length) == process->mmap_end) { 6805877Shsul@eecs.umich.edu uint64_t diff = new_length - old_length; 6815877Shsul@eecs.umich.edu process->pTable->allocate(process->mmap_end, diff); 6825877Shsul@eecs.umich.edu process->mmap_end += diff; 6835877Shsul@eecs.umich.edu return start; 6845877Shsul@eecs.umich.edu } else { 6855877Shsul@eecs.umich.edu // sys/mman.h defined MREMAP_MAYMOVE 6865877Shsul@eecs.umich.edu if (!(flags & 1)) { 6875877Shsul@eecs.umich.edu warn("can't remap here and MREMAP_MAYMOVE flag not set\n"); 6885877Shsul@eecs.umich.edu return -ENOMEM; 6895877Shsul@eecs.umich.edu } else { 6905877Shsul@eecs.umich.edu process->pTable->remap(start, old_length, process->mmap_end); 6915877Shsul@eecs.umich.edu warn("mremapping to totally new vaddr %08p-%08p, adding %d\n", 6925877Shsul@eecs.umich.edu process->mmap_end, process->mmap_end + new_length, new_length); 6935877Shsul@eecs.umich.edu start = process->mmap_end; 6945877Shsul@eecs.umich.edu // add on the remaining unallocated pages 6955877Shsul@eecs.umich.edu process->pTable->allocate(start + old_length, new_length - old_length); 6965877Shsul@eecs.umich.edu process->mmap_end += new_length; 6975877Shsul@eecs.umich.edu warn("returning %08p as start\n", start); 6985877Shsul@eecs.umich.edu return start; 6995877Shsul@eecs.umich.edu } 7005877Shsul@eecs.umich.edu } 7015877Shsul@eecs.umich.edu } else { 7025877Shsul@eecs.umich.edu process->pTable->deallocate(start + new_length, old_length - 7035877Shsul@eecs.umich.edu new_length); 7045877Shsul@eecs.umich.edu return start; 7055877Shsul@eecs.umich.edu } 7065877Shsul@eecs.umich.edu} 7071999SN/A 708378SN/A/// Target stat() handler. 709360SN/Atemplate <class OS> 7101450SN/ASyscallReturn 7113114Sgblack@eecs.umich.edustatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 7122680Sktlim@umich.edu ThreadContext *tc) 713360SN/A{ 714360SN/A std::string path; 715360SN/A 7166701Sgblack@eecs.umich.edu int index = 0; 7176701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 7186701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 7196701Sgblack@eecs.umich.edu return -EFAULT; 7206701Sgblack@eecs.umich.edu } 7216701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 722360SN/A 7233669Sbinkertn@umich.edu // Adjust path for current working directory 7243669Sbinkertn@umich.edu path = process->fullPath(path); 7253669Sbinkertn@umich.edu 726360SN/A struct stat hostBuf; 727360SN/A int result = stat(path.c_str(), &hostBuf); 728360SN/A 729360SN/A if (result < 0) 7302218SN/A return -errno; 731360SN/A 7326701Sgblack@eecs.umich.edu copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf); 733360SN/A 7341458SN/A return 0; 735360SN/A} 736360SN/A 737360SN/A 7385074Ssaidi@eecs.umich.edu/// Target stat64() handler. 7395074Ssaidi@eecs.umich.edutemplate <class OS> 7405074Ssaidi@eecs.umich.eduSyscallReturn 7415074Ssaidi@eecs.umich.edustat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 7425074Ssaidi@eecs.umich.edu ThreadContext *tc) 7435074Ssaidi@eecs.umich.edu{ 7445074Ssaidi@eecs.umich.edu std::string path; 7455074Ssaidi@eecs.umich.edu 7466701Sgblack@eecs.umich.edu int index = 0; 7476701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 7486701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) 7495074Ssaidi@eecs.umich.edu return -EFAULT; 7506701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 7515074Ssaidi@eecs.umich.edu 7525074Ssaidi@eecs.umich.edu // Adjust path for current working directory 7535074Ssaidi@eecs.umich.edu path = process->fullPath(path); 7545074Ssaidi@eecs.umich.edu 7555208Ssaidi@eecs.umich.edu#if NO_STAT64 7565208Ssaidi@eecs.umich.edu struct stat hostBuf; 7575208Ssaidi@eecs.umich.edu int result = stat(path.c_str(), &hostBuf); 7585208Ssaidi@eecs.umich.edu#else 7595074Ssaidi@eecs.umich.edu struct stat64 hostBuf; 7605074Ssaidi@eecs.umich.edu int result = stat64(path.c_str(), &hostBuf); 7615208Ssaidi@eecs.umich.edu#endif 7625074Ssaidi@eecs.umich.edu 7635074Ssaidi@eecs.umich.edu if (result < 0) 7645074Ssaidi@eecs.umich.edu return -errno; 7655074Ssaidi@eecs.umich.edu 7666701Sgblack@eecs.umich.edu copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf); 7675074Ssaidi@eecs.umich.edu 7685074Ssaidi@eecs.umich.edu return 0; 7695074Ssaidi@eecs.umich.edu} 7705074Ssaidi@eecs.umich.edu 7715074Ssaidi@eecs.umich.edu 7721999SN/A/// Target fstat64() handler. 7731999SN/Atemplate <class OS> 7741999SN/ASyscallReturn 7753114Sgblack@eecs.umich.edufstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 7762680Sktlim@umich.edu ThreadContext *tc) 7771999SN/A{ 7786701Sgblack@eecs.umich.edu int index = 0; 7796701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 7806701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 7811999SN/A if (fd < 0 || process->sim_fd(fd) < 0) { 7821999SN/A // doesn't map to any simulator fd: not a valid target fd 7831999SN/A return -EBADF; 7841999SN/A } 7851999SN/A 7862764Sstever@eecs.umich.edu#if NO_STAT64 7872064SN/A struct stat hostBuf; 7882064SN/A int result = fstat(process->sim_fd(fd), &hostBuf); 7892064SN/A#else 7902064SN/A struct stat64 hostBuf; 7911999SN/A int result = fstat64(process->sim_fd(fd), &hostBuf); 7922064SN/A#endif 7931999SN/A 7941999SN/A if (result < 0) 7952218SN/A return -errno; 7961999SN/A 7976701Sgblack@eecs.umich.edu copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf, (fd == 1)); 7981999SN/A 7991999SN/A return 0; 8001999SN/A} 8011999SN/A 8021999SN/A 803378SN/A/// Target lstat() handler. 804360SN/Atemplate <class OS> 8051450SN/ASyscallReturn 8063114Sgblack@eecs.umich.edulstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 8072680Sktlim@umich.edu ThreadContext *tc) 808360SN/A{ 809360SN/A std::string path; 810360SN/A 8116701Sgblack@eecs.umich.edu int index = 0; 8126701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 8136701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 8146701Sgblack@eecs.umich.edu return -EFAULT; 8156701Sgblack@eecs.umich.edu } 8166701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 817360SN/A 8183669Sbinkertn@umich.edu // Adjust path for current working directory 8193669Sbinkertn@umich.edu path = process->fullPath(path); 8203669Sbinkertn@umich.edu 821360SN/A struct stat hostBuf; 822360SN/A int result = lstat(path.c_str(), &hostBuf); 823360SN/A 824360SN/A if (result < 0) 8251458SN/A return -errno; 826360SN/A 8276701Sgblack@eecs.umich.edu copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf); 828360SN/A 8291458SN/A return 0; 830360SN/A} 831360SN/A 8321999SN/A/// Target lstat64() handler. 8331999SN/Atemplate <class OS> 8341999SN/ASyscallReturn 8353114Sgblack@eecs.umich.edulstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 8362680Sktlim@umich.edu ThreadContext *tc) 8371999SN/A{ 8381999SN/A std::string path; 8391999SN/A 8406701Sgblack@eecs.umich.edu int index = 0; 8416701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 8426701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 8436701Sgblack@eecs.umich.edu return -EFAULT; 8446701Sgblack@eecs.umich.edu } 8456701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 8461999SN/A 8473669Sbinkertn@umich.edu // Adjust path for current working directory 8483669Sbinkertn@umich.edu path = process->fullPath(path); 8493669Sbinkertn@umich.edu 8502764Sstever@eecs.umich.edu#if NO_STAT64 8512064SN/A struct stat hostBuf; 8522064SN/A int result = lstat(path.c_str(), &hostBuf); 8532064SN/A#else 8541999SN/A struct stat64 hostBuf; 8551999SN/A int result = lstat64(path.c_str(), &hostBuf); 8562064SN/A#endif 8571999SN/A 8581999SN/A if (result < 0) 8591999SN/A return -errno; 8601999SN/A 8616701Sgblack@eecs.umich.edu copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf); 8621999SN/A 8631999SN/A return 0; 8641999SN/A} 8651999SN/A 866378SN/A/// Target fstat() handler. 867360SN/Atemplate <class OS> 8681450SN/ASyscallReturn 8693114Sgblack@eecs.umich.edufstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 8702680Sktlim@umich.edu ThreadContext *tc) 871360SN/A{ 8726701Sgblack@eecs.umich.edu int index = 0; 8736701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 8746701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 875360SN/A 8761969SN/A DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd); 877360SN/A 878360SN/A if (fd < 0) 8791458SN/A return -EBADF; 880360SN/A 881360SN/A struct stat hostBuf; 882360SN/A int result = fstat(fd, &hostBuf); 883360SN/A 884360SN/A if (result < 0) 8851458SN/A return -errno; 886360SN/A 8876701Sgblack@eecs.umich.edu copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf, (fd == 1)); 8882021SN/A 8891458SN/A return 0; 890360SN/A} 891360SN/A 892360SN/A 8931706SN/A/// Target statfs() handler. 8941706SN/Atemplate <class OS> 8951706SN/ASyscallReturn 8963114Sgblack@eecs.umich.edustatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 8972680Sktlim@umich.edu ThreadContext *tc) 8981706SN/A{ 8991706SN/A std::string path; 9001706SN/A 9016701Sgblack@eecs.umich.edu int index = 0; 9026701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 9036701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 9046701Sgblack@eecs.umich.edu return -EFAULT; 9056701Sgblack@eecs.umich.edu } 9066701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 9071706SN/A 9083669Sbinkertn@umich.edu // Adjust path for current working directory 9093669Sbinkertn@umich.edu path = process->fullPath(path); 9103669Sbinkertn@umich.edu 9111706SN/A struct statfs hostBuf; 9121706SN/A int result = statfs(path.c_str(), &hostBuf); 9131706SN/A 9141706SN/A if (result < 0) 9152218SN/A return -errno; 9161706SN/A 9176701Sgblack@eecs.umich.edu OS::copyOutStatfsBuf(tc->getMemPort(), bufPtr, &hostBuf); 9181706SN/A 9191706SN/A return 0; 9201706SN/A} 9211706SN/A 9221706SN/A 9231706SN/A/// Target fstatfs() handler. 9241706SN/Atemplate <class OS> 9251706SN/ASyscallReturn 9263114Sgblack@eecs.umich.edufstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 9272680Sktlim@umich.edu ThreadContext *tc) 9281706SN/A{ 9296701Sgblack@eecs.umich.edu int index = 0; 9306701Sgblack@eecs.umich.edu int fd = process->sim_fd(process->getSyscallArg(tc, index)); 9316701Sgblack@eecs.umich.edu Addr bufPtr = process->getSyscallArg(tc, index); 9321706SN/A 9331706SN/A if (fd < 0) 9341706SN/A return -EBADF; 9351706SN/A 9361706SN/A struct statfs hostBuf; 9371706SN/A int result = fstatfs(fd, &hostBuf); 9381706SN/A 9391706SN/A if (result < 0) 9402218SN/A return -errno; 9411706SN/A 9426701Sgblack@eecs.umich.edu OS::copyOutStatfsBuf(tc->getMemPort(), bufPtr, &hostBuf); 9431706SN/A 9441706SN/A return 0; 9451706SN/A} 9461706SN/A 9471706SN/A 9481999SN/A/// Target writev() handler. 9491999SN/Atemplate <class OS> 9501999SN/ASyscallReturn 9513114Sgblack@eecs.umich.eduwritevFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 9522680Sktlim@umich.edu ThreadContext *tc) 9531999SN/A{ 9546701Sgblack@eecs.umich.edu int index = 0; 9556701Sgblack@eecs.umich.edu int fd = process->getSyscallArg(tc, index); 9561999SN/A if (fd < 0 || process->sim_fd(fd) < 0) { 9571999SN/A // doesn't map to any simulator fd: not a valid target fd 9581999SN/A return -EBADF; 9591999SN/A } 9601999SN/A 9612680Sktlim@umich.edu TranslatingPort *p = tc->getMemPort(); 9626701Sgblack@eecs.umich.edu uint64_t tiov_base = process->getSyscallArg(tc, index); 9636701Sgblack@eecs.umich.edu size_t count = process->getSyscallArg(tc, index); 9641999SN/A struct iovec hiov[count]; 9656227Snate@binkert.org for (size_t i = 0; i < count; ++i) { 9661999SN/A typename OS::tgt_iovec tiov; 9672461SN/A 9682461SN/A p->readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec), 9692461SN/A (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec)); 9702091SN/A hiov[i].iov_len = gtoh(tiov.iov_len); 9711999SN/A hiov[i].iov_base = new char [hiov[i].iov_len]; 9722461SN/A p->readBlob(gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base, 9732461SN/A hiov[i].iov_len); 9741999SN/A } 9751999SN/A 9761999SN/A int result = writev(process->sim_fd(fd), hiov, count); 9771999SN/A 9786227Snate@binkert.org for (size_t i = 0; i < count; ++i) 9791999SN/A delete [] (char *)hiov[i].iov_base; 9801999SN/A 9811999SN/A if (result < 0) 9822218SN/A return -errno; 9831999SN/A 9841999SN/A return 0; 9851999SN/A} 9861999SN/A 9871999SN/A 988378SN/A/// Target mmap() handler. 989378SN/A/// 990378SN/A/// We don't really handle mmap(). If the target is mmaping an 991378SN/A/// anonymous region or /dev/zero, we can get away with doing basically 992378SN/A/// nothing (since memory is initialized to zero and the simulator 9938324Ssteve.reinhardt@amd.com/// doesn't really check addresses anyway). 9948324Ssteve.reinhardt@amd.com/// 995360SN/Atemplate <class OS> 9961450SN/ASyscallReturn 9973114Sgblack@eecs.umich.edummapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 998360SN/A{ 9996701Sgblack@eecs.umich.edu int index = 0; 10006701Sgblack@eecs.umich.edu Addr start = p->getSyscallArg(tc, index); 10016701Sgblack@eecs.umich.edu uint64_t length = p->getSyscallArg(tc, index); 10026701Sgblack@eecs.umich.edu index++; // int prot = p->getSyscallArg(tc, index); 10036701Sgblack@eecs.umich.edu int flags = p->getSyscallArg(tc, index); 10048324Ssteve.reinhardt@amd.com int tgt_fd = p->getSyscallArg(tc, index); 10056701Sgblack@eecs.umich.edu // int offset = p->getSyscallArg(tc, index); 1006360SN/A 10078324Ssteve.reinhardt@amd.com if (!(flags & OS::TGT_MAP_ANONYMOUS)) { 10088324Ssteve.reinhardt@amd.com Process::FdMap *fd_map = p->sim_fd_obj(tgt_fd); 10098324Ssteve.reinhardt@amd.com if (!fd_map || fd_map->fd < 0) { 10108324Ssteve.reinhardt@amd.com warn("mmap failing: target fd %d is not valid\n", tgt_fd); 10118324Ssteve.reinhardt@amd.com return -EBADF; 10128324Ssteve.reinhardt@amd.com } 10138324Ssteve.reinhardt@amd.com 10148324Ssteve.reinhardt@amd.com if (fd_map->filename != "/dev/zero") { 10158324Ssteve.reinhardt@amd.com // This is very likely broken, but leave a warning here 10168324Ssteve.reinhardt@amd.com // (rather than panic) in case /dev/zero is known by 10178324Ssteve.reinhardt@amd.com // another name on some platform 10188324Ssteve.reinhardt@amd.com warn("allowing mmap of file %s; mmap not supported on files" 10198324Ssteve.reinhardt@amd.com " other than /dev/zero\n", fd_map->filename); 10208324Ssteve.reinhardt@amd.com } 10218324Ssteve.reinhardt@amd.com } 10225877Shsul@eecs.umich.edu 10232544SN/A if ((start % TheISA::VMPageSize) != 0 || 10242544SN/A (length % TheISA::VMPageSize) != 0) { 10252544SN/A warn("mmap failing: arguments not page-aligned: " 10262544SN/A "start 0x%x length 0x%x", 10272544SN/A start, length); 10282544SN/A return -EINVAL; 1029360SN/A } 1030360SN/A 10312544SN/A if (start != 0) { 10322544SN/A warn("mmap: ignoring suggested map address 0x%x, using 0x%x", 10332544SN/A start, p->mmap_end); 10342544SN/A } 10352544SN/A 10362544SN/A // pick next address from our "mmap region" 10376672Sgblack@eecs.umich.edu if (OS::mmapGrowsDown()) { 10386672Sgblack@eecs.umich.edu start = p->mmap_end - length; 10396672Sgblack@eecs.umich.edu p->mmap_end = start; 10406672Sgblack@eecs.umich.edu } else { 10416672Sgblack@eecs.umich.edu start = p->mmap_end; 10426672Sgblack@eecs.umich.edu p->mmap_end += length; 10436672Sgblack@eecs.umich.edu } 10442544SN/A p->pTable->allocate(start, length); 10452544SN/A 10461458SN/A return start; 1047360SN/A} 1048360SN/A 1049378SN/A/// Target getrlimit() handler. 1050360SN/Atemplate <class OS> 10511450SN/ASyscallReturn 10523114Sgblack@eecs.umich.edugetrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 10532680Sktlim@umich.edu ThreadContext *tc) 1054360SN/A{ 10556701Sgblack@eecs.umich.edu int index = 0; 10566701Sgblack@eecs.umich.edu unsigned resource = process->getSyscallArg(tc, index); 10576701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index)); 1058360SN/A 1059360SN/A switch (resource) { 10602064SN/A case OS::TGT_RLIMIT_STACK: 10615877Shsul@eecs.umich.edu // max stack size in bytes: make up a number (8MB for now) 10622064SN/A rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024; 10632091SN/A rlp->rlim_cur = htog(rlp->rlim_cur); 10642091SN/A rlp->rlim_max = htog(rlp->rlim_max); 10652064SN/A break; 1066360SN/A 10675877Shsul@eecs.umich.edu case OS::TGT_RLIMIT_DATA: 10685877Shsul@eecs.umich.edu // max data segment size in bytes: make up a number 10695877Shsul@eecs.umich.edu rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024; 10705877Shsul@eecs.umich.edu rlp->rlim_cur = htog(rlp->rlim_cur); 10715877Shsul@eecs.umich.edu rlp->rlim_max = htog(rlp->rlim_max); 10725877Shsul@eecs.umich.edu break; 10735877Shsul@eecs.umich.edu 10742064SN/A default: 10752064SN/A std::cerr << "getrlimitFunc: unimplemented resource " << resource 10762064SN/A << std::endl; 10772064SN/A abort(); 10782064SN/A break; 1079360SN/A } 1080360SN/A 10812680Sktlim@umich.edu rlp.copyOut(tc->getMemPort()); 10821458SN/A return 0; 1083360SN/A} 1084360SN/A 1085378SN/A/// Target gettimeofday() handler. 1086360SN/Atemplate <class OS> 10871450SN/ASyscallReturn 10883114Sgblack@eecs.umich.edugettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 10892680Sktlim@umich.edu ThreadContext *tc) 1090360SN/A{ 10916701Sgblack@eecs.umich.edu int index = 0; 10926701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index)); 1093360SN/A 1094360SN/A getElapsedTime(tp->tv_sec, tp->tv_usec); 1095360SN/A tp->tv_sec += seconds_since_epoch; 10966109Ssanchezd@stanford.edu tp->tv_sec = TheISA::htog(tp->tv_sec); 10976109Ssanchezd@stanford.edu tp->tv_usec = TheISA::htog(tp->tv_usec); 1098360SN/A 10992680Sktlim@umich.edu tp.copyOut(tc->getMemPort()); 1100360SN/A 11011458SN/A return 0; 1102360SN/A} 1103360SN/A 1104360SN/A 11051999SN/A/// Target utimes() handler. 11061999SN/Atemplate <class OS> 11071999SN/ASyscallReturn 11083114Sgblack@eecs.umich.eduutimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 11092680Sktlim@umich.edu ThreadContext *tc) 11101999SN/A{ 11111999SN/A std::string path; 11121999SN/A 11136701Sgblack@eecs.umich.edu int index = 0; 11146701Sgblack@eecs.umich.edu if (!tc->getMemPort()->tryReadString(path, 11156701Sgblack@eecs.umich.edu process->getSyscallArg(tc, index))) { 11166701Sgblack@eecs.umich.edu return -EFAULT; 11176701Sgblack@eecs.umich.edu } 11181999SN/A 11196701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::timeval [2]> 11206701Sgblack@eecs.umich.edu tp(process->getSyscallArg(tc, index)); 11212680Sktlim@umich.edu tp.copyIn(tc->getMemPort()); 11221999SN/A 11231999SN/A struct timeval hostTimeval[2]; 11241999SN/A for (int i = 0; i < 2; ++i) 11251999SN/A { 11262091SN/A hostTimeval[i].tv_sec = gtoh((*tp)[i].tv_sec); 11272091SN/A hostTimeval[i].tv_usec = gtoh((*tp)[i].tv_usec); 11281999SN/A } 11293669Sbinkertn@umich.edu 11303669Sbinkertn@umich.edu // Adjust path for current working directory 11313669Sbinkertn@umich.edu path = process->fullPath(path); 11323669Sbinkertn@umich.edu 11331999SN/A int result = utimes(path.c_str(), hostTimeval); 11341999SN/A 11351999SN/A if (result < 0) 11361999SN/A return -errno; 11371999SN/A 11381999SN/A return 0; 11391999SN/A} 1140378SN/A/// Target getrusage() function. 1141360SN/Atemplate <class OS> 11421450SN/ASyscallReturn 11433114Sgblack@eecs.umich.edugetrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 11442680Sktlim@umich.edu ThreadContext *tc) 1145360SN/A{ 11466701Sgblack@eecs.umich.edu int index = 0; 11476701Sgblack@eecs.umich.edu int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN 11486701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index)); 1149360SN/A 11503670Sbinkertn@umich.edu rup->ru_utime.tv_sec = 0; 11513670Sbinkertn@umich.edu rup->ru_utime.tv_usec = 0; 1152360SN/A rup->ru_stime.tv_sec = 0; 1153360SN/A rup->ru_stime.tv_usec = 0; 1154360SN/A rup->ru_maxrss = 0; 1155360SN/A rup->ru_ixrss = 0; 1156360SN/A rup->ru_idrss = 0; 1157360SN/A rup->ru_isrss = 0; 1158360SN/A rup->ru_minflt = 0; 1159360SN/A rup->ru_majflt = 0; 1160360SN/A rup->ru_nswap = 0; 1161360SN/A rup->ru_inblock = 0; 1162360SN/A rup->ru_oublock = 0; 1163360SN/A rup->ru_msgsnd = 0; 1164360SN/A rup->ru_msgrcv = 0; 1165360SN/A rup->ru_nsignals = 0; 1166360SN/A rup->ru_nvcsw = 0; 1167360SN/A rup->ru_nivcsw = 0; 1168360SN/A 11693670Sbinkertn@umich.edu switch (who) { 11703670Sbinkertn@umich.edu case OS::TGT_RUSAGE_SELF: 11713670Sbinkertn@umich.edu getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec); 11723670Sbinkertn@umich.edu rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec); 11733670Sbinkertn@umich.edu rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec); 11743670Sbinkertn@umich.edu break; 11753670Sbinkertn@umich.edu 11763670Sbinkertn@umich.edu case OS::TGT_RUSAGE_CHILDREN: 11773670Sbinkertn@umich.edu // do nothing. We have no child processes, so they take no time. 11783670Sbinkertn@umich.edu break; 11793670Sbinkertn@umich.edu 11803670Sbinkertn@umich.edu default: 11813670Sbinkertn@umich.edu // don't really handle THREAD or CHILDREN, but just warn and 11823670Sbinkertn@umich.edu // plow ahead 11833670Sbinkertn@umich.edu warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.", 11843670Sbinkertn@umich.edu who); 11853670Sbinkertn@umich.edu } 11863670Sbinkertn@umich.edu 11872680Sktlim@umich.edu rup.copyOut(tc->getMemPort()); 1188360SN/A 11891458SN/A return 0; 1190360SN/A} 1191360SN/A 11926683Stjones1@inf.ed.ac.uk/// Target times() function. 11936683Stjones1@inf.ed.ac.uktemplate <class OS> 11946683Stjones1@inf.ed.ac.ukSyscallReturn 11956683Stjones1@inf.ed.ac.uktimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 11966683Stjones1@inf.ed.ac.uk ThreadContext *tc) 11976683Stjones1@inf.ed.ac.uk{ 11986701Sgblack@eecs.umich.edu int index = 0; 11996701Sgblack@eecs.umich.edu TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index)); 12006683Stjones1@inf.ed.ac.uk 12016683Stjones1@inf.ed.ac.uk // Fill in the time structure (in clocks) 12027823Ssteve.reinhardt@amd.com int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s; 12036683Stjones1@inf.ed.ac.uk bufp->tms_utime = clocks; 12046683Stjones1@inf.ed.ac.uk bufp->tms_stime = 0; 12056683Stjones1@inf.ed.ac.uk bufp->tms_cutime = 0; 12066683Stjones1@inf.ed.ac.uk bufp->tms_cstime = 0; 12076683Stjones1@inf.ed.ac.uk 12086683Stjones1@inf.ed.ac.uk // Convert to host endianness 12096683Stjones1@inf.ed.ac.uk bufp->tms_utime = htog(bufp->tms_utime); 12106683Stjones1@inf.ed.ac.uk 12116683Stjones1@inf.ed.ac.uk // Write back 12126683Stjones1@inf.ed.ac.uk bufp.copyOut(tc->getMemPort()); 12136683Stjones1@inf.ed.ac.uk 12146683Stjones1@inf.ed.ac.uk // Return clock ticks since system boot 12156683Stjones1@inf.ed.ac.uk return clocks; 12166683Stjones1@inf.ed.ac.uk} 12172553SN/A 12186684Stjones1@inf.ed.ac.uk/// Target time() function. 12196684Stjones1@inf.ed.ac.uktemplate <class OS> 12206684Stjones1@inf.ed.ac.ukSyscallReturn 12216684Stjones1@inf.ed.ac.uktimeFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 12226684Stjones1@inf.ed.ac.uk ThreadContext *tc) 12236684Stjones1@inf.ed.ac.uk{ 12246684Stjones1@inf.ed.ac.uk typename OS::time_t sec, usec; 12256684Stjones1@inf.ed.ac.uk getElapsedTime(sec, usec); 12266684Stjones1@inf.ed.ac.uk sec += seconds_since_epoch; 12276684Stjones1@inf.ed.ac.uk 12286701Sgblack@eecs.umich.edu int index = 0; 12296701Sgblack@eecs.umich.edu Addr taddr = (Addr)process->getSyscallArg(tc, index); 12306684Stjones1@inf.ed.ac.uk if(taddr != 0) { 12316684Stjones1@inf.ed.ac.uk typename OS::time_t t = sec; 12326684Stjones1@inf.ed.ac.uk t = htog(t); 12336684Stjones1@inf.ed.ac.uk TranslatingPort *p = tc->getMemPort(); 12346684Stjones1@inf.ed.ac.uk p->writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t)); 12356684Stjones1@inf.ed.ac.uk } 12366684Stjones1@inf.ed.ac.uk return sec; 12376684Stjones1@inf.ed.ac.uk} 12382553SN/A 12392553SN/A 12401354SN/A#endif // __SIM_SYSCALL_EMUL_HH__ 1241