syscall_emul.cc (10955:9abf6a7c14ab) syscall_emul.cc (11140:cf07f8bf58db)
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 {
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 // readlink() will return the path of the binary given
411 // with the -c option, however it is possible that this
412 // will still result in incorrect behavior if one binary
413 // runs another, e.g., -c time -o "my_binary" where
414 // my_binary calls readlink(). this is a very unlikely case,
415 // so we issue a warning.
416 warn_once("readlink may yield unexpected results if multiple "
417 "binaries are used\n");
418 if (strlen(p->progName()) > bufsiz) {
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) {
419 // readlink will truncate the contents of the
420 // path to ensure it is no more than bufsiz
431 // readlink will truncate the contents of the
432 // path to ensure it is no more than bufsiz
421 strncpy((char*)buf.bufferPtr(), p->progName(), bufsiz);
422 result = bufsiz;
423 } else {
433 result = bufsiz;
434 } else {
424 // return the program's working path rather
425 // than the one for the gem5 binary itself.
426 strcpy((char*)buf.bufferPtr(), p->progName());
427 result = strlen((char*)buf.bufferPtr());
435 result = real_path_len;
428 }
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());
429 }
430
431 buf.copyOut(tc->getMemProxy());
432
433 return (result == -1) ? -errno : result;
434}
435
436SyscallReturn

--- 509 unchanged lines hidden ---
442 }
443
444 buf.copyOut(tc->getMemProxy());
445
446 return (result == -1) ? -errno : result;
447}
448
449SyscallReturn

--- 509 unchanged lines hidden ---