summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/faults.cc10
-rw-r--r--sim/faults.hh12
-rw-r--r--sim/process.cc15
-rw-r--r--sim/process.hh6
-rw-r--r--sim/syscall_emul.cc46
-rw-r--r--sim/syscall_emul.hh4
6 files changed, 79 insertions, 14 deletions
diff --git a/sim/faults.cc b/sim/faults.cc
index 640f439c4..58a631263 100644
--- a/sim/faults.cc
+++ b/sim/faults.cc
@@ -28,9 +28,9 @@
#include "sim/faults.hh"
-NoFaultType * NoFault = new NoFaultType("none");
-MachineCheckFaultType * MachineCheckFault = new MachineCheckFaultType("mchk");
-AlignmentFaultType * AlignmentFault = new AlignmentFaultType("unalign");
-//This needs to not exist
-FakeMemFaultType * FakeMemFault = new FakeMemFaultType("fakemem");
+NoFaultType * const NoFault = new NoFaultType("none");
+MachineCheckFaultType * const MachineCheckFault =
+ new MachineCheckFaultType("mchk");
+AlignmentFaultType * const AlignmentFault =
+ new AlignmentFaultType("unalign");
diff --git a/sim/faults.hh b/sim/faults.hh
index bc2c35c64..d9c742b90 100644
--- a/sim/faults.hh
+++ b/sim/faults.hh
@@ -41,25 +41,19 @@ extern class NoFaultType : public Fault
{
public:
NoFaultType(char * newName) : Fault(newName) {;}
-} * NoFault;
+} * const NoFault;
extern class MachineCheckFaultType : public Fault
{
public:
MachineCheckFaultType(char * newName) : Fault(newName) {;}
-} * MachineCheckFault;
+} * const MachineCheckFault;
extern class AlignmentFaultType : public Fault
{
public:
AlignmentFaultType(char * newName) : Fault(newName) {;}
-} * AlignmentFault;
-
-extern class FakeMemFaultType : public Fault
-{
-public:
- FakeMemFaultType(char * newName) : Fault(newName) {;}
-} * FakeMemFault;
+} * const AlignmentFault;
#endif // __FAULTS_HH__
diff --git a/sim/process.cc b/sim/process.cc
index b2f3046fb..0a7e46082 100644
--- a/sim/process.cc
+++ b/sim/process.cc
@@ -46,6 +46,7 @@
#include "sim/fake_syscall.hh"
#include "sim/process.hh"
#include "sim/stats.hh"
+#include "sim/syscall_emul.hh"
#ifdef TARGET_ALPHA
#include "arch/alpha/alpha_tru64_process.hh"
@@ -351,6 +352,19 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile,
init_regs->npc = prog_entry + sizeof(MachInst);
}
+void
+LiveProcess::syscall(ExecContext *xc)
+{
+ num_syscalls++;
+
+ int64_t callnum = xc->regs.intRegFile[ReturnValueReg];
+
+ SyscallDesc *desc = getDesc(callnum);
+ if (desc == NULL)
+ fatal("Syscall %d out of range", callnum);
+
+ desc->doSyscall(callnum, this, xc);
+}
LiveProcess *
LiveProcess::create(const string &nm,
@@ -395,6 +409,7 @@ LiveProcess::create(const string &nm,
}
+
BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
VectorParam<string> cmd;
diff --git a/sim/process.hh b/sim/process.hh
index f5b713e3c..6e91bb0ab 100644
--- a/sim/process.hh
+++ b/sim/process.hh
@@ -48,6 +48,7 @@
class ExecContext;
class FunctionalMemory;
+class SyscallDesc;
class Process : public SimObject
{
protected:
@@ -204,6 +205,11 @@ class LiveProcess : public Process
std::string executable,
std::vector<std::string> &argv,
std::vector<std::string> &envp);
+
+ virtual void syscall(ExecContext *xc);
+
+ virtual SyscallDesc* getDesc(int callnum) { panic("Must be implemented."); }
+
};
diff --git a/sim/syscall_emul.cc b/sim/syscall_emul.cc
index 68001b0d1..d22dde3b8 100644
--- a/sim/syscall_emul.cc
+++ b/sim/syscall_emul.cc
@@ -26,6 +26,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <fcntl.h>
#include <unistd.h>
#include <string>
@@ -279,3 +280,48 @@ fchownFunc(SyscallDesc *desc, int num, Process *process, ExecContext *xc)
int result = fchown(fd, hostOwner, hostGroup);
return (result == -1) ? -errno : result;
}
+
+
+SyscallReturn
+fcntlFunc(SyscallDesc *desc, int num, Process *process,
+ ExecContext *xc)
+{
+ int fd = xc->getSyscallArg(0);
+
+ if (fd < 0 || process->sim_fd(fd) < 0)
+ return -EBADF;
+
+ int cmd = xc->getSyscallArg(1);
+ switch (cmd) {
+ case 0: // F_DUPFD
+ // if we really wanted to support this, we'd need to do it
+ // in the target fd space.
+ warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
+ return -EMFILE;
+
+ case 1: // F_GETFD (get close-on-exec flag)
+ case 2: // F_SETFD (set close-on-exec flag)
+ return 0;
+
+ case 3: // F_GETFL (get file flags)
+ case 4: // F_SETFL (set file flags)
+ // not sure if this is totally valid, but we'll pass it through
+ // to the underlying OS
+ warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
+ return fcntl(process->sim_fd(fd), cmd);
+ // return 0;
+
+ case 7: // F_GETLK (get lock)
+ case 8: // F_SETLK (set lock)
+ case 9: // F_SETLKW (set lock and wait)
+ // don't mess with file locking... just act like it's OK
+ warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
+ return 0;
+
+ default:
+ warn("Unknown fcntl command %d\n", cmd);
+ return 0;
+ }
+}
+
+
diff --git a/sim/syscall_emul.hh b/sim/syscall_emul.hh
index bc22c5c4c..4e4f9a5d7 100644
--- a/sim/syscall_emul.hh
+++ b/sim/syscall_emul.hh
@@ -242,6 +242,10 @@ SyscallReturn chownFunc(SyscallDesc *desc, int num,
SyscallReturn fchownFunc(SyscallDesc *desc, int num,
Process *p, ExecContext *xc);
+/// Target fnctl() handler.
+SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
+ Process *process, ExecContext *xc);
+
/// This struct is used to build an target-OS-dependent table that
/// maps the target's open() flags to the host open() flags.
struct OpenFlagTransTable {