syscall_emul.cc revision 4118
1360SN/A/* 21458SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 3360SN/A * All rights reserved. 4360SN/A * 5360SN/A * Redistribution and use in source and binary forms, with or without 6360SN/A * modification, are permitted provided that the following conditions are 7360SN/A * met: redistributions of source code must retain the above copyright 8360SN/A * notice, this list of conditions and the following disclaimer; 9360SN/A * redistributions in binary form must reproduce the above copyright 10360SN/A * notice, this list of conditions and the following disclaimer in the 11360SN/A * documentation and/or other materials provided with the distribution; 12360SN/A * neither the name of the copyright holders nor the names of its 13360SN/A * contributors may be used to endorse or promote products derived from 14360SN/A * this software without specific prior written permission. 15360SN/A * 16360SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17360SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18360SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19360SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20360SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21360SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22360SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23360SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24360SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25360SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26360SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Ali Saidi 30360SN/A */ 31360SN/A 322093SN/A#include <fcntl.h> 33360SN/A#include <unistd.h> 34360SN/A 35360SN/A#include <string> 36360SN/A#include <iostream> 37360SN/A 38360SN/A#include "sim/syscall_emul.hh" 392474SN/A#include "base/chunk_generator.hh" 40360SN/A#include "base/trace.hh" 412680Sktlim@umich.edu#include "cpu/thread_context.hh" 421717SN/A#include "cpu/base.hh" 432474SN/A#include "mem/page_table.hh" 44360SN/A#include "sim/process.hh" 45360SN/A 462667Sstever@eecs.umich.edu#include "sim/sim_exit.hh" 47360SN/A 48360SN/Ausing namespace std; 492107SN/Ausing namespace TheISA; 50360SN/A 51360SN/Avoid 523114Sgblack@eecs.umich.eduSyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) 53360SN/A{ 542495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", 552680Sktlim@umich.edu curTick,tc->getCpuPtr()->name(), name, 562680Sktlim@umich.edu tc->getSyscallArg(0),tc->getSyscallArg(1), 572680Sktlim@umich.edu tc->getSyscallArg(2),tc->getSyscallArg(3)); 58360SN/A 592680Sktlim@umich.edu SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); 60360SN/A 612495SN/A DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", 622680Sktlim@umich.edu curTick,tc->getCpuPtr()->name(), name, retval.value()); 63360SN/A 641450SN/A if (!(flags & SyscallDesc::SuppressReturnValue)) 652680Sktlim@umich.edu tc->setSyscallReturn(retval); 66360SN/A} 67360SN/A 68360SN/A 691450SN/ASyscallReturn 703114Sgblack@eecs.umich.eduunimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 712680Sktlim@umich.edu ThreadContext *tc) 72360SN/A{ 731969SN/A fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); 742484SN/A 752484SN/A return 1; 76360SN/A} 77360SN/A 78360SN/A 791450SN/ASyscallReturn 803114Sgblack@eecs.umich.eduignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 812680Sktlim@umich.edu ThreadContext *tc) 82360SN/A{ 831969SN/A warn("ignoring syscall %s(%d, %d, ...)", desc->name, 842680Sktlim@umich.edu tc->getSyscallArg(0), tc->getSyscallArg(1)); 85360SN/A 861458SN/A return 0; 87360SN/A} 88360SN/A 89360SN/A 901450SN/ASyscallReturn 913114Sgblack@eecs.umich.eduexitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 922680Sktlim@umich.edu ThreadContext *tc) 93360SN/A{ 942834Sksewell@umich.edu if (tc->exit()) { 952834Sksewell@umich.edu exitSimLoop("target called exit()", tc->getSyscallArg(0) & 0xff); 962834Sksewell@umich.edu } 97360SN/A 981458SN/A return 1; 99360SN/A} 100360SN/A 101360SN/A 1021450SN/ASyscallReturn 1033114Sgblack@eecs.umich.edugetpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 104360SN/A{ 1052107SN/A return (int)VMPageSize; 106360SN/A} 107360SN/A 108360SN/A 1091450SN/ASyscallReturn 1103114Sgblack@eecs.umich.eduobreakFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 111360SN/A{ 1122474SN/A Addr junk; 1132474SN/A 114360SN/A // change brk addr to first arg 1152680Sktlim@umich.edu Addr new_brk = tc->getSyscallArg(0); 1162474SN/A if (new_brk != 0) { 1172474SN/A for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, 1182474SN/A VMPageSize); !gen.done(); gen.next()) { 1192474SN/A if (!p->pTable->translate(gen.addr(), junk)) 1202474SN/A p->pTable->allocate(roundDown(gen.addr(), VMPageSize), 1212474SN/A VMPageSize); 1222474SN/A } 1232474SN/A p->brk_point = new_brk; 1241450SN/A } 1251458SN/A DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); 1261458SN/A return p->brk_point; 127360SN/A} 128360SN/A 129360SN/A 1301450SN/ASyscallReturn 1313114Sgblack@eecs.umich.educloseFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 132360SN/A{ 1332680Sktlim@umich.edu int target_fd = tc->getSyscallArg(0); 1341970SN/A int status = close(p->sim_fd(target_fd)); 1351970SN/A if (status >= 0) 1361970SN/A p->free_fd(target_fd); 1371970SN/A return status; 138360SN/A} 139360SN/A 140360SN/A 1411450SN/ASyscallReturn 1423114Sgblack@eecs.umich.edureadFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 143360SN/A{ 1442680Sktlim@umich.edu int fd = p->sim_fd(tc->getSyscallArg(0)); 1452680Sktlim@umich.edu int nbytes = tc->getSyscallArg(2); 1462680Sktlim@umich.edu BufferArg bufArg(tc->getSyscallArg(1), nbytes); 147360SN/A 148360SN/A int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); 149360SN/A 150360SN/A if (bytes_read != -1) 1512680Sktlim@umich.edu bufArg.copyOut(tc->getMemPort()); 152360SN/A 1531458SN/A return bytes_read; 154360SN/A} 155360SN/A 1561450SN/ASyscallReturn 1573114Sgblack@eecs.umich.eduwriteFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 158360SN/A{ 1592680Sktlim@umich.edu int fd = p->sim_fd(tc->getSyscallArg(0)); 1602680Sktlim@umich.edu int nbytes = tc->getSyscallArg(2); 1612680Sktlim@umich.edu BufferArg bufArg(tc->getSyscallArg(1), nbytes); 162360SN/A 1632680Sktlim@umich.edu bufArg.copyIn(tc->getMemPort()); 164360SN/A 165360SN/A int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); 166360SN/A 167360SN/A fsync(fd); 168360SN/A 1691458SN/A return bytes_written; 170360SN/A} 171360SN/A 172360SN/A 1731450SN/ASyscallReturn 1743114Sgblack@eecs.umich.edulseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 175360SN/A{ 1762680Sktlim@umich.edu int fd = p->sim_fd(tc->getSyscallArg(0)); 1772680Sktlim@umich.edu uint64_t offs = tc->getSyscallArg(1); 1782680Sktlim@umich.edu int whence = tc->getSyscallArg(2); 179360SN/A 180360SN/A off_t result = lseek(fd, offs, whence); 181360SN/A 1821458SN/A return (result == (off_t)-1) ? -errno : result; 183360SN/A} 184360SN/A 185360SN/A 1861450SN/ASyscallReturn 1874118Sgblack@eecs.umich.edu_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 1884118Sgblack@eecs.umich.edu{ 1894118Sgblack@eecs.umich.edu int fd = p->sim_fd(tc->getSyscallArg(0)); 1904118Sgblack@eecs.umich.edu uint64_t offset_high = tc->getSyscallArg(1); 1914118Sgblack@eecs.umich.edu uint32_t offset_low = tc->getSyscallArg(2); 1924118Sgblack@eecs.umich.edu Addr result_ptr = tc->getSyscallArg(3); 1934118Sgblack@eecs.umich.edu int whence = tc->getSyscallArg(4); 1944118Sgblack@eecs.umich.edu 1954118Sgblack@eecs.umich.edu uint64_t offset = (offset_high << 32) | offset_low; 1964118Sgblack@eecs.umich.edu 1974118Sgblack@eecs.umich.edu uint64_t result = lseek(fd, offset, whence); 1984118Sgblack@eecs.umich.edu result = TheISA::htog(result); 1994118Sgblack@eecs.umich.edu 2004118Sgblack@eecs.umich.edu if (result == (off_t)-1) { 2014118Sgblack@eecs.umich.edu //The seek failed. 2024118Sgblack@eecs.umich.edu return -errno; 2034118Sgblack@eecs.umich.edu } else { 2044118Sgblack@eecs.umich.edu //The seek succeeded. 2054118Sgblack@eecs.umich.edu //Copy "result" to "result_ptr" 2064118Sgblack@eecs.umich.edu //XXX We'll assume that the size of loff_t is 64 bits on the 2074118Sgblack@eecs.umich.edu //target platform 2084118Sgblack@eecs.umich.edu BufferArg result_buf(result_ptr, sizeof(result)); 2094118Sgblack@eecs.umich.edu memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 2104118Sgblack@eecs.umich.edu result_buf.copyOut(tc->getMemPort()); 2114118Sgblack@eecs.umich.edu return 0; 2124118Sgblack@eecs.umich.edu } 2134118Sgblack@eecs.umich.edu 2144118Sgblack@eecs.umich.edu 2154118Sgblack@eecs.umich.edu return (result == (off_t)-1) ? -errno : result; 2164118Sgblack@eecs.umich.edu} 2174118Sgblack@eecs.umich.edu 2184118Sgblack@eecs.umich.edu 2194118Sgblack@eecs.umich.eduSyscallReturn 2203114Sgblack@eecs.umich.edumunmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 221360SN/A{ 222360SN/A // given that we don't really implement mmap, munmap is really easy 2231458SN/A return 0; 224360SN/A} 225360SN/A 226360SN/A 227360SN/Aconst char *hostname = "m5.eecs.umich.edu"; 228360SN/A 2291450SN/ASyscallReturn 2303114Sgblack@eecs.umich.edugethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 231360SN/A{ 2322680Sktlim@umich.edu int name_len = tc->getSyscallArg(1); 2332680Sktlim@umich.edu BufferArg name(tc->getSyscallArg(0), name_len); 234360SN/A 235360SN/A strncpy((char *)name.bufferPtr(), hostname, name_len); 236360SN/A 2372680Sktlim@umich.edu name.copyOut(tc->getMemPort()); 238360SN/A 2391458SN/A return 0; 240360SN/A} 241360SN/A 2421450SN/ASyscallReturn 2433114Sgblack@eecs.umich.eduunlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 244511SN/A{ 2451706SN/A string path; 246360SN/A 2472680Sktlim@umich.edu if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) 2481450SN/A return (TheISA::IntReg)-EFAULT; 249511SN/A 2503669Sbinkertn@umich.edu // Adjust path for current working directory 2513669Sbinkertn@umich.edu path = p->fullPath(path); 2523669Sbinkertn@umich.edu 253511SN/A int result = unlink(path.c_str()); 2541458SN/A return (result == -1) ? -errno : result; 255511SN/A} 256511SN/A 2571450SN/ASyscallReturn 2583114Sgblack@eecs.umich.edurenameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 259511SN/A{ 2601706SN/A string old_name; 261511SN/A 2622680Sktlim@umich.edu if (!tc->getMemPort()->tryReadString(old_name, tc->getSyscallArg(0))) 2631458SN/A return -EFAULT; 264511SN/A 2651706SN/A string new_name; 266511SN/A 2672680Sktlim@umich.edu if (!tc->getMemPort()->tryReadString(new_name, tc->getSyscallArg(1))) 2681458SN/A return -EFAULT; 269511SN/A 2703669Sbinkertn@umich.edu // Adjust path for current working directory 2713669Sbinkertn@umich.edu old_name = p->fullPath(old_name); 2723669Sbinkertn@umich.edu new_name = p->fullPath(new_name); 2733669Sbinkertn@umich.edu 2741706SN/A int64_t result = rename(old_name.c_str(), new_name.c_str()); 2751458SN/A return (result == -1) ? -errno : result; 276511SN/A} 277511SN/A 2781706SN/ASyscallReturn 2793114Sgblack@eecs.umich.edutruncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 2801706SN/A{ 2811706SN/A string path; 2821706SN/A 2832680Sktlim@umich.edu if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) 2841706SN/A return -EFAULT; 2851706SN/A 2862680Sktlim@umich.edu off_t length = tc->getSyscallArg(1); 2871706SN/A 2883669Sbinkertn@umich.edu // Adjust path for current working directory 2893669Sbinkertn@umich.edu path = p->fullPath(path); 2903669Sbinkertn@umich.edu 2911706SN/A int result = truncate(path.c_str(), length); 2921706SN/A return (result == -1) ? -errno : result; 2931706SN/A} 2941706SN/A 2951706SN/ASyscallReturn 2963114Sgblack@eecs.umich.eduftruncateFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 2971706SN/A{ 2982680Sktlim@umich.edu int fd = process->sim_fd(tc->getSyscallArg(0)); 2991706SN/A 3001706SN/A if (fd < 0) 3011706SN/A return -EBADF; 3021706SN/A 3032680Sktlim@umich.edu off_t length = tc->getSyscallArg(1); 3041706SN/A 3051706SN/A int result = ftruncate(fd, length); 3061706SN/A return (result == -1) ? -errno : result; 3071706SN/A} 3081999SN/A 3091999SN/ASyscallReturn 3103114Sgblack@eecs.umich.educhownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 3111999SN/A{ 3121999SN/A string path; 3131999SN/A 3142680Sktlim@umich.edu if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) 3151999SN/A return -EFAULT; 3161999SN/A 3171999SN/A /* XXX endianess */ 3182680Sktlim@umich.edu uint32_t owner = tc->getSyscallArg(1); 3191999SN/A uid_t hostOwner = owner; 3202680Sktlim@umich.edu uint32_t group = tc->getSyscallArg(2); 3211999SN/A gid_t hostGroup = group; 3221999SN/A 3233669Sbinkertn@umich.edu // Adjust path for current working directory 3243669Sbinkertn@umich.edu path = p->fullPath(path); 3253669Sbinkertn@umich.edu 3261999SN/A int result = chown(path.c_str(), hostOwner, hostGroup); 3271999SN/A return (result == -1) ? -errno : result; 3281999SN/A} 3291999SN/A 3301999SN/ASyscallReturn 3313114Sgblack@eecs.umich.edufchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 3321999SN/A{ 3332680Sktlim@umich.edu int fd = process->sim_fd(tc->getSyscallArg(0)); 3341999SN/A 3351999SN/A if (fd < 0) 3361999SN/A return -EBADF; 3371999SN/A 3381999SN/A /* XXX endianess */ 3392680Sktlim@umich.edu uint32_t owner = tc->getSyscallArg(1); 3401999SN/A uid_t hostOwner = owner; 3412680Sktlim@umich.edu uint32_t group = tc->getSyscallArg(2); 3421999SN/A gid_t hostGroup = group; 3431999SN/A 3441999SN/A int result = fchown(fd, hostOwner, hostGroup); 3451999SN/A return (result == -1) ? -errno : result; 3461999SN/A} 3472093SN/A 3482093SN/A 3492093SN/ASyscallReturn 3503114Sgblack@eecs.umich.edudupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) 3513079Sstever@eecs.umich.edu{ 3523079Sstever@eecs.umich.edu int fd = process->sim_fd(tc->getSyscallArg(0)); 3533079Sstever@eecs.umich.edu 3543079Sstever@eecs.umich.edu if (fd < 0) 3553079Sstever@eecs.umich.edu return -EBADF; 3563079Sstever@eecs.umich.edu 3573079Sstever@eecs.umich.edu int result = dup(fd); 3583079Sstever@eecs.umich.edu return (result == -1) ? -errno : process->alloc_fd(result); 3593079Sstever@eecs.umich.edu} 3603079Sstever@eecs.umich.edu 3613079Sstever@eecs.umich.edu 3623079Sstever@eecs.umich.eduSyscallReturn 3633114Sgblack@eecs.umich.edufcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, 3642680Sktlim@umich.edu ThreadContext *tc) 3652093SN/A{ 3662680Sktlim@umich.edu int fd = tc->getSyscallArg(0); 3672093SN/A 3682093SN/A if (fd < 0 || process->sim_fd(fd) < 0) 3692093SN/A return -EBADF; 3702093SN/A 3712680Sktlim@umich.edu int cmd = tc->getSyscallArg(1); 3722093SN/A switch (cmd) { 3732093SN/A case 0: // F_DUPFD 3742093SN/A // if we really wanted to support this, we'd need to do it 3752093SN/A // in the target fd space. 3762093SN/A warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); 3772093SN/A return -EMFILE; 3782093SN/A 3792093SN/A case 1: // F_GETFD (get close-on-exec flag) 3802093SN/A case 2: // F_SETFD (set close-on-exec flag) 3812093SN/A return 0; 3822093SN/A 3832093SN/A case 3: // F_GETFL (get file flags) 3842093SN/A case 4: // F_SETFL (set file flags) 3852093SN/A // not sure if this is totally valid, but we'll pass it through 3862093SN/A // to the underlying OS 3872093SN/A warn("fcntl(%d, %d) passed through to host\n", fd, cmd); 3882093SN/A return fcntl(process->sim_fd(fd), cmd); 3892093SN/A // return 0; 3902093SN/A 3912093SN/A case 7: // F_GETLK (get lock) 3922093SN/A case 8: // F_SETLK (set lock) 3932093SN/A case 9: // F_SETLKW (set lock and wait) 3942093SN/A // don't mess with file locking... just act like it's OK 3952093SN/A warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); 3962093SN/A return 0; 3972093SN/A 3982093SN/A default: 3992093SN/A warn("Unknown fcntl command %d\n", cmd); 4002093SN/A return 0; 4012093SN/A } 4022093SN/A} 4032093SN/A 4042238SN/ASyscallReturn 4053114Sgblack@eecs.umich.edufcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, 4062687Sksewell@umich.edu ThreadContext *tc) 4072687Sksewell@umich.edu{ 4082687Sksewell@umich.edu int fd = tc->getSyscallArg(0); 4092687Sksewell@umich.edu 4102687Sksewell@umich.edu if (fd < 0 || process->sim_fd(fd) < 0) 4112687Sksewell@umich.edu return -EBADF; 4122687Sksewell@umich.edu 4132687Sksewell@umich.edu int cmd = tc->getSyscallArg(1); 4142687Sksewell@umich.edu switch (cmd) { 4152687Sksewell@umich.edu case 33: //F_GETLK64 4162687Sksewell@umich.edu warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); 4172687Sksewell@umich.edu return -EMFILE; 4182687Sksewell@umich.edu 4192687Sksewell@umich.edu case 34: // F_SETLK64 4202687Sksewell@umich.edu case 35: // F_SETLKW64 4212687Sksewell@umich.edu warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); 4222687Sksewell@umich.edu return -EMFILE; 4232687Sksewell@umich.edu 4242687Sksewell@umich.edu default: 4252687Sksewell@umich.edu // not sure if this is totally valid, but we'll pass it through 4262687Sksewell@umich.edu // to the underlying OS 4272687Sksewell@umich.edu warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); 4282687Sksewell@umich.edu return fcntl(process->sim_fd(fd), cmd); 4292687Sksewell@umich.edu // return 0; 4302687Sksewell@umich.edu } 4312687Sksewell@umich.edu} 4322687Sksewell@umich.edu 4332687Sksewell@umich.eduSyscallReturn 4343114Sgblack@eecs.umich.edupipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4352680Sktlim@umich.edu ThreadContext *tc) 4362238SN/A{ 4372238SN/A int fds[2], sim_fds[2]; 4382238SN/A int pipe_retval = pipe(fds); 4392093SN/A 4402238SN/A if (pipe_retval < 0) { 4412238SN/A // error 4422238SN/A return pipe_retval; 4432238SN/A } 4442238SN/A 4452238SN/A sim_fds[0] = process->alloc_fd(fds[0]); 4462238SN/A sim_fds[1] = process->alloc_fd(fds[1]); 4472238SN/A 4482238SN/A // Alpha Linux convention for pipe() is that fd[0] is returned as 4492238SN/A // the return value of the function, and fd[1] is returned in r20. 4502680Sktlim@umich.edu tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 4512238SN/A return sim_fds[0]; 4522238SN/A} 4532238SN/A 4542238SN/A 4552238SN/ASyscallReturn 4563114Sgblack@eecs.umich.edugetpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4572680Sktlim@umich.edu ThreadContext *tc) 4582238SN/A{ 4592238SN/A // Make up a PID. There's no interprocess communication in 4602238SN/A // fake_syscall mode, so there's no way for a process to know it's 4612238SN/A // not getting a unique value. 4622238SN/A 4633114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 4643114Sgblack@eecs.umich.edu return process->pid(); 4652238SN/A} 4662238SN/A 4672238SN/A 4682238SN/ASyscallReturn 4693114Sgblack@eecs.umich.edugetuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4702680Sktlim@umich.edu ThreadContext *tc) 4712238SN/A{ 4722238SN/A // Make up a UID and EUID... it shouldn't matter, and we want the 4732238SN/A // simulation to be deterministic. 4742238SN/A 4752238SN/A // EUID goes in r20. 4763114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 4773114Sgblack@eecs.umich.edu return process->uid(); // UID 4782238SN/A} 4792238SN/A 4802238SN/A 4812238SN/ASyscallReturn 4823114Sgblack@eecs.umich.edugetgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4832680Sktlim@umich.edu ThreadContext *tc) 4842238SN/A{ 4852238SN/A // Get current group ID. EGID goes in r20. 4863114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 4873114Sgblack@eecs.umich.edu return process->gid(); 4882238SN/A} 4892238SN/A 4902238SN/A 4912238SN/ASyscallReturn 4923114Sgblack@eecs.umich.edusetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 4932680Sktlim@umich.edu ThreadContext *tc) 4942238SN/A{ 4952238SN/A // can't fathom why a benchmark would call this. 4962680Sktlim@umich.edu warn("Ignoring call to setuid(%d)\n", tc->getSyscallArg(0)); 4972238SN/A return 0; 4982238SN/A} 4992238SN/A 5002238SN/ASyscallReturn 5013114Sgblack@eecs.umich.edugetpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5022680Sktlim@umich.edu ThreadContext *tc) 5032238SN/A{ 5042238SN/A // Make up a PID. There's no interprocess communication in 5052238SN/A // fake_syscall mode, so there's no way for a process to know it's 5062238SN/A // not getting a unique value. 5072238SN/A 5083114Sgblack@eecs.umich.edu tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 5093114Sgblack@eecs.umich.edu return process->pid(); 5102238SN/A} 5112238SN/A 5122238SN/ASyscallReturn 5133114Sgblack@eecs.umich.edugetppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5142680Sktlim@umich.edu ThreadContext *tc) 5152238SN/A{ 5163114Sgblack@eecs.umich.edu return process->ppid(); 5172238SN/A} 5182238SN/A 5192238SN/ASyscallReturn 5203114Sgblack@eecs.umich.edugetuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5212680Sktlim@umich.edu ThreadContext *tc) 5222238SN/A{ 5233114Sgblack@eecs.umich.edu return process->uid(); // UID 5242238SN/A} 5252238SN/A 5262238SN/ASyscallReturn 5273114Sgblack@eecs.umich.edugeteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5282680Sktlim@umich.edu ThreadContext *tc) 5292238SN/A{ 5303114Sgblack@eecs.umich.edu return process->euid(); // UID 5312238SN/A} 5322238SN/A 5332238SN/ASyscallReturn 5343114Sgblack@eecs.umich.edugetgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5352680Sktlim@umich.edu ThreadContext *tc) 5362238SN/A{ 5373114Sgblack@eecs.umich.edu return process->gid(); 5382238SN/A} 5392238SN/A 5402238SN/ASyscallReturn 5413114Sgblack@eecs.umich.edugetegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 5422680Sktlim@umich.edu ThreadContext *tc) 5432238SN/A{ 5443114Sgblack@eecs.umich.edu return process->egid(); 5452238SN/A} 5462238SN/A 5472238SN/A 548