syscall_emul.cc (10932:cafae9abd4e4) syscall_emul.cc (10955:9abf6a7c14ab)
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;

--- 351 unchanged lines hidden (view full) ---

360 string cwd = p->getcwd();
361 if (!cwd.empty()) {
362 if (cwd.length() >= size) {
363 // Buffer too small
364 return -ERANGE;
365 }
366 strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
367 result = cwd.length();
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;

--- 351 unchanged lines hidden (view full) ---

360 string cwd = p->getcwd();
361 if (!cwd.empty()) {
362 if (cwd.length() >= size) {
363 // Buffer too small
364 return -ERANGE;
365 }
366 strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
367 result = cwd.length();
368 }
369 else {
368 } else {
370 if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
371 result = strlen((char *)buf.bufferPtr());
369 if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
370 result = strlen((char *)buf.bufferPtr());
372 }
373 else {
371 } else {
374 result = -1;
375 }
376 }
377
378 buf.copyOut(tc->getMemProxy());
379
380 return (result == -1) ? -errno : result;
381}

--- 18 unchanged lines hidden (view full) ---

400 // Adjust path for current working directory
401 path = p->fullPath(path);
402
403 Addr bufPtr = p->getSyscallArg(tc, index);
404 size_t bufsiz = p->getSyscallArg(tc, index);
405
406 BufferArg buf(bufPtr, bufsiz);
407
372 result = -1;
373 }
374 }
375
376 buf.copyOut(tc->getMemProxy());
377
378 return (result == -1) ? -errno : result;
379}

--- 18 unchanged lines hidden (view full) ---

398 // Adjust path for current working directory
399 path = p->fullPath(path);
400
401 Addr bufPtr = p->getSyscallArg(tc, index);
402 size_t bufsiz = p->getSyscallArg(tc, index);
403
404 BufferArg buf(bufPtr, bufsiz);
405
408 int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
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) {
419 // readlink will truncate the contents of the
420 // path to ensure it is no more than bufsiz
421 strncpy((char*)buf.bufferPtr(), p->progName(), bufsiz);
422 result = bufsiz;
423 } 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());
428 }
429 }
409
410 buf.copyOut(tc->getMemProxy());
411
412 return (result == -1) ? -errno : result;
413}
414
415SyscallReturn
416unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)

--- 508 unchanged lines hidden ---
430
431 buf.copyOut(tc->getMemProxy());
432
433 return (result == -1) ? -errno : result;
434}
435
436SyscallReturn
437unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)

--- 508 unchanged lines hidden ---