2003-12-02 04:34:38 +01:00
|
|
|
/*
|
2005-03-10 20:20:12 +01:00
|
|
|
* Copyright (c) 2003-2005 The Regents of The University of Michigan
|
2003-12-02 04:34:38 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
|
|
|
* Kevin Lim
|
2003-12-02 04:34:38 +01:00
|
|
|
*/
|
|
|
|
|
2005-01-15 00:34:56 +01:00
|
|
|
#ifndef __SIM_SYSCALL_EMUL_HH__
|
|
|
|
#define __SIM_SYSCALL_EMUL_HH__
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-06-18 00:27:28 +02:00
|
|
|
#define NO_STAT64 (defined(__APPLE__) || defined(__OpenBSD__) || \
|
|
|
|
defined(__FreeBSD__) || defined(__CYGWIN__))
|
2006-02-10 20:21:32 +01:00
|
|
|
|
2003-12-02 04:34:38 +01:00
|
|
|
///
|
|
|
|
/// @file syscall_emul.hh
|
|
|
|
///
|
|
|
|
/// This file defines objects used to emulate syscalls from the target
|
|
|
|
/// application on the host machine.
|
|
|
|
|
2005-06-30 06:42:27 +02:00
|
|
|
#ifdef __CYGWIN32__
|
2008-09-10 20:26:15 +02:00
|
|
|
#include <sys/fcntl.h> // for O_BINARY
|
2005-06-30 06:42:27 +02:00
|
|
|
#endif
|
2006-09-16 03:43:12 +02:00
|
|
|
#include <sys/stat.h>
|
2010-05-06 17:42:18 +02:00
|
|
|
#include <sys/time.h>
|
2011-04-15 19:44:06 +02:00
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <fcntl.h>
|
2010-05-06 17:42:18 +02:00
|
|
|
|
2011-04-15 19:44:06 +02:00
|
|
|
#include <cerrno>
|
2010-05-06 17:42:18 +02:00
|
|
|
#include <string>
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "base/chunk_generator.hh"
|
2008-09-10 20:26:15 +02:00
|
|
|
#include "base/intmath.hh" // for RoundUp
|
2006-03-12 23:21:59 +01:00
|
|
|
#include "base/misc.hh"
|
2005-01-15 00:34:56 +01:00
|
|
|
#include "base/trace.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "base/types.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2006-02-16 04:05:23 +01:00
|
|
|
#include "cpu/base.hh"
|
2006-06-06 23:32:21 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/SyscallVerbose.hh"
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "mem/page_table.hh"
|
2012-01-17 19:55:08 +01:00
|
|
|
#include "mem/se_translating_port_proxy.hh"
|
2010-09-14 04:26:03 +02:00
|
|
|
#include "sim/byteswap.hh"
|
2005-01-15 00:34:56 +01:00
|
|
|
#include "sim/process.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "sim/system.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// System call descriptor.
|
|
|
|
///
|
|
|
|
class SyscallDesc {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Typedef for target syscall handler functions.
|
2005-03-09 21:52:10 +01:00
|
|
|
typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *, ThreadContext *);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2008-09-10 20:26:15 +02:00
|
|
|
const char *name; //!< Syscall name (e.g., "open").
|
|
|
|
FuncPtr funcPtr; //!< Pointer to emulation function.
|
|
|
|
int flags; //!< Flags (see Flags enum).
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
/// Flag values for controlling syscall behavior.
|
|
|
|
enum Flags {
|
|
|
|
/// Don't set return regs according to funcPtr return value.
|
|
|
|
/// Used for syscalls with non-standard return conventions
|
2006-06-06 23:32:21 +02:00
|
|
|
/// that explicitly set the ThreadContext regs (e.g.,
|
2003-12-02 04:34:38 +01:00
|
|
|
/// sigreturn).
|
|
|
|
SuppressReturnValue = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Constructor.
|
|
|
|
SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
|
|
|
|
: name(_name), funcPtr(_funcPtr), flags(_flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emulate the syscall. Public interface for calling through funcPtr.
|
2006-09-17 09:00:55 +02:00
|
|
|
void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc);
|
2003-12-02 04:34:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BaseBufferArg {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size)
|
|
|
|
{
|
|
|
|
bufPtr = new uint8_t[size];
|
|
|
|
// clear out buffer: in case we only partially populate this,
|
|
|
|
// and then do a copyOut(), we want to make sure we don't
|
|
|
|
// introduce any random junk into the simulated address space
|
|
|
|
memset(bufPtr, 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~BaseBufferArg() { delete [] bufPtr; }
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy data into simulator space (read from target memory)
|
|
|
|
//
|
2012-01-17 19:55:08 +01:00
|
|
|
virtual bool copyIn(SETranslatingPortProxy* memproxy)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2012-01-17 19:55:08 +01:00
|
|
|
memproxy->readBlob(addr, bufPtr, size);
|
2008-09-10 20:26:15 +02:00
|
|
|
return true; // no EFAULT detection for now
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy data out of simulator space (write to target memory)
|
|
|
|
//
|
2012-01-17 19:55:08 +01:00
|
|
|
virtual bool copyOut(SETranslatingPortProxy* memproxy)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2012-01-17 19:55:08 +01:00
|
|
|
memproxy->writeBlob(addr, bufPtr, size);
|
2008-09-10 20:26:15 +02:00
|
|
|
return true; // no EFAULT detection for now
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Addr addr;
|
|
|
|
int size;
|
|
|
|
uint8_t *bufPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BufferArg : public BaseBufferArg
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
|
2008-09-10 20:26:15 +02:00
|
|
|
void *bufferPtr() { return bufPtr; }
|
2003-12-02 04:34:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class TypedBufferArg : public BaseBufferArg
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// user can optionally specify a specific number of bytes to
|
|
|
|
// allocate to deal with those structs that have variable-size
|
|
|
|
// arrays at the end
|
|
|
|
TypedBufferArg(Addr _addr, int _size = sizeof(T))
|
|
|
|
: BaseBufferArg(_addr, _size)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// type case
|
|
|
|
operator T*() { return (T *)bufPtr; }
|
|
|
|
|
|
|
|
// dereference operators
|
2008-09-10 20:26:15 +02:00
|
|
|
T &operator*() { return *((T *)bufPtr); }
|
|
|
|
T* operator->() { return (T *)bufPtr; }
|
2004-02-03 00:55:35 +01:00
|
|
|
T &operator[](int i) { return ((T *)bufPtr)[i]; }
|
2003-12-02 04:34:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// The following emulation functions are generic enough that they
|
|
|
|
// don't need to be recompiled for different emulated OS's. They are
|
|
|
|
// defined in sim/syscall_emul.cc.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Handler for unimplemented syscalls that we haven't thought about.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Handler for unimplemented syscalls that we never intend to
|
|
|
|
/// implement (signal handling, etc.) and should not affect the correct
|
|
|
|
/// behavior of the program. Print a warning only if the appropriate
|
|
|
|
/// trace flag is enabled. Return success to the target program.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2011-03-18 01:20:20 +01:00
|
|
|
SyscallReturn ignoreWarnOnceFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
/// Target exit() handler: terminate current context.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn exitFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
/// Target exit_group() handler: terminate simulation. (exit all threads)
|
|
|
|
SyscallReturn exitGroupFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target getpagesize() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
2008-11-15 18:30:10 +01:00
|
|
|
/// Target brk() handler: set brk address.
|
|
|
|
SyscallReturn brkFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Target close() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn closeFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Target read() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn readFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Target write() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn writeFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Target lseek() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn lseekFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
2007-03-03 04:34:55 +01:00
|
|
|
/// Target _llseek() handler.
|
|
|
|
SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target munmap() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn munmapFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 07:39:27 +01:00
|
|
|
|
|
|
|
/// Target gethostname() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
/// Target getcwd() handler.
|
|
|
|
SyscallReturn getcwdFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
|
|
|
/// Target unlink() handler.
|
|
|
|
SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
2004-02-05 18:16:17 +01:00
|
|
|
/// Target unlink() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
/// Target mkdir() handler.
|
|
|
|
SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
2004-02-05 18:16:17 +01:00
|
|
|
/// Target rename() handler.
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn renameFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/// Target truncate() handler.
|
|
|
|
SyscallReturn truncateFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/// Target ftruncate() handler.
|
|
|
|
SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-10-30 17:31:55 +01:00
|
|
|
/// Target truncate64() handler.
|
|
|
|
SyscallReturn truncate64Func(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
2009-10-24 19:53:58 +02:00
|
|
|
/// Target ftruncate64() handler.
|
|
|
|
SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
/// Target umask() handler.
|
|
|
|
SyscallReturn umaskFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
|
|
|
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target chown() handler.
|
|
|
|
SyscallReturn chownFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
/// Target fchown() handler.
|
|
|
|
SyscallReturn fchownFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2006-08-28 16:39:56 +02:00
|
|
|
/// Target dup() handler.
|
|
|
|
SyscallReturn dupFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *process, ThreadContext *tc);
|
2006-08-28 16:39:56 +02:00
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
/// Target fnctl() handler.
|
|
|
|
SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *process, ThreadContext *tc);
|
2006-02-19 05:44:22 +01:00
|
|
|
|
2006-06-09 23:07:13 +02:00
|
|
|
/// Target fcntl64() handler.
|
|
|
|
SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *process, ThreadContext *tc);
|
2006-06-09 23:07:13 +02:00
|
|
|
|
2006-03-09 21:42:09 +01:00
|
|
|
/// Target setuid() handler.
|
|
|
|
SyscallReturn setuidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getpid() handler.
|
|
|
|
SyscallReturn getpidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getuid() handler.
|
|
|
|
SyscallReturn getuidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getgid() handler.
|
|
|
|
SyscallReturn getgidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getppid() handler.
|
|
|
|
SyscallReturn getppidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target geteuid() handler.
|
|
|
|
SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getegid() handler.
|
|
|
|
SyscallReturn getegidFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
/// Target clone() handler.
|
|
|
|
SyscallReturn cloneFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
/// Pseudo Funcs - These functions use a different return convension,
|
|
|
|
/// returning a second value in a register other than the normal return register
|
|
|
|
SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *process, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getpidPseudo() handler.
|
|
|
|
SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getuidPseudo() handler.
|
|
|
|
SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
/// Target getgidPseudo() handler.
|
|
|
|
SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
|
2006-09-17 09:00:55 +02:00
|
|
|
LiveProcess *p, ThreadContext *tc);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
|
|
|
|
2005-01-15 00:34:56 +01:00
|
|
|
/// A readable name for 1,000,000, for converting microseconds to seconds.
|
|
|
|
const int one_million = 1000000;
|
|
|
|
|
|
|
|
/// Approximate seconds since the epoch (1/1/1970). About a billion,
|
|
|
|
/// by my reckoning. We want to keep this a constant (not use the
|
|
|
|
/// real-world time) to keep simulations repeatable.
|
|
|
|
const unsigned seconds_since_epoch = 1000000000;
|
|
|
|
|
|
|
|
/// Helper function to convert current elapsed time to seconds and
|
|
|
|
/// microseconds.
|
|
|
|
template <class T1, class T2>
|
|
|
|
void
|
|
|
|
getElapsedTime(T1 &sec, T2 &usec)
|
|
|
|
{
|
2011-01-08 06:50:29 +01:00
|
|
|
int elapsed_usecs = curTick() / SimClock::Int::us;
|
2005-01-15 00:34:56 +01:00
|
|
|
sec = elapsed_usecs / one_million;
|
|
|
|
usec = elapsed_usecs % one_million;
|
|
|
|
}
|
|
|
|
|
2003-12-02 04:34:38 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// The following emulation functions are generic, but need to be
|
|
|
|
// templated to account for differences in types, constants, etc.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-09-16 03:43:12 +02:00
|
|
|
#if NO_STAT64
|
|
|
|
typedef struct stat hst_stat;
|
|
|
|
typedef struct stat hst_stat64;
|
|
|
|
#else
|
|
|
|
typedef struct stat hst_stat;
|
|
|
|
typedef struct stat64 hst_stat64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//// Helper function to convert a host stat buffer to a target stat
|
|
|
|
//// buffer. Also copies the target buffer out to the simulated
|
|
|
|
//// memory space. Used by stat(), fstat(), and lstat().
|
|
|
|
|
|
|
|
template <typename target_stat, typename host_stat>
|
|
|
|
static void
|
|
|
|
convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
|
|
|
|
{
|
2007-03-09 23:14:25 +01:00
|
|
|
using namespace TheISA;
|
|
|
|
|
2006-09-16 03:43:12 +02:00
|
|
|
if (fakeTTY)
|
|
|
|
tgt->st_dev = 0xA;
|
|
|
|
else
|
|
|
|
tgt->st_dev = host->st_dev;
|
|
|
|
tgt->st_dev = htog(tgt->st_dev);
|
|
|
|
tgt->st_ino = host->st_ino;
|
|
|
|
tgt->st_ino = htog(tgt->st_ino);
|
2006-10-16 03:54:59 +02:00
|
|
|
tgt->st_mode = host->st_mode;
|
2008-07-25 01:31:33 +02:00
|
|
|
if (fakeTTY) {
|
|
|
|
// Claim to be a character device
|
|
|
|
tgt->st_mode &= ~S_IFMT; // Clear S_IFMT
|
|
|
|
tgt->st_mode |= S_IFCHR; // Set S_IFCHR
|
|
|
|
}
|
2006-10-16 03:54:59 +02:00
|
|
|
tgt->st_mode = htog(tgt->st_mode);
|
|
|
|
tgt->st_nlink = host->st_nlink;
|
|
|
|
tgt->st_nlink = htog(tgt->st_nlink);
|
|
|
|
tgt->st_uid = host->st_uid;
|
|
|
|
tgt->st_uid = htog(tgt->st_uid);
|
|
|
|
tgt->st_gid = host->st_gid;
|
|
|
|
tgt->st_gid = htog(tgt->st_gid);
|
2006-09-16 03:43:12 +02:00
|
|
|
if (fakeTTY)
|
|
|
|
tgt->st_rdev = 0x880d;
|
|
|
|
else
|
|
|
|
tgt->st_rdev = host->st_rdev;
|
|
|
|
tgt->st_rdev = htog(tgt->st_rdev);
|
|
|
|
tgt->st_size = host->st_size;
|
|
|
|
tgt->st_size = htog(tgt->st_size);
|
2006-09-17 09:00:55 +02:00
|
|
|
tgt->st_atimeX = host->st_atime;
|
2006-09-16 03:43:12 +02:00
|
|
|
tgt->st_atimeX = htog(tgt->st_atimeX);
|
2006-09-17 09:00:55 +02:00
|
|
|
tgt->st_mtimeX = host->st_mtime;
|
2006-09-16 03:43:12 +02:00
|
|
|
tgt->st_mtimeX = htog(tgt->st_mtimeX);
|
2006-09-17 09:00:55 +02:00
|
|
|
tgt->st_ctimeX = host->st_ctime;
|
2006-09-16 03:43:12 +02:00
|
|
|
tgt->st_ctimeX = htog(tgt->st_ctimeX);
|
2007-02-14 18:58:28 +01:00
|
|
|
// Force the block size to be 8k. This helps to ensure buffered io works
|
|
|
|
// consistently across different hosts.
|
|
|
|
tgt->st_blksize = 0x2000;
|
2006-09-16 03:43:12 +02:00
|
|
|
tgt->st_blksize = htog(tgt->st_blksize);
|
|
|
|
tgt->st_blocks = host->st_blocks;
|
|
|
|
tgt->st_blocks = htog(tgt->st_blocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same for stat64
|
|
|
|
|
|
|
|
template <typename target_stat, typename host_stat64>
|
|
|
|
static void
|
|
|
|
convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
|
|
|
|
{
|
2007-03-09 23:14:25 +01:00
|
|
|
using namespace TheISA;
|
|
|
|
|
2006-09-16 03:43:12 +02:00
|
|
|
convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
|
|
|
|
#if defined(STAT_HAVE_NSEC)
|
|
|
|
tgt->st_atime_nsec = host->st_atime_nsec;
|
|
|
|
tgt->st_atime_nsec = htog(tgt->st_atime_nsec);
|
|
|
|
tgt->st_mtime_nsec = host->st_mtime_nsec;
|
|
|
|
tgt->st_mtime_nsec = htog(tgt->st_mtime_nsec);
|
|
|
|
tgt->st_ctime_nsec = host->st_ctime_nsec;
|
|
|
|
tgt->st_ctime_nsec = htog(tgt->st_ctime_nsec);
|
|
|
|
#else
|
|
|
|
tgt->st_atime_nsec = 0;
|
|
|
|
tgt->st_mtime_nsec = 0;
|
|
|
|
tgt->st_ctime_nsec = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//Here are a couple convenience functions
|
|
|
|
template<class OS>
|
|
|
|
static void
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStatBuf(SETranslatingPortProxy* mem, Addr addr,
|
2006-09-16 03:43:12 +02:00
|
|
|
hst_stat *host, bool fakeTTY = false)
|
|
|
|
{
|
|
|
|
typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
|
|
|
|
tgt_stat_buf tgt(addr);
|
|
|
|
convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
|
|
|
|
tgt.copyOut(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class OS>
|
|
|
|
static void
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStat64Buf(SETranslatingPortProxy* mem, Addr addr,
|
2006-09-16 03:43:12 +02:00
|
|
|
hst_stat64 *host, bool fakeTTY = false)
|
|
|
|
{
|
|
|
|
typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
|
|
|
|
tgt_stat_buf tgt(addr);
|
2009-10-24 19:53:58 +02:00
|
|
|
convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
|
2006-09-16 03:43:12 +02:00
|
|
|
tgt.copyOut(mem);
|
|
|
|
}
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target ioctl() handler. For the most part, programs call ioctl()
|
|
|
|
/// only to find out if their stdout is a tty, to determine whether to
|
|
|
|
/// do line or block buffering.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
|
|
|
unsigned req = process->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-11-11 03:05:31 +01:00
|
|
|
DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0) {
|
|
|
|
// doesn't map to any simulator fd: not a valid target fd
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EBADF;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (req) {
|
2007-03-05 04:26:49 +01:00
|
|
|
case OS::TIOCISATTY_:
|
|
|
|
case OS::TIOCGETP_:
|
|
|
|
case OS::TIOCSETP_:
|
|
|
|
case OS::TIOCSETN_:
|
|
|
|
case OS::TIOCSETC_:
|
|
|
|
case OS::TIOCGETC_:
|
|
|
|
case OS::TIOCGETS_:
|
|
|
|
case OS::TIOCGETA_:
|
2009-10-24 19:53:59 +02:00
|
|
|
case OS::TCSETAW_:
|
2005-03-10 20:20:12 +01:00
|
|
|
return -ENOTTY;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
default:
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n",
|
|
|
|
fd, req, tc->pcState());
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target open() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index)))
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EFAULT;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
if (path == "/dev/sysdev0") {
|
|
|
|
// This is a memory-mapped high-resolution timer device on Alpha.
|
|
|
|
// We don't support it, so just punt.
|
2005-06-03 22:19:34 +02:00
|
|
|
warn("Ignoring open(%s, ...)\n", path);
|
2005-03-10 20:20:12 +01:00
|
|
|
return -ENOENT;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int tgtFlags = process->getSyscallArg(tc, index);
|
|
|
|
int mode = process->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
int hostFlags = 0;
|
|
|
|
|
|
|
|
// translate open flags
|
|
|
|
for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
|
|
|
|
if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
|
|
|
|
tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
|
|
|
|
hostFlags |= OS::openFlagTable[i].hostFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// any target flags left?
|
|
|
|
if (tgtFlags != 0)
|
2005-06-03 22:19:34 +02:00
|
|
|
warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
#ifdef __CYGWIN32__
|
|
|
|
hostFlags |= O_BINARY;
|
|
|
|
#endif
|
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
|
|
|
|
|
2009-01-18 00:56:46 +01:00
|
|
|
int fd;
|
|
|
|
if (!path.compare(0, 6, "/proc/") || !path.compare(0, 8, "/system/") ||
|
|
|
|
!path.compare(0, 10, "/platform/") || !path.compare(0, 5, "/sys/")) {
|
|
|
|
// It's a proc/sys entery and requires special handling
|
|
|
|
fd = OS::openSpecialFile(path, process, tc);
|
|
|
|
return (fd == -1) ? -1 : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false);
|
|
|
|
} else {
|
|
|
|
// open the file
|
|
|
|
fd = open(path.c_str(), hostFlags, mode);
|
|
|
|
return (fd == -1) ? -errno : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false);
|
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-16 07:36:47 +02:00
|
|
|
/// Target sysinfo() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
|
|
|
sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
TypedBufferArg<typename OS::tgt_sysinfo>
|
|
|
|
sysinfo(process->getSyscallArg(tc, index));
|
2009-09-16 07:36:47 +02:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
sysinfo->uptime=seconds_since_epoch;
|
|
|
|
sysinfo->totalram=process->system->memSize();
|
2009-09-16 07:36:47 +02:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
sysinfo.copyOut(tc->getMemProxy());
|
2009-09-16 07:36:47 +02:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
return 0;
|
2009-09-16 07:36:47 +02:00
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target chmod() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
2005-11-22 18:08:08 +01:00
|
|
|
return -EFAULT;
|
2009-10-30 08:44:55 +01:00
|
|
|
}
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t mode = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
mode_t hostMode = 0;
|
|
|
|
|
|
|
|
// XXX translate mode flags via OS::something???
|
|
|
|
hostMode = mode;
|
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
// do the chmod
|
|
|
|
int result = chmod(path.c_str(), hostMode);
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Target fchmod() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0) {
|
|
|
|
// doesn't map to any simulator fd: not a valid target fd
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t mode = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
mode_t hostMode = 0;
|
|
|
|
|
|
|
|
// XXX translate mode flags via OS::someting???
|
|
|
|
hostMode = mode;
|
|
|
|
|
|
|
|
// do the fchmod
|
|
|
|
int result = fchmod(process->sim_fd(fd), hostMode);
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-16 23:47:39 +01:00
|
|
|
/// Target mremap() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
|
|
|
mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
Addr start = process->getSyscallArg(tc, index);
|
|
|
|
uint64_t old_length = process->getSyscallArg(tc, index);
|
|
|
|
uint64_t new_length = process->getSyscallArg(tc, index);
|
|
|
|
uint64_t flags = process->getSyscallArg(tc, index);
|
2009-02-16 23:47:39 +01:00
|
|
|
|
|
|
|
if ((start % TheISA::VMPageSize != 0) ||
|
|
|
|
(new_length % TheISA::VMPageSize != 0)) {
|
|
|
|
warn("mremap failing: arguments not page aligned");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_length > old_length) {
|
|
|
|
if ((start + old_length) == process->mmap_end) {
|
|
|
|
uint64_t diff = new_length - old_length;
|
2011-10-23 07:30:08 +02:00
|
|
|
process->allocateMem(process->mmap_end, diff);
|
2009-02-16 23:47:39 +01:00
|
|
|
process->mmap_end += diff;
|
|
|
|
return start;
|
|
|
|
} else {
|
|
|
|
// sys/mman.h defined MREMAP_MAYMOVE
|
|
|
|
if (!(flags & 1)) {
|
|
|
|
warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
} else {
|
|
|
|
process->pTable->remap(start, old_length, process->mmap_end);
|
|
|
|
warn("mremapping to totally new vaddr %08p-%08p, adding %d\n",
|
|
|
|
process->mmap_end, process->mmap_end + new_length, new_length);
|
|
|
|
start = process->mmap_end;
|
|
|
|
// add on the remaining unallocated pages
|
2011-10-23 07:30:08 +02:00
|
|
|
process->allocateMem(start + old_length,
|
|
|
|
new_length - old_length);
|
2009-02-16 23:47:39 +01:00
|
|
|
process->mmap_end += new_length;
|
|
|
|
warn("returning %08p as start\n", start);
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-23 07:30:08 +02:00
|
|
|
process->pTable->unmap(start + new_length, old_length - new_length);
|
2009-02-16 23:47:39 +01:00
|
|
|
return start;
|
|
|
|
}
|
|
|
|
}
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target stat() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2003-12-02 04:34:38 +01:00
|
|
|
struct stat hostBuf;
|
|
|
|
int result = stat(path.c_str(), &hostBuf);
|
|
|
|
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 18:30:12 +02:00
|
|
|
/// Target stat64() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
|
|
|
stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index)))
|
2007-09-13 18:30:12 +02:00
|
|
|
return -EFAULT;
|
2009-10-30 08:44:55 +01:00
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2007-09-13 18:30:12 +02:00
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2007-11-02 07:11:15 +01:00
|
|
|
#if NO_STAT64
|
|
|
|
struct stat hostBuf;
|
|
|
|
int result = stat(path.c_str(), &hostBuf);
|
|
|
|
#else
|
2007-09-13 18:30:12 +02:00
|
|
|
struct stat64 hostBuf;
|
|
|
|
int result = stat64(path.c_str(), &hostBuf);
|
2007-11-02 07:11:15 +01:00
|
|
|
#endif
|
2007-09-13 18:30:12 +02:00
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return -errno;
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
|
2007-09-13 18:30:12 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target fstat64() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0) {
|
|
|
|
// doesn't map to any simulator fd: not a valid target fd
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
2006-06-18 00:27:28 +02:00
|
|
|
#if NO_STAT64
|
2006-02-10 20:21:32 +01:00
|
|
|
struct stat hostBuf;
|
|
|
|
int result = fstat(process->sim_fd(fd), &hostBuf);
|
|
|
|
#else
|
|
|
|
struct stat64 hostBuf;
|
2005-11-22 18:08:08 +01:00
|
|
|
int result = fstat64(process->sim_fd(fd), &hostBuf);
|
2006-02-10 20:21:32 +01:00
|
|
|
#endif
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (fd == 1));
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target lstat() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2003-12-02 04:34:38 +01:00
|
|
|
struct stat hostBuf;
|
|
|
|
int result = lstat(path.c_str(), &hostBuf);
|
|
|
|
|
|
|
|
if (result < 0)
|
2005-03-10 20:20:12 +01:00
|
|
|
return -errno;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target lstat64() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2006-06-18 00:27:28 +02:00
|
|
|
#if NO_STAT64
|
2006-02-10 20:21:32 +01:00
|
|
|
struct stat hostBuf;
|
|
|
|
int result = lstat(path.c_str(), &hostBuf);
|
|
|
|
#else
|
2005-11-22 18:08:08 +01:00
|
|
|
struct stat64 hostBuf;
|
|
|
|
int result = lstat64(path.c_str(), &hostBuf);
|
2006-02-10 20:21:32 +01:00
|
|
|
#endif
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return -errno;
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target fstat() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-11-11 03:05:31 +01:00
|
|
|
DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
if (fd < 0)
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EBADF;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
struct stat hostBuf;
|
|
|
|
int result = fstat(fd, &hostBuf);
|
|
|
|
|
|
|
|
if (result < 0)
|
2005-03-10 20:20:12 +01:00
|
|
|
return -errno;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (fd == 1));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
/// Target statfs() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
struct statfs hostBuf;
|
|
|
|
int result = statfs(path.c_str(), &hostBuf);
|
|
|
|
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Target fstatfs() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
|
|
|
Addr bufPtr = process->getSyscallArg(tc, index);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
|
|
|
struct statfs hostBuf;
|
|
|
|
int result = fstatfs(fd, &hostBuf);
|
|
|
|
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target writev() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0) {
|
|
|
|
// doesn't map to any simulator fd: not a valid target fd
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
SETranslatingPortProxy *p = tc->getMemProxy();
|
2009-10-30 08:44:55 +01:00
|
|
|
uint64_t tiov_base = process->getSyscallArg(tc, index);
|
|
|
|
size_t count = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
struct iovec hiov[count];
|
2009-06-05 08:21:12 +02:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
2005-11-22 18:08:08 +01:00
|
|
|
typename OS::tgt_iovec tiov;
|
2006-03-12 22:38:16 +01:00
|
|
|
|
|
|
|
p->readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
|
|
|
|
(uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
|
2006-02-15 07:23:13 +01:00
|
|
|
hiov[i].iov_len = gtoh(tiov.iov_len);
|
2005-11-22 18:08:08 +01:00
|
|
|
hiov[i].iov_base = new char [hiov[i].iov_len];
|
2006-03-12 22:38:16 +01:00
|
|
|
p->readBlob(gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
|
|
|
|
hiov[i].iov_len);
|
2005-11-22 18:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int result = writev(process->sim_fd(fd), hiov, count);
|
|
|
|
|
2009-06-05 08:21:12 +02:00
|
|
|
for (size_t i = 0; i < count; ++i)
|
2005-11-22 18:08:08 +01:00
|
|
|
delete [] (char *)hiov[i].iov_base;
|
|
|
|
|
|
|
|
if (result < 0)
|
2006-03-05 03:06:40 +01:00
|
|
|
return -errno;
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target mmap() handler.
|
|
|
|
///
|
|
|
|
/// We don't really handle mmap(). If the target is mmaping an
|
|
|
|
/// anonymous region or /dev/zero, we can get away with doing basically
|
|
|
|
/// nothing (since memory is initialized to zero and the simulator
|
2011-05-23 23:29:23 +02:00
|
|
|
/// doesn't really check addresses anyway).
|
|
|
|
///
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
Addr start = p->getSyscallArg(tc, index);
|
|
|
|
uint64_t length = p->getSyscallArg(tc, index);
|
|
|
|
index++; // int prot = p->getSyscallArg(tc, index);
|
|
|
|
int flags = p->getSyscallArg(tc, index);
|
2011-05-23 23:29:23 +02:00
|
|
|
int tgt_fd = p->getSyscallArg(tc, index);
|
2009-10-30 08:44:55 +01:00
|
|
|
// int offset = p->getSyscallArg(tc, index);
|
2006-04-11 02:02:36 +02:00
|
|
|
|
2011-05-23 23:29:23 +02:00
|
|
|
if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
|
|
|
|
Process::FdMap *fd_map = p->sim_fd_obj(tgt_fd);
|
|
|
|
if (!fd_map || fd_map->fd < 0) {
|
|
|
|
warn("mmap failing: target fd %d is not valid\n", tgt_fd);
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd_map->filename != "/dev/zero") {
|
|
|
|
// This is very likely broken, but leave a warning here
|
|
|
|
// (rather than panic) in case /dev/zero is known by
|
|
|
|
// another name on some platform
|
|
|
|
warn("allowing mmap of file %s; mmap not supported on files"
|
|
|
|
" other than /dev/zero\n", fd_map->filename);
|
|
|
|
}
|
|
|
|
}
|
2009-02-16 23:47:39 +01:00
|
|
|
|
2006-04-11 02:02:36 +02:00
|
|
|
if ((start % TheISA::VMPageSize) != 0 ||
|
|
|
|
(length % TheISA::VMPageSize) != 0) {
|
|
|
|
warn("mmap failing: arguments not page-aligned: "
|
|
|
|
"start 0x%x length 0x%x",
|
|
|
|
start, length);
|
|
|
|
return -EINVAL;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2011-10-23 07:30:07 +02:00
|
|
|
// are we ok with clobbering existing mappings? only set this to
|
|
|
|
// true if the user has been warned.
|
|
|
|
bool clobber = false;
|
|
|
|
|
|
|
|
// try to use the caller-provided address if there is one
|
|
|
|
bool use_provided_address = (start != 0);
|
|
|
|
|
|
|
|
if (use_provided_address) {
|
|
|
|
// check to see if the desired address is already in use
|
|
|
|
if (!p->pTable->isUnmapped(start, length)) {
|
|
|
|
// there are existing mappings in the desired range
|
|
|
|
// whether we clobber them or not depends on whether the caller
|
|
|
|
// specified MAP_FIXED
|
|
|
|
if (flags & OS::TGT_MAP_FIXED) {
|
|
|
|
// MAP_FIXED specified: clobber existing mappings
|
|
|
|
warn("mmap: MAP_FIXED at 0x%x overwrites existing mappings\n",
|
|
|
|
start);
|
|
|
|
clobber = true;
|
|
|
|
} else {
|
|
|
|
// MAP_FIXED not specified: ignore suggested start address
|
|
|
|
warn("mmap: ignoring suggested map address 0x%x\n", start);
|
|
|
|
use_provided_address = false;
|
|
|
|
}
|
|
|
|
}
|
2006-04-11 02:02:36 +02:00
|
|
|
}
|
|
|
|
|
2011-10-23 07:30:07 +02:00
|
|
|
if (!use_provided_address) {
|
|
|
|
// no address provided, or provided address unusable:
|
|
|
|
// pick next address from our "mmap region"
|
|
|
|
if (OS::mmapGrowsDown()) {
|
|
|
|
start = p->mmap_end - length;
|
|
|
|
p->mmap_end = start;
|
|
|
|
} else {
|
|
|
|
start = p->mmap_end;
|
|
|
|
p->mmap_end += length;
|
|
|
|
}
|
2009-10-02 10:32:00 +02:00
|
|
|
}
|
2011-10-23 07:30:07 +02:00
|
|
|
|
2011-10-23 07:30:08 +02:00
|
|
|
p->allocateMem(start, length, clobber);
|
2006-04-11 02:02:36 +02:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return start;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target getrlimit() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
unsigned resource = process->getSyscallArg(tc, index);
|
|
|
|
TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
switch (resource) {
|
2006-02-10 20:21:32 +01:00
|
|
|
case OS::TGT_RLIMIT_STACK:
|
2009-02-16 23:47:39 +01:00
|
|
|
// max stack size in bytes: make up a number (8MB for now)
|
2006-02-10 20:21:32 +01:00
|
|
|
rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
|
2006-02-15 07:23:13 +01:00
|
|
|
rlp->rlim_cur = htog(rlp->rlim_cur);
|
|
|
|
rlp->rlim_max = htog(rlp->rlim_max);
|
2006-02-10 20:21:32 +01:00
|
|
|
break;
|
|
|
|
|
2009-02-16 23:47:39 +01:00
|
|
|
case OS::TGT_RLIMIT_DATA:
|
|
|
|
// max data segment size in bytes: make up a number
|
|
|
|
rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
|
|
|
|
rlp->rlim_cur = htog(rlp->rlim_cur);
|
|
|
|
rlp->rlim_max = htog(rlp->rlim_max);
|
|
|
|
break;
|
|
|
|
|
2006-02-10 20:21:32 +01:00
|
|
|
default:
|
|
|
|
std::cerr << "getrlimitFunc: unimplemented resource " << resource
|
|
|
|
<< std::endl;
|
|
|
|
abort();
|
|
|
|
break;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
rlp.copyOut(tc->getMemProxy());
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target gettimeofday() handler.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
getElapsedTime(tp->tv_sec, tp->tv_usec);
|
|
|
|
tp->tv_sec += seconds_since_epoch;
|
2009-04-21 17:17:36 +02:00
|
|
|
tp->tv_sec = TheISA::htog(tp->tv_sec);
|
|
|
|
tp->tv_usec = TheISA::htog(tp->tv_usec);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
tp.copyOut(tc->getMemProxy());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
/// Target utimes() handler.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index))) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
TypedBufferArg<typename OS::timeval [2]>
|
|
|
|
tp(process->getSyscallArg(tc, index));
|
2012-01-17 19:55:08 +01:00
|
|
|
tp.copyIn(tc->getMemProxy());
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
struct timeval hostTimeval[2];
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2006-02-15 07:23:13 +01:00
|
|
|
hostTimeval[i].tv_sec = gtoh((*tp)[i].tv_sec);
|
|
|
|
hostTimeval[i].tv_usec = gtoh((*tp)[i].tv_usec);
|
2005-11-22 18:08:08 +01:00
|
|
|
}
|
2006-11-16 21:43:11 +01:00
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
int result = utimes(path.c_str(), hostTimeval);
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-12-02 07:39:27 +01:00
|
|
|
/// Target getrusage() function.
|
2003-12-02 04:34:38 +01:00
|
|
|
template <class OS>
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
|
|
|
|
TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-11-16 22:08:29 +01:00
|
|
|
rup->ru_utime.tv_sec = 0;
|
|
|
|
rup->ru_utime.tv_usec = 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
rup->ru_stime.tv_sec = 0;
|
|
|
|
rup->ru_stime.tv_usec = 0;
|
|
|
|
rup->ru_maxrss = 0;
|
|
|
|
rup->ru_ixrss = 0;
|
|
|
|
rup->ru_idrss = 0;
|
|
|
|
rup->ru_isrss = 0;
|
|
|
|
rup->ru_minflt = 0;
|
|
|
|
rup->ru_majflt = 0;
|
|
|
|
rup->ru_nswap = 0;
|
|
|
|
rup->ru_inblock = 0;
|
|
|
|
rup->ru_oublock = 0;
|
|
|
|
rup->ru_msgsnd = 0;
|
|
|
|
rup->ru_msgrcv = 0;
|
|
|
|
rup->ru_nsignals = 0;
|
|
|
|
rup->ru_nvcsw = 0;
|
|
|
|
rup->ru_nivcsw = 0;
|
|
|
|
|
2006-11-16 22:08:29 +01:00
|
|
|
switch (who) {
|
|
|
|
case OS::TGT_RUSAGE_SELF:
|
|
|
|
getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
|
|
|
|
rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec);
|
|
|
|
rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OS::TGT_RUSAGE_CHILDREN:
|
|
|
|
// do nothing. We have no child processes, so they take no time.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// don't really handle THREAD or CHILDREN, but just warn and
|
|
|
|
// plow ahead
|
|
|
|
warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
|
|
|
|
who);
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
rup.copyOut(tc->getMemProxy());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2009-10-24 19:53:57 +02:00
|
|
|
/// Target times() function.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
|
|
|
timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
|
2009-10-24 19:53:57 +02:00
|
|
|
|
|
|
|
// Fill in the time structure (in clocks)
|
2011-01-08 06:50:29 +01:00
|
|
|
int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s;
|
2009-10-24 19:53:57 +02:00
|
|
|
bufp->tms_utime = clocks;
|
|
|
|
bufp->tms_stime = 0;
|
|
|
|
bufp->tms_cutime = 0;
|
|
|
|
bufp->tms_cstime = 0;
|
|
|
|
|
|
|
|
// Convert to host endianness
|
|
|
|
bufp->tms_utime = htog(bufp->tms_utime);
|
|
|
|
|
|
|
|
// Write back
|
2012-01-17 19:55:08 +01:00
|
|
|
bufp.copyOut(tc->getMemProxy());
|
2009-10-24 19:53:57 +02:00
|
|
|
|
|
|
|
// Return clock ticks since system boot
|
|
|
|
return clocks;
|
|
|
|
}
|
2006-04-13 11:42:18 +02:00
|
|
|
|
2009-10-24 19:53:57 +02:00
|
|
|
/// Target time() function.
|
|
|
|
template <class OS>
|
|
|
|
SyscallReturn
|
|
|
|
timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
typename OS::time_t sec, usec;
|
|
|
|
getElapsedTime(sec, usec);
|
|
|
|
sec += seconds_since_epoch;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
Addr taddr = (Addr)process->getSyscallArg(tc, index);
|
2009-10-24 19:53:57 +02:00
|
|
|
if(taddr != 0) {
|
|
|
|
typename OS::time_t t = sec;
|
|
|
|
t = htog(t);
|
2012-01-17 19:55:08 +01:00
|
|
|
SETranslatingPortProxy *p = tc->getMemProxy();
|
2009-10-24 19:53:57 +02:00
|
|
|
p->writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
|
|
|
|
}
|
|
|
|
return sec;
|
|
|
|
}
|
2006-04-13 11:42:18 +02:00
|
|
|
|
|
|
|
|
2005-01-15 00:34:56 +01:00
|
|
|
#endif // __SIM_SYSCALL_EMUL_HH__
|