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; --- 393 unchanged lines hidden (view full) --- 402 size_t bufsiz = p->getSyscallArg(tc, index); 403 404 BufferArg buf(bufPtr, bufsiz); 405 406 int result = -1; 407 if (path != "/proc/self/exe") { 408 result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz); 409 } else { |
410 // Emulate readlink() called on '/proc/self/exe' should return the 411 // absolute path of the binary running in the simulated system (the 412 // LiveProcess' executable). It is possible that using this path in 413 // the simulated system will result in unexpected behavior if: 414 // 1) One binary runs another (e.g., -c time -o "my_binary"), and 415 // called binary calls readlink(). 416 // 2) The host's full path to the running benchmark changes from one 417 // simulation to another. This can result in different simulated 418 // performance since the simulated system will process the binary 419 // path differently, even if the binary itself does not change. 420 421 // Get the absolute canonical path to the running application 422 char real_path[PATH_MAX]; 423 char *check_real_path = realpath(p->progName(), real_path); 424 if (!check_real_path) { 425 fatal("readlink('/proc/self/exe') unable to resolve path to " 426 "executable: %s", p->progName()); 427 } 428 strncpy((char*)buf.bufferPtr(), real_path, bufsiz); 429 size_t real_path_len = strlen(real_path); 430 if (real_path_len > bufsiz) { |
431 // readlink will truncate the contents of the 432 // path to ensure it is no more than bufsiz |
433 result = bufsiz; 434 } else { |
435 result = real_path_len; |
436 } |
437 438 // Issue a warning about potential unexpected results 439 warn_once("readlink() called on '/proc/self/exe' may yield unexpected " 440 "results in various settings.\n Returning '%s'\n", 441 (char*)buf.bufferPtr()); |
442 } 443 444 buf.copyOut(tc->getMemProxy()); 445 446 return (result == -1) ? -errno : result; 447} 448 449SyscallReturn --- 509 unchanged lines hidden --- |