Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 1 | /* |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 2 | * Copyright (c) 2003-2005 The Regents of The University of Michigan |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer; |
| 9 | * redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution; |
| 12 | * neither the name of the copyright holders nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived from |
| 14 | * this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ali Saidi | cb0cf2d | 2006-05-31 19:26:56 -0400 | [diff] [blame] | 27 | * |
| 28 | * Authors: Steve Reinhardt |
| 29 | * Ali Saidi |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 30 | */ |
| 31 | |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 32 | #include <fcntl.h> |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 33 | #include <unistd.h> |
| 34 | |
| 35 | #include <string> |
| 36 | #include <iostream> |
| 37 | |
| 38 | #include "sim/syscall_emul.hh" |
Ali Saidi | 97e4249 | 2006-03-15 17:04:50 -0500 | [diff] [blame] | 39 | #include "base/chunk_generator.hh" |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 40 | #include "base/trace.hh" |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 41 | #include "cpu/thread_context.hh" |
Nathan Binkert | 13c005a | 2005-06-04 20:50:10 -0400 | [diff] [blame] | 42 | #include "cpu/base.hh" |
Ali Saidi | 97e4249 | 2006-03-15 17:04:50 -0500 | [diff] [blame] | 43 | #include "mem/page_table.hh" |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 44 | #include "sim/process.hh" |
| 45 | |
Steve Reinhardt | 29e34a7 | 2006-06-09 23:01:31 -0400 | [diff] [blame] | 46 | #include "sim/sim_exit.hh" |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 47 | |
| 48 | using namespace std; |
Gabe Black | 463aa6d | 2006-02-19 02:34:37 -0500 | [diff] [blame] | 49 | using namespace TheISA; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 50 | |
| 51 | void |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 52 | SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 53 | { |
Korey Sewell | 4f430e9 | 2006-04-10 12:23:17 -0400 | [diff] [blame] | 54 | DPRINTFR(SyscallVerbose, "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 55 | curTick,tc->getCpuPtr()->name(), name, |
| 56 | tc->getSyscallArg(0),tc->getSyscallArg(1), |
| 57 | tc->getSyscallArg(2),tc->getSyscallArg(3)); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 58 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 59 | SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 60 | |
Korey Sewell | 4f430e9 | 2006-04-10 12:23:17 -0400 | [diff] [blame] | 61 | DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 62 | curTick,tc->getCpuPtr()->name(), name, retval.value()); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 63 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 64 | if (!(flags & SyscallDesc::SuppressReturnValue)) |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 65 | tc->setSyscallReturn(retval); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 69 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 70 | unimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 71 | ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 72 | { |
Steve Reinhardt | 99bf6ed | 2005-11-10 21:05:31 -0500 | [diff] [blame] | 73 | fatal("syscall %s (#%d) unimplemented.", desc->name, callnum); |
Korey Sewell | 8ddd509 | 2006-03-18 10:51:28 -0500 | [diff] [blame] | 74 | |
| 75 | return 1; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 79 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 80 | ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 81 | ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 82 | { |
Steve Reinhardt | 99bf6ed | 2005-11-10 21:05:31 -0500 | [diff] [blame] | 83 | warn("ignoring syscall %s(%d, %d, ...)", desc->name, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 84 | tc->getSyscallArg(0), tc->getSyscallArg(1)); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 85 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 86 | return 0; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 90 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 91 | exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 92 | ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 93 | { |
Korey Sewell | f4c5609 | 2006-07-03 12:19:35 -0400 | [diff] [blame] | 94 | if (tc->exit()) { |
| 95 | exitSimLoop("target called exit()", tc->getSyscallArg(0) & 0xff); |
| 96 | } |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 97 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 98 | return 1; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 102 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 103 | getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 104 | { |
Gabe Black | 463aa6d | 2006-02-19 02:34:37 -0500 | [diff] [blame] | 105 | return (int)VMPageSize; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 109 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 110 | obreakFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 111 | { |
Ali Saidi | 97e4249 | 2006-03-15 17:04:50 -0500 | [diff] [blame] | 112 | Addr junk; |
| 113 | |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 114 | // change brk addr to first arg |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 115 | Addr new_brk = tc->getSyscallArg(0); |
Ali Saidi | 97e4249 | 2006-03-15 17:04:50 -0500 | [diff] [blame] | 116 | if (new_brk != 0) { |
| 117 | for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, |
| 118 | VMPageSize); !gen.done(); gen.next()) { |
| 119 | if (!p->pTable->translate(gen.addr(), junk)) |
| 120 | p->pTable->allocate(roundDown(gen.addr(), VMPageSize), |
| 121 | VMPageSize); |
| 122 | } |
| 123 | p->brk_point = new_brk; |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 124 | } |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 125 | DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point); |
| 126 | return p->brk_point; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 130 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 131 | closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 132 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 133 | int target_fd = tc->getSyscallArg(0); |
Steve Reinhardt | 4410876 | 2005-11-10 21:08:33 -0500 | [diff] [blame] | 134 | int status = close(p->sim_fd(target_fd)); |
| 135 | if (status >= 0) |
| 136 | p->free_fd(target_fd); |
| 137 | return status; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 141 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 142 | readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 143 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 144 | int fd = p->sim_fd(tc->getSyscallArg(0)); |
| 145 | int nbytes = tc->getSyscallArg(2); |
| 146 | BufferArg bufArg(tc->getSyscallArg(1), nbytes); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 147 | |
| 148 | int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); |
| 149 | |
| 150 | if (bytes_read != -1) |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 151 | bufArg.copyOut(tc->getMemPort()); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 152 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 153 | return bytes_read; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 156 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 157 | writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 158 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 159 | int fd = p->sim_fd(tc->getSyscallArg(0)); |
| 160 | int nbytes = tc->getSyscallArg(2); |
| 161 | BufferArg bufArg(tc->getSyscallArg(1), nbytes); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 162 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 163 | bufArg.copyIn(tc->getMemPort()); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 164 | |
| 165 | int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); |
| 166 | |
| 167 | fsync(fd); |
| 168 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 169 | return bytes_written; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 173 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 174 | lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 175 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 176 | int fd = p->sim_fd(tc->getSyscallArg(0)); |
| 177 | uint64_t offs = tc->getSyscallArg(1); |
| 178 | int whence = tc->getSyscallArg(2); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 179 | |
| 180 | off_t result = lseek(fd, offs, whence); |
| 181 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 182 | return (result == (off_t)-1) ? -errno : result; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 186 | SyscallReturn |
Gabe Black | 23dc509 | 2007-03-03 03:34:55 +0000 | [diff] [blame] | 187 | _llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
| 188 | { |
| 189 | int fd = p->sim_fd(tc->getSyscallArg(0)); |
| 190 | uint64_t offset_high = tc->getSyscallArg(1); |
| 191 | uint32_t offset_low = tc->getSyscallArg(2); |
| 192 | Addr result_ptr = tc->getSyscallArg(3); |
| 193 | int whence = tc->getSyscallArg(4); |
| 194 | |
| 195 | uint64_t offset = (offset_high << 32) | offset_low; |
| 196 | |
| 197 | uint64_t result = lseek(fd, offset, whence); |
| 198 | result = TheISA::htog(result); |
| 199 | |
| 200 | if (result == (off_t)-1) { |
| 201 | //The seek failed. |
| 202 | return -errno; |
| 203 | } else { |
| 204 | //The seek succeeded. |
| 205 | //Copy "result" to "result_ptr" |
| 206 | //XXX We'll assume that the size of loff_t is 64 bits on the |
| 207 | //target platform |
| 208 | BufferArg result_buf(result_ptr, sizeof(result)); |
| 209 | memcpy(result_buf.bufferPtr(), &result, sizeof(result)); |
| 210 | result_buf.copyOut(tc->getMemPort()); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | |
| 215 | return (result == (off_t)-1) ? -errno : result; |
| 216 | } |
| 217 | |
| 218 | |
| 219 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 220 | munmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 221 | { |
| 222 | // given that we don't really implement mmap, munmap is really easy |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 223 | return 0; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | |
| 227 | const char *hostname = "m5.eecs.umich.edu"; |
| 228 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 229 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 230 | gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 231 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 232 | int name_len = tc->getSyscallArg(1); |
| 233 | BufferArg name(tc->getSyscallArg(0), name_len); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 234 | |
| 235 | strncpy((char *)name.bufferPtr(), hostname, name_len); |
| 236 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 237 | name.copyOut(tc->getMemPort()); |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 238 | |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 239 | return 0; |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 242 | SyscallReturn |
Michael Adler | 2cd04fd | 2008-07-23 14:41:33 -0700 | [diff] [blame^] | 243 | getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
| 244 | { |
| 245 | int result = 0; |
| 246 | unsigned long size = tc->getSyscallArg(1); |
| 247 | BufferArg buf(tc->getSyscallArg(0), size); |
| 248 | |
| 249 | // Is current working directory defined? |
| 250 | string cwd = p->getcwd(); |
| 251 | if (!cwd.empty()) { |
| 252 | if (cwd.length() >= size) { |
| 253 | // Buffer too small |
| 254 | return -ERANGE; |
| 255 | } |
| 256 | strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); |
| 257 | result = cwd.length(); |
| 258 | } |
| 259 | else { |
| 260 | if (getcwd((char *)buf.bufferPtr(), size) != NULL) { |
| 261 | result = strlen((char *)buf.bufferPtr()); |
| 262 | } |
| 263 | else { |
| 264 | result = -1; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | buf.copyOut(tc->getMemPort()); |
| 269 | |
| 270 | return (result == -1) ? -errno : result; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | SyscallReturn |
| 275 | readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
| 276 | { |
| 277 | string path; |
| 278 | |
| 279 | if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) |
| 280 | return (TheISA::IntReg)-EFAULT; |
| 281 | |
| 282 | // Adjust path for current working directory |
| 283 | path = p->fullPath(path); |
| 284 | |
| 285 | size_t bufsiz = tc->getSyscallArg(2); |
| 286 | BufferArg buf(tc->getSyscallArg(1), bufsiz); |
| 287 | |
| 288 | int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); |
| 289 | |
| 290 | buf.copyOut(tc->getMemPort()); |
| 291 | |
| 292 | return (result == -1) ? -errno : result; |
| 293 | } |
| 294 | |
| 295 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 296 | unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 297 | { |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 298 | string path; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 299 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 300 | if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 301 | return (TheISA::IntReg)-EFAULT; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 302 | |
Nathan Binkert | 31d829d | 2006-11-16 12:43:11 -0800 | [diff] [blame] | 303 | // Adjust path for current working directory |
| 304 | path = p->fullPath(path); |
| 305 | |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 306 | int result = unlink(path.c_str()); |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 307 | return (result == -1) ? -errno : result; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Michael Adler | 2cd04fd | 2008-07-23 14:41:33 -0700 | [diff] [blame^] | 310 | |
| 311 | SyscallReturn |
| 312 | mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
| 313 | { |
| 314 | string path; |
| 315 | |
| 316 | if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) |
| 317 | return (TheISA::IntReg)-EFAULT; |
| 318 | |
| 319 | // Adjust path for current working directory |
| 320 | path = p->fullPath(path); |
| 321 | |
| 322 | mode_t mode = tc->getSyscallArg(1); |
| 323 | |
| 324 | int result = mkdir(path.c_str(), mode); |
| 325 | return (result == -1) ? -errno : result; |
| 326 | } |
| 327 | |
Ali Saidi | 232134a | 2005-03-09 15:52:10 -0500 | [diff] [blame] | 328 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 329 | renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 330 | { |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 331 | string old_name; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 332 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 333 | if (!tc->getMemPort()->tryReadString(old_name, tc->getSyscallArg(0))) |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 334 | return -EFAULT; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 335 | |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 336 | string new_name; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 337 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 338 | if (!tc->getMemPort()->tryReadString(new_name, tc->getSyscallArg(1))) |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 339 | return -EFAULT; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 340 | |
Nathan Binkert | 31d829d | 2006-11-16 12:43:11 -0800 | [diff] [blame] | 341 | // Adjust path for current working directory |
| 342 | old_name = p->fullPath(old_name); |
| 343 | new_name = p->fullPath(new_name); |
| 344 | |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 345 | int64_t result = rename(old_name.c_str(), new_name.c_str()); |
Ali Saidi | ad9b28f | 2005-03-10 14:20:12 -0500 | [diff] [blame] | 346 | return (result == -1) ? -errno : result; |
David Oehmke | 95c248c | 2004-02-05 12:16:17 -0500 | [diff] [blame] | 347 | } |
Steve Reinhardt | 7976794 | 2003-12-01 19:34:38 -0800 | [diff] [blame] | 348 | |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 349 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 350 | truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 351 | { |
| 352 | string path; |
| 353 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 354 | if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 355 | return -EFAULT; |
| 356 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 357 | off_t length = tc->getSyscallArg(1); |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 358 | |
Nathan Binkert | 31d829d | 2006-11-16 12:43:11 -0800 | [diff] [blame] | 359 | // Adjust path for current working directory |
| 360 | path = p->fullPath(path); |
| 361 | |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 362 | int result = truncate(path.c_str(), length); |
| 363 | return (result == -1) ? -errno : result; |
| 364 | } |
| 365 | |
| 366 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 367 | ftruncateFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 368 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 369 | int fd = process->sim_fd(tc->getSyscallArg(0)); |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 370 | |
| 371 | if (fd < 0) |
| 372 | return -EBADF; |
| 373 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 374 | off_t length = tc->getSyscallArg(1); |
Steve Reinhardt | 22eccce | 2005-06-03 16:19:34 -0400 | [diff] [blame] | 375 | |
| 376 | int result = ftruncate(fd, length); |
| 377 | return (result == -1) ? -errno : result; |
| 378 | } |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 379 | |
| 380 | SyscallReturn |
Michael Adler | 2cd04fd | 2008-07-23 14:41:33 -0700 | [diff] [blame^] | 381 | umaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) |
| 382 | { |
| 383 | // Letting the simulated program change the simulator's umask seems like |
| 384 | // a bad idea. Compromise by just returning the current umask but not |
| 385 | // changing anything. |
| 386 | mode_t oldMask = umask(0); |
| 387 | umask(oldMask); |
| 388 | return oldMask; |
| 389 | } |
| 390 | |
| 391 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 392 | chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 393 | { |
| 394 | string path; |
| 395 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 396 | if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 397 | return -EFAULT; |
| 398 | |
| 399 | /* XXX endianess */ |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 400 | uint32_t owner = tc->getSyscallArg(1); |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 401 | uid_t hostOwner = owner; |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 402 | uint32_t group = tc->getSyscallArg(2); |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 403 | gid_t hostGroup = group; |
| 404 | |
Nathan Binkert | 31d829d | 2006-11-16 12:43:11 -0800 | [diff] [blame] | 405 | // Adjust path for current working directory |
| 406 | path = p->fullPath(path); |
| 407 | |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 408 | int result = chown(path.c_str(), hostOwner, hostGroup); |
| 409 | return (result == -1) ? -errno : result; |
| 410 | } |
| 411 | |
| 412 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 413 | fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 414 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 415 | int fd = process->sim_fd(tc->getSyscallArg(0)); |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 416 | |
| 417 | if (fd < 0) |
| 418 | return -EBADF; |
| 419 | |
| 420 | /* XXX endianess */ |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 421 | uint32_t owner = tc->getSyscallArg(1); |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 422 | uid_t hostOwner = owner; |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 423 | uint32_t group = tc->getSyscallArg(2); |
Kevin Lim | 6da93ea | 2005-11-22 12:08:08 -0500 | [diff] [blame] | 424 | gid_t hostGroup = group; |
| 425 | |
| 426 | int result = fchown(fd, hostOwner, hostGroup); |
| 427 | return (result == -1) ? -errno : result; |
| 428 | } |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 429 | |
| 430 | |
| 431 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 432 | dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) |
Steve Reinhardt | c538436 | 2006-08-28 07:39:56 -0700 | [diff] [blame] | 433 | { |
| 434 | int fd = process->sim_fd(tc->getSyscallArg(0)); |
Steve Reinhardt | c538436 | 2006-08-28 07:39:56 -0700 | [diff] [blame] | 435 | if (fd < 0) |
| 436 | return -EBADF; |
| 437 | |
Rick Strong | 376c728 | 2007-11-29 00:22:46 -0500 | [diff] [blame] | 438 | Process::FdMap *fdo = process->sim_fd_obj(tc->getSyscallArg(0)); |
| 439 | |
Steve Reinhardt | c538436 | 2006-08-28 07:39:56 -0700 | [diff] [blame] | 440 | int result = dup(fd); |
Rick Strong | 376c728 | 2007-11-29 00:22:46 -0500 | [diff] [blame] | 441 | return (result == -1) ? -errno : process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false); |
Steve Reinhardt | c538436 | 2006-08-28 07:39:56 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
| 445 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 446 | fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 447 | ThreadContext *tc) |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 448 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 449 | int fd = tc->getSyscallArg(0); |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 450 | |
| 451 | if (fd < 0 || process->sim_fd(fd) < 0) |
| 452 | return -EBADF; |
| 453 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 454 | int cmd = tc->getSyscallArg(1); |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 455 | switch (cmd) { |
| 456 | case 0: // F_DUPFD |
| 457 | // if we really wanted to support this, we'd need to do it |
| 458 | // in the target fd space. |
| 459 | warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd); |
| 460 | return -EMFILE; |
| 461 | |
| 462 | case 1: // F_GETFD (get close-on-exec flag) |
| 463 | case 2: // F_SETFD (set close-on-exec flag) |
| 464 | return 0; |
| 465 | |
| 466 | case 3: // F_GETFL (get file flags) |
| 467 | case 4: // F_SETFL (set file flags) |
| 468 | // not sure if this is totally valid, but we'll pass it through |
| 469 | // to the underlying OS |
| 470 | warn("fcntl(%d, %d) passed through to host\n", fd, cmd); |
| 471 | return fcntl(process->sim_fd(fd), cmd); |
| 472 | // return 0; |
| 473 | |
| 474 | case 7: // F_GETLK (get lock) |
| 475 | case 8: // F_SETLK (set lock) |
| 476 | case 9: // F_SETLKW (set lock and wait) |
| 477 | // don't mess with file locking... just act like it's OK |
| 478 | warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd); |
| 479 | return 0; |
| 480 | |
| 481 | default: |
| 482 | warn("Unknown fcntl command %d\n", cmd); |
| 483 | return 0; |
| 484 | } |
| 485 | } |
| 486 | |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 487 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 488 | fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, |
Korey Sewell | 4cc31e1 | 2006-06-09 17:07:13 -0400 | [diff] [blame] | 489 | ThreadContext *tc) |
| 490 | { |
| 491 | int fd = tc->getSyscallArg(0); |
| 492 | |
| 493 | if (fd < 0 || process->sim_fd(fd) < 0) |
| 494 | return -EBADF; |
| 495 | |
| 496 | int cmd = tc->getSyscallArg(1); |
| 497 | switch (cmd) { |
| 498 | case 33: //F_GETLK64 |
| 499 | warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd); |
| 500 | return -EMFILE; |
| 501 | |
| 502 | case 34: // F_SETLK64 |
| 503 | case 35: // F_SETLKW64 |
| 504 | warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd); |
| 505 | return -EMFILE; |
| 506 | |
| 507 | default: |
| 508 | // not sure if this is totally valid, but we'll pass it through |
| 509 | // to the underlying OS |
| 510 | warn("fcntl64(%d, %d) passed through to host\n", fd, cmd); |
| 511 | return fcntl(process->sim_fd(fd), cmd); |
| 512 | // return 0; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 517 | pipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 518 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 519 | { |
| 520 | int fds[2], sim_fds[2]; |
| 521 | int pipe_retval = pipe(fds); |
| 522 | |
| 523 | if (pipe_retval < 0) { |
| 524 | // error |
| 525 | return pipe_retval; |
| 526 | } |
| 527 | |
Rick Strong | 376c728 | 2007-11-29 00:22:46 -0500 | [diff] [blame] | 528 | sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true); |
| 529 | sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 530 | |
Rick Strong | 376c728 | 2007-11-29 00:22:46 -0500 | [diff] [blame] | 531 | process->setReadPipeSource(sim_fds[0], sim_fds[1]); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 532 | // Alpha Linux convention for pipe() is that fd[0] is returned as |
| 533 | // the return value of the function, and fd[1] is returned in r20. |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 534 | tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 535 | return sim_fds[0]; |
| 536 | } |
| 537 | |
| 538 | |
| 539 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 540 | getpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 541 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 542 | { |
| 543 | // Make up a PID. There's no interprocess communication in |
| 544 | // fake_syscall mode, so there's no way for a process to know it's |
| 545 | // not getting a unique value. |
| 546 | |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 547 | tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); |
| 548 | return process->pid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
| 552 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 553 | getuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 554 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 555 | { |
| 556 | // Make up a UID and EUID... it shouldn't matter, and we want the |
| 557 | // simulation to be deterministic. |
| 558 | |
| 559 | // EUID goes in r20. |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 560 | tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID |
| 561 | return process->uid(); // UID |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 566 | getgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 567 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 568 | { |
| 569 | // Get current group ID. EGID goes in r20. |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 570 | tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID |
| 571 | return process->gid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
| 575 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 576 | setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 577 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 578 | { |
| 579 | // can't fathom why a benchmark would call this. |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 580 | warn("Ignoring call to setuid(%d)\n", tc->getSyscallArg(0)); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 585 | getpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 586 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 587 | { |
| 588 | // Make up a PID. There's no interprocess communication in |
| 589 | // fake_syscall mode, so there's no way for a process to know it's |
| 590 | // not getting a unique value. |
| 591 | |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 592 | tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID |
| 593 | return process->pid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 597 | getppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 598 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 599 | { |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 600 | return process->ppid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 604 | getuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 605 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 606 | { |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 607 | return process->uid(); // UID |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 611 | geteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 612 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 613 | { |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 614 | return process->euid(); // UID |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 618 | getgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 619 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 620 | { |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 621 | return process->gid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | SyscallReturn |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 625 | getegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 626 | ThreadContext *tc) |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 627 | { |
Gabe Black | 30b87e9 | 2006-09-17 03:00:55 -0400 | [diff] [blame] | 628 | return process->egid(); |
Ali Saidi | ce3a634 | 2006-03-09 15:42:09 -0500 | [diff] [blame] | 629 | } |
| 630 | |
Ali Saidi | 53d2c93 | 2006-02-18 23:44:22 -0500 | [diff] [blame] | 631 | |