syscall_emul.cc (11800:54436a1784dc) | syscall_emul.cc (11851:824055fe6b30) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 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; --- 39 unchanged lines hidden (view full) --- 48#include "sim/syscall_debug_macros.hh" 49#include "sim/syscall_desc.hh" 50#include "sim/system.hh" 51 52using namespace std; 53using namespace TheISA; 54 55SyscallReturn | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 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; --- 39 unchanged lines hidden (view full) --- 48#include "sim/syscall_debug_macros.hh" 49#include "sim/syscall_desc.hh" 50#include "sim/system.hh" 51 52using namespace std; 53using namespace TheISA; 54 55SyscallReturn |
56unimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 56unimplementedFunc(SyscallDesc *desc, int callnum, Process *process, |
57 ThreadContext *tc) 58{ 59 fatal("syscall %s (#%d) unimplemented.", desc->name(), callnum); 60 61 return 1; 62} 63 64 65SyscallReturn | 57 ThreadContext *tc) 58{ 59 fatal("syscall %s (#%d) unimplemented.", desc->name(), callnum); 60 61 return 1; 62} 63 64 65SyscallReturn |
66ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 66ignoreFunc(SyscallDesc *desc, int callnum, Process *process, |
67 ThreadContext *tc) 68{ 69 if (desc->needWarning()) { 70 warn("ignoring syscall %s(...)%s", desc->name(), desc->warnOnce() ? 71 "\n (further warnings will be suppressed)" : ""); 72 } 73 74 return 0; 75} 76 77 78SyscallReturn | 67 ThreadContext *tc) 68{ 69 if (desc->needWarning()) { 70 warn("ignoring syscall %s(...)%s", desc->name(), desc->warnOnce() ? 71 "\n (further warnings will be suppressed)" : ""); 72 } 73 74 return 0; 75} 76 77 78SyscallReturn |
79exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 79exitFunc(SyscallDesc *desc, int callnum, Process *process, |
80 ThreadContext *tc) 81{ 82 if (process->system->numRunningContexts() == 1) { 83 // Last running context... exit simulator 84 int index = 0; 85 exitSimLoop("target called exit()", 86 process->getSyscallArg(tc, index) & 0xff); 87 } else { 88 // other running threads... just halt this one 89 tc->halt(); 90 } 91 92 return 1; 93} 94 95 96SyscallReturn | 80 ThreadContext *tc) 81{ 82 if (process->system->numRunningContexts() == 1) { 83 // Last running context... exit simulator 84 int index = 0; 85 exitSimLoop("target called exit()", 86 process->getSyscallArg(tc, index) & 0xff); 87 } else { 88 // other running threads... just halt this one 89 tc->halt(); 90 } 91 92 return 1; 93} 94 95 96SyscallReturn |
97exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 97exitGroupFunc(SyscallDesc *desc, int callnum, Process *process, |
98 ThreadContext *tc) 99{ 100 // halt all threads belonging to this process 101 for (auto i: process->contextIds) { 102 process->system->getThreadContext(i)->halt(); 103 } 104 105 if (!process->system->numRunningContexts()) { 106 // all threads belonged to this process... exit simulator 107 int index = 0; 108 exitSimLoop("target called exit()", 109 process->getSyscallArg(tc, index) & 0xff); 110 } 111 112 return 1; 113} 114 115 116SyscallReturn | 98 ThreadContext *tc) 99{ 100 // halt all threads belonging to this process 101 for (auto i: process->contextIds) { 102 process->system->getThreadContext(i)->halt(); 103 } 104 105 if (!process->system->numRunningContexts()) { 106 // all threads belonged to this process... exit simulator 107 int index = 0; 108 exitSimLoop("target called exit()", 109 process->getSyscallArg(tc, index) & 0xff); 110 } 111 112 return 1; 113} 114 115 116SyscallReturn |
117getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 117getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
118{ 119 return (int)PageBytes; 120} 121 122 123SyscallReturn | 118{ 119 return (int)PageBytes; 120} 121 122 123SyscallReturn |
124brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 124brkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
125{ 126 // change brk addr to first arg 127 int index = 0; 128 Addr new_brk = p->getSyscallArg(tc, index); 129 130 // in Linux at least, brk(0) returns the current break value 131 // (note that the syscall and the glibc function have different behavior) 132 if (new_brk == 0) --- 29 unchanged lines hidden (view full) --- 162 p->brk_point = new_brk; 163 DPRINTF_SYSCALL(Verbose, "brk: break point changed to: %#X\n", 164 p->brk_point); 165 return p->brk_point; 166} 167 168 169SyscallReturn | 125{ 126 // change brk addr to first arg 127 int index = 0; 128 Addr new_brk = p->getSyscallArg(tc, index); 129 130 // in Linux at least, brk(0) returns the current break value 131 // (note that the syscall and the glibc function have different behavior) 132 if (new_brk == 0) --- 29 unchanged lines hidden (view full) --- 162 p->brk_point = new_brk; 163 DPRINTF_SYSCALL(Verbose, "brk: break point changed to: %#X\n", 164 p->brk_point); 165 return p->brk_point; 166} 167 168 169SyscallReturn |
170closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 170closeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
171{ 172 int index = 0; 173 int tgt_fd = p->getSyscallArg(tc, index); 174 175 int sim_fd = p->getSimFD(tgt_fd); 176 if (sim_fd < 0) 177 return -EBADF; 178 179 int status = 0; 180 if (sim_fd > 2) 181 status = close(sim_fd); 182 if (status >= 0) 183 p->resetFDEntry(tgt_fd); 184 return status; 185} 186 187 188SyscallReturn | 171{ 172 int index = 0; 173 int tgt_fd = p->getSyscallArg(tc, index); 174 175 int sim_fd = p->getSimFD(tgt_fd); 176 if (sim_fd < 0) 177 return -EBADF; 178 179 int status = 0; 180 if (sim_fd > 2) 181 status = close(sim_fd); 182 if (status >= 0) 183 p->resetFDEntry(tgt_fd); 184 return status; 185} 186 187 188SyscallReturn |
189readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 189readFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
190{ 191 int index = 0; 192 int tgt_fd = p->getSyscallArg(tc, index); 193 Addr bufPtr = p->getSyscallArg(tc, index); 194 int nbytes = p->getSyscallArg(tc, index); 195 BufferArg bufArg(bufPtr, nbytes); 196 197 int sim_fd = p->getSimFD(tgt_fd); --- 4 unchanged lines hidden (view full) --- 202 203 if (bytes_read > 0) 204 bufArg.copyOut(tc->getMemProxy()); 205 206 return bytes_read; 207} 208 209SyscallReturn | 190{ 191 int index = 0; 192 int tgt_fd = p->getSyscallArg(tc, index); 193 Addr bufPtr = p->getSyscallArg(tc, index); 194 int nbytes = p->getSyscallArg(tc, index); 195 BufferArg bufArg(bufPtr, nbytes); 196 197 int sim_fd = p->getSimFD(tgt_fd); --- 4 unchanged lines hidden (view full) --- 202 203 if (bytes_read > 0) 204 bufArg.copyOut(tc->getMemProxy()); 205 206 return bytes_read; 207} 208 209SyscallReturn |
210writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 210writeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
211{ 212 int index = 0; 213 int tgt_fd = p->getSyscallArg(tc, index); 214 Addr bufPtr = p->getSyscallArg(tc, index); 215 int nbytes = p->getSyscallArg(tc, index); 216 BufferArg bufArg(bufPtr, nbytes); 217 218 int sim_fd = p->getSimFD(tgt_fd); --- 6 unchanged lines hidden (view full) --- 225 226 fsync(sim_fd); 227 228 return bytes_written; 229} 230 231 232SyscallReturn | 211{ 212 int index = 0; 213 int tgt_fd = p->getSyscallArg(tc, index); 214 Addr bufPtr = p->getSyscallArg(tc, index); 215 int nbytes = p->getSyscallArg(tc, index); 216 BufferArg bufArg(bufPtr, nbytes); 217 218 int sim_fd = p->getSimFD(tgt_fd); --- 6 unchanged lines hidden (view full) --- 225 226 fsync(sim_fd); 227 228 return bytes_written; 229} 230 231 232SyscallReturn |
233lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 233lseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
234{ 235 int index = 0; 236 int tgt_fd = p->getSyscallArg(tc, index); 237 uint64_t offs = p->getSyscallArg(tc, index); 238 int whence = p->getSyscallArg(tc, index); 239 240 int sim_fd = p->getSimFD(tgt_fd); 241 if (sim_fd < 0) 242 return -EBADF; 243 244 off_t result = lseek(sim_fd, offs, whence); 245 246 return (result == (off_t)-1) ? -errno : result; 247} 248 249 250SyscallReturn | 234{ 235 int index = 0; 236 int tgt_fd = p->getSyscallArg(tc, index); 237 uint64_t offs = p->getSyscallArg(tc, index); 238 int whence = p->getSyscallArg(tc, index); 239 240 int sim_fd = p->getSimFD(tgt_fd); 241 if (sim_fd < 0) 242 return -EBADF; 243 244 off_t result = lseek(sim_fd, offs, whence); 245 246 return (result == (off_t)-1) ? -errno : result; 247} 248 249 250SyscallReturn |
251_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 251_llseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
252{ 253 int index = 0; 254 int tgt_fd = p->getSyscallArg(tc, index); 255 uint64_t offset_high = p->getSyscallArg(tc, index); 256 uint32_t offset_low = p->getSyscallArg(tc, index); 257 Addr result_ptr = p->getSyscallArg(tc, index); 258 int whence = p->getSyscallArg(tc, index); 259 --- 12 unchanged lines hidden (view full) --- 272 BufferArg result_buf(result_ptr, sizeof(result)); 273 memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 274 result_buf.copyOut(tc->getMemProxy()); 275 return 0; 276} 277 278 279SyscallReturn | 252{ 253 int index = 0; 254 int tgt_fd = p->getSyscallArg(tc, index); 255 uint64_t offset_high = p->getSyscallArg(tc, index); 256 uint32_t offset_low = p->getSyscallArg(tc, index); 257 Addr result_ptr = p->getSyscallArg(tc, index); 258 int whence = p->getSyscallArg(tc, index); 259 --- 12 unchanged lines hidden (view full) --- 272 BufferArg result_buf(result_ptr, sizeof(result)); 273 memcpy(result_buf.bufferPtr(), &result, sizeof(result)); 274 result_buf.copyOut(tc->getMemProxy()); 275 return 0; 276} 277 278 279SyscallReturn |
280munmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 280munmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
281{ 282 // With mmap more fully implemented, it might be worthwhile to bite 283 // the bullet and implement munmap. Should allow us to reuse simulated 284 // memory. 285 return 0; 286} 287 288 289const char *hostname = "m5.eecs.umich.edu"; 290 291SyscallReturn | 281{ 282 // With mmap more fully implemented, it might be worthwhile to bite 283 // the bullet and implement munmap. Should allow us to reuse simulated 284 // memory. 285 return 0; 286} 287 288 289const char *hostname = "m5.eecs.umich.edu"; 290 291SyscallReturn |
292gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 292gethostnameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
293{ 294 int index = 0; 295 Addr bufPtr = p->getSyscallArg(tc, index); 296 int name_len = p->getSyscallArg(tc, index); 297 BufferArg name(bufPtr, name_len); 298 299 strncpy((char *)name.bufferPtr(), hostname, name_len); 300 301 name.copyOut(tc->getMemProxy()); 302 303 return 0; 304} 305 306SyscallReturn | 293{ 294 int index = 0; 295 Addr bufPtr = p->getSyscallArg(tc, index); 296 int name_len = p->getSyscallArg(tc, index); 297 BufferArg name(bufPtr, name_len); 298 299 strncpy((char *)name.bufferPtr(), hostname, name_len); 300 301 name.copyOut(tc->getMemProxy()); 302 303 return 0; 304} 305 306SyscallReturn |
307getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 307getcwdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
308{ 309 int result = 0; 310 int index = 0; 311 Addr bufPtr = p->getSyscallArg(tc, index); 312 unsigned long size = p->getSyscallArg(tc, index); 313 BufferArg buf(bufPtr, size); 314 315 // Is current working directory defined? --- 15 unchanged lines hidden (view full) --- 331 332 buf.copyOut(tc->getMemProxy()); 333 334 return (result == -1) ? -errno : result; 335} 336 337/// Target open() handler. 338SyscallReturn | 308{ 309 int result = 0; 310 int index = 0; 311 Addr bufPtr = p->getSyscallArg(tc, index); 312 unsigned long size = p->getSyscallArg(tc, index); 313 BufferArg buf(bufPtr, size); 314 315 // Is current working directory defined? --- 15 unchanged lines hidden (view full) --- 331 332 buf.copyOut(tc->getMemProxy()); 333 334 return (result == -1) ? -errno : result; 335} 336 337/// Target open() handler. 338SyscallReturn |
339readlinkFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 340 ThreadContext *tc) | 339readlinkFunc(SyscallDesc *desc, int callnum, Process *process, 340 ThreadContext *tc) |
341{ 342 return readlinkFunc(desc, callnum, process, tc, 0); 343} 344 345SyscallReturn | 341{ 342 return readlinkFunc(desc, callnum, process, tc, 0); 343} 344 345SyscallReturn |
346readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc, 347 int index) | 346readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 347 int index) |
348{ 349 string path; 350 351 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 352 return -EFAULT; 353 354 // Adjust path for current working directory 355 path = p->fullPath(path); --- 4 unchanged lines hidden (view full) --- 360 BufferArg buf(bufPtr, bufsiz); 361 362 int result = -1; 363 if (path != "/proc/self/exe") { 364 result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 365 } else { 366 // Emulate readlink() called on '/proc/self/exe' should return the 367 // absolute path of the binary running in the simulated system (the | 348{ 349 string path; 350 351 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 352 return -EFAULT; 353 354 // Adjust path for current working directory 355 path = p->fullPath(path); --- 4 unchanged lines hidden (view full) --- 360 BufferArg buf(bufPtr, bufsiz); 361 362 int result = -1; 363 if (path != "/proc/self/exe") { 364 result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 365 } else { 366 // Emulate readlink() called on '/proc/self/exe' should return the 367 // absolute path of the binary running in the simulated system (the |
368 // LiveProcess' executable). It is possible that using this path in | 368 // Process' executable). It is possible that using this path in |
369 // the simulated system will result in unexpected behavior if: 370 // 1) One binary runs another (e.g., -c time -o "my_binary"), and 371 // called binary calls readlink(). 372 // 2) The host's full path to the running benchmark changes from one 373 // simulation to another. This can result in different simulated 374 // performance since the simulated system will process the binary 375 // path differently, even if the binary itself does not change. 376 --- 21 unchanged lines hidden (view full) --- 398 } 399 400 buf.copyOut(tc->getMemProxy()); 401 402 return (result == -1) ? -errno : result; 403} 404 405SyscallReturn | 369 // the simulated system will result in unexpected behavior if: 370 // 1) One binary runs another (e.g., -c time -o "my_binary"), and 371 // called binary calls readlink(). 372 // 2) The host's full path to the running benchmark changes from one 373 // simulation to another. This can result in different simulated 374 // performance since the simulated system will process the binary 375 // path differently, even if the binary itself does not change. 376 --- 21 unchanged lines hidden (view full) --- 398 } 399 400 buf.copyOut(tc->getMemProxy()); 401 402 return (result == -1) ? -errno : result; 403} 404 405SyscallReturn |
406unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 406unlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
407{ 408 return unlinkHelper(desc, num, p, tc, 0); 409} 410 411SyscallReturn | 407{ 408 return unlinkHelper(desc, num, p, tc, 0); 409} 410 411SyscallReturn |
412unlinkHelper(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc, 413 int index) | 412unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, 413 int index) |
414{ 415 string path; 416 417 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 418 return -EFAULT; 419 420 // Adjust path for current working directory 421 path = p->fullPath(path); 422 423 int result = unlink(path.c_str()); 424 return (result == -1) ? -errno : result; 425} 426 427 428SyscallReturn | 414{ 415 string path; 416 417 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 418 return -EFAULT; 419 420 // Adjust path for current working directory 421 path = p->fullPath(path); 422 423 int result = unlink(path.c_str()); 424 return (result == -1) ? -errno : result; 425} 426 427 428SyscallReturn |
429mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 429mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
430{ 431 string path; 432 433 int index = 0; 434 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 435 return -EFAULT; 436 437 // Adjust path for current working directory 438 path = p->fullPath(path); 439 440 mode_t mode = p->getSyscallArg(tc, index); 441 442 int result = mkdir(path.c_str(), mode); 443 return (result == -1) ? -errno : result; 444} 445 446SyscallReturn | 430{ 431 string path; 432 433 int index = 0; 434 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 435 return -EFAULT; 436 437 // Adjust path for current working directory 438 path = p->fullPath(path); 439 440 mode_t mode = p->getSyscallArg(tc, index); 441 442 int result = mkdir(path.c_str(), mode); 443 return (result == -1) ? -errno : result; 444} 445 446SyscallReturn |
447renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 447renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
448{ 449 string old_name; 450 451 int index = 0; 452 if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) 453 return -EFAULT; 454 455 string new_name; --- 5 unchanged lines hidden (view full) --- 461 old_name = p->fullPath(old_name); 462 new_name = p->fullPath(new_name); 463 464 int64_t result = rename(old_name.c_str(), new_name.c_str()); 465 return (result == -1) ? -errno : result; 466} 467 468SyscallReturn | 448{ 449 string old_name; 450 451 int index = 0; 452 if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) 453 return -EFAULT; 454 455 string new_name; --- 5 unchanged lines hidden (view full) --- 461 old_name = p->fullPath(old_name); 462 new_name = p->fullPath(new_name); 463 464 int64_t result = rename(old_name.c_str(), new_name.c_str()); 465 return (result == -1) ? -errno : result; 466} 467 468SyscallReturn |
469truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 469truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
470{ 471 string path; 472 473 int index = 0; 474 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 475 return -EFAULT; 476 477 off_t length = p->getSyscallArg(tc, index); 478 479 // Adjust path for current working directory 480 path = p->fullPath(path); 481 482 int result = truncate(path.c_str(), length); 483 return (result == -1) ? -errno : result; 484} 485 486SyscallReturn 487ftruncateFunc(SyscallDesc *desc, int num, | 470{ 471 string path; 472 473 int index = 0; 474 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 475 return -EFAULT; 476 477 off_t length = p->getSyscallArg(tc, index); 478 479 // Adjust path for current working directory 480 path = p->fullPath(path); 481 482 int result = truncate(path.c_str(), length); 483 return (result == -1) ? -errno : result; 484} 485 486SyscallReturn 487ftruncateFunc(SyscallDesc *desc, int num, |
488 LiveProcess *process, ThreadContext *tc) | 488 Process *process, ThreadContext *tc) |
489{ 490 int index = 0; 491 int tgt_fd = process->getSyscallArg(tc, index); 492 off_t length = process->getSyscallArg(tc, index); 493 494 int sim_fd = process->getSimFD(tgt_fd); 495 if (sim_fd < 0) 496 return -EBADF; 497 498 int result = ftruncate(sim_fd, length); 499 return (result == -1) ? -errno : result; 500} 501 502SyscallReturn 503truncate64Func(SyscallDesc *desc, int num, | 489{ 490 int index = 0; 491 int tgt_fd = process->getSyscallArg(tc, index); 492 off_t length = process->getSyscallArg(tc, index); 493 494 int sim_fd = process->getSimFD(tgt_fd); 495 if (sim_fd < 0) 496 return -EBADF; 497 498 int result = ftruncate(sim_fd, length); 499 return (result == -1) ? -errno : result; 500} 501 502SyscallReturn 503truncate64Func(SyscallDesc *desc, int num, |
504 LiveProcess *process, ThreadContext *tc) | 504 Process *process, ThreadContext *tc) |
505{ 506 int index = 0; 507 string path; 508 509 if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) 510 return -EFAULT; 511 512 int64_t length = process->getSyscallArg(tc, index, 64); --- 6 unchanged lines hidden (view full) --- 519#else 520 int result = truncate64(path.c_str(), length); 521#endif 522 return (result == -1) ? -errno : result; 523} 524 525SyscallReturn 526ftruncate64Func(SyscallDesc *desc, int num, | 505{ 506 int index = 0; 507 string path; 508 509 if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) 510 return -EFAULT; 511 512 int64_t length = process->getSyscallArg(tc, index, 64); --- 6 unchanged lines hidden (view full) --- 519#else 520 int result = truncate64(path.c_str(), length); 521#endif 522 return (result == -1) ? -errno : result; 523} 524 525SyscallReturn 526ftruncate64Func(SyscallDesc *desc, int num, |
527 LiveProcess *process, ThreadContext *tc) | 527 Process *process, ThreadContext *tc) |
528{ 529 int index = 0; 530 int tgt_fd = process->getSyscallArg(tc, index); 531 int64_t length = process->getSyscallArg(tc, index, 64); 532 533 int sim_fd = process->getSimFD(tgt_fd); 534 if (sim_fd < 0) 535 return -EBADF; 536 537#if NO_STAT64 538 int result = ftruncate(sim_fd, length); 539#else 540 int result = ftruncate64(sim_fd, length); 541#endif 542 return (result == -1) ? -errno : result; 543} 544 545SyscallReturn | 528{ 529 int index = 0; 530 int tgt_fd = process->getSyscallArg(tc, index); 531 int64_t length = process->getSyscallArg(tc, index, 64); 532 533 int sim_fd = process->getSimFD(tgt_fd); 534 if (sim_fd < 0) 535 return -EBADF; 536 537#if NO_STAT64 538 int result = ftruncate(sim_fd, length); 539#else 540 int result = ftruncate64(sim_fd, length); 541#endif 542 return (result == -1) ? -errno : result; 543} 544 545SyscallReturn |
546umaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) | 546umaskFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) |
547{ 548 // Letting the simulated program change the simulator's umask seems like 549 // a bad idea. Compromise by just returning the current umask but not 550 // changing anything. 551 mode_t oldMask = umask(0); 552 umask(oldMask); 553 return (int)oldMask; 554} 555 556SyscallReturn | 547{ 548 // Letting the simulated program change the simulator's umask seems like 549 // a bad idea. Compromise by just returning the current umask but not 550 // changing anything. 551 mode_t oldMask = umask(0); 552 umask(oldMask); 553 return (int)oldMask; 554} 555 556SyscallReturn |
557chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) | 557chownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) |
558{ 559 string path; 560 561 int index = 0; 562 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 563 return -EFAULT; 564 565 /* XXX endianess */ --- 5 unchanged lines hidden (view full) --- 571 // Adjust path for current working directory 572 path = p->fullPath(path); 573 574 int result = chown(path.c_str(), hostOwner, hostGroup); 575 return (result == -1) ? -errno : result; 576} 577 578SyscallReturn | 558{ 559 string path; 560 561 int index = 0; 562 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 563 return -EFAULT; 564 565 /* XXX endianess */ --- 5 unchanged lines hidden (view full) --- 571 // Adjust path for current working directory 572 path = p->fullPath(path); 573 574 int result = chown(path.c_str(), hostOwner, hostGroup); 575 return (result == -1) ? -errno : result; 576} 577 578SyscallReturn |
579fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) | 579fchownFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) |
580{ 581 int index = 0; 582 int tgt_fd = process->getSyscallArg(tc, index); 583 584 int sim_fd = process->getSimFD(tgt_fd); 585 if (sim_fd < 0) 586 return -EBADF; 587 --- 4 unchanged lines hidden (view full) --- 592 gid_t hostGroup = group; 593 594 int result = fchown(sim_fd, hostOwner, hostGroup); 595 return (result == -1) ? -errno : result; 596} 597 598 599SyscallReturn | 580{ 581 int index = 0; 582 int tgt_fd = process->getSyscallArg(tc, index); 583 584 int sim_fd = process->getSimFD(tgt_fd); 585 if (sim_fd < 0) 586 return -EBADF; 587 --- 4 unchanged lines hidden (view full) --- 592 gid_t hostGroup = group; 593 594 int result = fchown(sim_fd, hostOwner, hostGroup); 595 return (result == -1) ? -errno : result; 596} 597 598 599SyscallReturn |
600dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc) | 600dupFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) |
601{ 602 int index = 0; 603 int tgt_fd = process->getSyscallArg(tc, index); 604 605 int sim_fd = process->getSimFD(tgt_fd); 606 if (sim_fd < 0) 607 return -EBADF; 608 609 FDEntry *fde = process->getFDEntry(tgt_fd); 610 611 int result = dup(sim_fd); 612 return (result == -1) ? -errno : 613 process->allocFD(result, fde->filename, fde->flags, fde->mode, false); 614} 615 616 617SyscallReturn | 601{ 602 int index = 0; 603 int tgt_fd = process->getSyscallArg(tc, index); 604 605 int sim_fd = process->getSimFD(tgt_fd); 606 if (sim_fd < 0) 607 return -EBADF; 608 609 FDEntry *fde = process->getFDEntry(tgt_fd); 610 611 int result = dup(sim_fd); 612 return (result == -1) ? -errno : 613 process->allocFD(result, fde->filename, fde->flags, fde->mode, false); 614} 615 616 617SyscallReturn |
618fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process, | 618fcntlFunc(SyscallDesc *desc, int num, Process *process, |
619 ThreadContext *tc) 620{ 621 int index = 0; 622 int tgt_fd = process->getSyscallArg(tc, index); 623 624 int sim_fd = process->getSimFD(tgt_fd); 625 if (sim_fd < 0) 626 return -EBADF; --- 27 unchanged lines hidden (view full) --- 654 655 default: 656 warn("Unknown fcntl command %d\n", cmd); 657 return 0; 658 } 659} 660 661SyscallReturn | 619 ThreadContext *tc) 620{ 621 int index = 0; 622 int tgt_fd = process->getSyscallArg(tc, index); 623 624 int sim_fd = process->getSimFD(tgt_fd); 625 if (sim_fd < 0) 626 return -EBADF; --- 27 unchanged lines hidden (view full) --- 654 655 default: 656 warn("Unknown fcntl command %d\n", cmd); 657 return 0; 658 } 659} 660 661SyscallReturn |
662fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process, | 662fcntl64Func(SyscallDesc *desc, int num, Process *process, |
663 ThreadContext *tc) 664{ 665 int index = 0; 666 int tgt_fd = process->getSyscallArg(tc, index); 667 668 int sim_fd = process->getSimFD(tgt_fd); 669 if (sim_fd < 0) 670 return -EBADF; --- 15 unchanged lines hidden (view full) --- 686 // to the underlying OS 687 warn("fcntl64(%d, %d) passed through to host\n", tgt_fd, cmd); 688 return fcntl(sim_fd, cmd); 689 // return 0; 690 } 691} 692 693SyscallReturn | 663 ThreadContext *tc) 664{ 665 int index = 0; 666 int tgt_fd = process->getSyscallArg(tc, index); 667 668 int sim_fd = process->getSimFD(tgt_fd); 669 if (sim_fd < 0) 670 return -EBADF; --- 15 unchanged lines hidden (view full) --- 686 // to the underlying OS 687 warn("fcntl64(%d, %d) passed through to host\n", tgt_fd, cmd); 688 return fcntl(sim_fd, cmd); 689 // return 0; 690 } 691} 692 693SyscallReturn |
694pipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 695 ThreadContext *tc) | 694pipePseudoFunc(SyscallDesc *desc, int callnum, Process *process, 695 ThreadContext *tc) |
696{ 697 int fds[2], sim_fds[2]; 698 int pipe_retval = pipe(fds); 699 700 if (pipe_retval < 0) { 701 // error 702 return pipe_retval; 703 } --- 5 unchanged lines hidden (view full) --- 709 // Alpha Linux convention for pipe() is that fd[0] is returned as 710 // the return value of the function, and fd[1] is returned in r20. 711 tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 712 return sim_fds[0]; 713} 714 715 716SyscallReturn | 696{ 697 int fds[2], sim_fds[2]; 698 int pipe_retval = pipe(fds); 699 700 if (pipe_retval < 0) { 701 // error 702 return pipe_retval; 703 } --- 5 unchanged lines hidden (view full) --- 709 // Alpha Linux convention for pipe() is that fd[0] is returned as 710 // the return value of the function, and fd[1] is returned in r20. 711 tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]); 712 return sim_fds[0]; 713} 714 715 716SyscallReturn |
717getpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 718 ThreadContext *tc) | 717getpidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, 718 ThreadContext *tc) |
719{ 720 // Make up a PID. There's no interprocess communication in 721 // fake_syscall mode, so there's no way for a process to know it's 722 // not getting a unique value. 723 724 tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 725 return process->pid(); 726} 727 728 729SyscallReturn | 719{ 720 // Make up a PID. There's no interprocess communication in 721 // fake_syscall mode, so there's no way for a process to know it's 722 // not getting a unique value. 723 724 tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); 725 return process->pid(); 726} 727 728 729SyscallReturn |
730getuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 731 ThreadContext *tc) | 730getuidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, 731 ThreadContext *tc) |
732{ 733 // Make up a UID and EUID... it shouldn't matter, and we want the 734 // simulation to be deterministic. 735 736 // EUID goes in r20. 737 tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 738 return process->uid(); // UID 739} 740 741 742SyscallReturn | 732{ 733 // Make up a UID and EUID... it shouldn't matter, and we want the 734 // simulation to be deterministic. 735 736 // EUID goes in r20. 737 tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID 738 return process->uid(); // UID 739} 740 741 742SyscallReturn |
743getgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 744 ThreadContext *tc) | 743getgidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, 744 ThreadContext *tc) |
745{ 746 // Get current group ID. EGID goes in r20. 747 tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 748 return process->gid(); 749} 750 751 752SyscallReturn | 745{ 746 // Get current group ID. EGID goes in r20. 747 tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID 748 return process->gid(); 749} 750 751 752SyscallReturn |
753setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 753setuidFunc(SyscallDesc *desc, int callnum, Process *process, |
754 ThreadContext *tc) 755{ 756 // can't fathom why a benchmark would call this. 757 int index = 0; 758 warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 759 return 0; 760} 761 762SyscallReturn | 754 ThreadContext *tc) 755{ 756 // can't fathom why a benchmark would call this. 757 int index = 0; 758 warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); 759 return 0; 760} 761 762SyscallReturn |
763getpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 763getpidFunc(SyscallDesc *desc, int callnum, Process *process, |
764 ThreadContext *tc) 765{ 766 // Make up a PID. There's no interprocess communication in 767 // fake_syscall mode, so there's no way for a process to know it's 768 // not getting a unique value. 769 770 tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 771 return process->pid(); 772} 773 774SyscallReturn | 764 ThreadContext *tc) 765{ 766 // Make up a PID. There's no interprocess communication in 767 // fake_syscall mode, so there's no way for a process to know it's 768 // not getting a unique value. 769 770 tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID 771 return process->pid(); 772} 773 774SyscallReturn |
775getppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 776 ThreadContext *tc) | 775getppidFunc(SyscallDesc *desc, int callnum, Process *process, 776 ThreadContext *tc) |
777{ 778 return process->ppid(); 779} 780 781SyscallReturn | 777{ 778 return process->ppid(); 779} 780 781SyscallReturn |
782getuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 782getuidFunc(SyscallDesc *desc, int callnum, Process *process, |
783 ThreadContext *tc) 784{ 785 return process->uid(); // UID 786} 787 788SyscallReturn | 783 ThreadContext *tc) 784{ 785 return process->uid(); // UID 786} 787 788SyscallReturn |
789geteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 790 ThreadContext *tc) | 789geteuidFunc(SyscallDesc *desc, int callnum, Process *process, 790 ThreadContext *tc) |
791{ 792 return process->euid(); // UID 793} 794 795SyscallReturn | 791{ 792 return process->euid(); // UID 793} 794 795SyscallReturn |
796getgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 796getgidFunc(SyscallDesc *desc, int callnum, Process *process, |
797 ThreadContext *tc) 798{ 799 return process->gid(); 800} 801 802SyscallReturn | 797 ThreadContext *tc) 798{ 799 return process->gid(); 800} 801 802SyscallReturn |
803getegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 804 ThreadContext *tc) | 803getegidFunc(SyscallDesc *desc, int callnum, Process *process, 804 ThreadContext *tc) |
805{ 806 return process->egid(); 807} 808 809 810SyscallReturn | 805{ 806 return process->egid(); 807} 808 809 810SyscallReturn |
811cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 812 ThreadContext *tc) | 811cloneFunc(SyscallDesc *desc, int callnum, Process *process, 812 ThreadContext *tc) |
813{ 814 int index = 0; 815 IntReg flags = process->getSyscallArg(tc, index); 816 IntReg newStack = process->getSyscallArg(tc, index); 817 818 DPRINTF(SyscallVerbose, "In sys_clone:\n"); 819 DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 820 DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); --- 64 unchanged lines hidden (view full) --- 885 return 1; 886 } else { 887 fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 888 return 0; 889 } 890} 891 892SyscallReturn | 813{ 814 int index = 0; 815 IntReg flags = process->getSyscallArg(tc, index); 816 IntReg newStack = process->getSyscallArg(tc, index); 817 818 DPRINTF(SyscallVerbose, "In sys_clone:\n"); 819 DPRINTF(SyscallVerbose, " Flags=%llx\n", flags); 820 DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack); --- 64 unchanged lines hidden (view full) --- 885 return 1; 886 } else { 887 fatal("Called sys_clone, but no unallocated thread contexts found!\n"); 888 return 0; 889 } 890} 891 892SyscallReturn |
893fallocateFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 893fallocateFunc(SyscallDesc *desc, int callnum, Process *process, |
894 ThreadContext *tc) 895{ 896#if NO_FALLOCATE 897 warn("Host OS cannot support calls to fallocate. Ignoring syscall"); 898#else 899 int index = 0; 900 int tgt_fd = process->getSyscallArg(tc, index); 901 int mode = process->getSyscallArg(tc, index); --- 7 unchanged lines hidden (view full) --- 909 int result = fallocate(sim_fd, mode, offset, len); 910 if (result < 0) 911 return -errno; 912#endif 913 return 0; 914} 915 916SyscallReturn | 894 ThreadContext *tc) 895{ 896#if NO_FALLOCATE 897 warn("Host OS cannot support calls to fallocate. Ignoring syscall"); 898#else 899 int index = 0; 900 int tgt_fd = process->getSyscallArg(tc, index); 901 int mode = process->getSyscallArg(tc, index); --- 7 unchanged lines hidden (view full) --- 909 int result = fallocate(sim_fd, mode, offset, len); 910 if (result < 0) 911 return -errno; 912#endif 913 return 0; 914} 915 916SyscallReturn |
917accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc, 918 int index) | 917accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, 918 int index) |
919{ 920 string path; 921 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 922 return -EFAULT; 923 924 // Adjust path for current working directory 925 path = p->fullPath(path); 926 927 mode_t mode = p->getSyscallArg(tc, index); 928 929 int result = access(path.c_str(), mode); 930 return (result == -1) ? -errno : result; 931} 932 933SyscallReturn | 919{ 920 string path; 921 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) 922 return -EFAULT; 923 924 // Adjust path for current working directory 925 path = p->fullPath(path); 926 927 mode_t mode = p->getSyscallArg(tc, index); 928 929 int result = access(path.c_str(), mode); 930 return (result == -1) ? -errno : result; 931} 932 933SyscallReturn |
934accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc) | 934accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) |
935{ 936 return accessFunc(desc, callnum, p, tc, 0); 937} 938 | 935{ 936 return accessFunc(desc, callnum, p, tc, 0); 937} 938 |