gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
process.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 The Regents of The University of Michigan
3  * Copyright (c) 2007 MIPS Technologies, Inc.
4  * Copyright (c) 2016 The University of Virginia
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Authors: Gabe Black
31  * Korey Sewell
32  * Alec Roelke
33  */
34 
36 
37 #include <map>
38 
39 #include "arch/riscv/isa_traits.hh"
41 #include "base/trace.hh"
42 #include "cpu/thread_context.hh"
43 #include "debug/SyscallVerbose.hh"
44 #include "kern/linux/linux.hh"
45 #include "sim/eventq.hh"
46 #include "sim/process.hh"
47 #include "sim/syscall_desc.hh"
48 #include "sim/syscall_emul.hh"
49 #include "sim/system.hh"
50 
51 using namespace std;
52 using namespace RiscvISA;
53 
55 static SyscallReturn
56 unameFunc(SyscallDesc *desc, int callnum, Process *process,
57  ThreadContext *tc)
58 {
59  int index = 0;
61 
62  strcpy(name->sysname, "Linux");
63  strcpy(name->nodename,"sim.gem5.org");
64  strcpy(name->release, "3.0.0");
65  strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
66  strcpy(name->machine, "riscv");
67 
68  name.copyOut(tc->getMemProxy());
69  return 0;
70 }
71 
72 std::map<int, SyscallDesc> RiscvLinuxProcess::syscallDescs = {
73  {17, SyscallDesc("getcwd", getcwdFunc)},
74  {23, SyscallDesc("dup", dupFunc)},
75  {25, SyscallDesc("fcntl", fcntl64Func)},
76  {29, SyscallDesc("ioctl", ioctlFunc<RiscvLinux>)},
77  {34, SyscallDesc("mkdirat", unimplementedFunc)},
78  {35, SyscallDesc("unlinkat", unlinkatFunc<RiscvLinux>)},
79  {37, SyscallDesc("linkat", unimplementedFunc)},
80  {38, SyscallDesc("renameat", renameatFunc<RiscvLinux>)},
81  {46, SyscallDesc("ftruncate", ftruncate64Func)},
82  {48, SyscallDesc("faccessat", faccessatFunc<RiscvLinux>)},
83  {49, SyscallDesc("chdir", unimplementedFunc)},
84  {56, SyscallDesc("openat", openatFunc<RiscvLinux>)},
85  {57, SyscallDesc("close", closeFunc)},
86  {61, SyscallDesc("getdents", unimplementedFunc)},
87  {62, SyscallDesc("lseek", lseekFunc)},
88  {63, SyscallDesc("read", readFunc)},
89  {64, SyscallDesc("write", writeFunc)},
90  {66, SyscallDesc("writev", writevFunc<RiscvLinux>)},
91  {67, SyscallDesc("pread", unimplementedFunc)},
92  {68, SyscallDesc("pwrite", pwrite64Func<RiscvLinux>)},
93  {78, SyscallDesc("readlinkat", readlinkatFunc<RiscvLinux>)},
94  {79, SyscallDesc("fstatat", fstatat64Func<RiscvLinux>)},
95  {80, SyscallDesc("fstat", fstat64Func<RiscvLinux>)},
96  {93, SyscallDesc("exit", exitFunc)},
97  {94, SyscallDesc("exit_group", exitGroupFunc)},
98  {113, SyscallDesc("clock_gettime", clock_gettimeFunc<RiscvLinux>)},
99  {129, SyscallDesc("kill", unimplementedFunc)},
100  {134, SyscallDesc("rt_sigaction", ignoreFunc, SyscallDesc::WarnOnce)},
101  {135, SyscallDesc("rt_sigprocmask", ignoreFunc, SyscallDesc::WarnOnce)},
102  {153, SyscallDesc("times", timesFunc<RiscvLinux>)},
103  {160, SyscallDesc("uname", unameFunc)},
104  {163, SyscallDesc("getrlimit", getrlimitFunc<RiscvLinux>)},
105  {164, SyscallDesc("setrlimit", ignoreFunc)},
106  {165, SyscallDesc("getrusage", getrusageFunc<RiscvLinux>)},
107  {169, SyscallDesc("gettimeofday", gettimeofdayFunc<RiscvLinux>)},
108  {172, SyscallDesc("getpid", getpidFunc)},
109  {174, SyscallDesc("getuid", getuidFunc)},
110  {175, SyscallDesc("geteuid", geteuidFunc)},
111  {176, SyscallDesc("getgid", getgidFunc)},
112  {177, SyscallDesc("getegid", getegidFunc)},
113  {214, SyscallDesc("brk", brkFunc)},
114  {215, SyscallDesc("munmap", munmapFunc)},
115  {216, SyscallDesc("mremap", mremapFunc<RiscvLinux>)},
116  {222, SyscallDesc("mmap", mmapFunc<RiscvLinux>)},
117  {226, SyscallDesc("mprotect", ignoreFunc)},
118  {1024, SyscallDesc("open", openFunc<RiscvLinux>)},
119  {1025, SyscallDesc("link", unimplementedFunc)},
120  {1026, SyscallDesc("unlink", unlinkFunc)},
121  {1030, SyscallDesc("mkdir", mkdirFunc)},
122  {1033, SyscallDesc("access", accessFunc)},
123  {1038, SyscallDesc("stat", stat64Func<RiscvLinux>)},
124  {1039, SyscallDesc("lstat", lstat64Func<RiscvLinux>)},
125  {1062, SyscallDesc("time", timeFunc<RiscvLinux>)},
126  {2011, SyscallDesc("getmainvars", unimplementedFunc)},
127 };
128 
130  ObjectFile *objFile) : RiscvProcess(params, objFile)
131 {}
132 
135 {
136  return syscallDescs.find(callnum) != syscallDescs.end() ?
137  &syscallDescs.at(callnum) : nullptr;
138 }
Bitfield< 30, 0 > index
SyscallReturn brkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target brk() handler: set brk address.
const std::string & name()
Definition: trace.cc:49
RiscvLinuxProcess(ProcessParams *params, ObjectFile *objFile)
Constructor.
Definition: process.cc:129
SyscallReturn dupFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
FIXME: The file description is not shared among file descriptors created with dup.
SyscallReturn getcwdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getcwd() handler.
SyscallReturn ignoreFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Handler for unimplemented syscalls that we never intend to implement (signal handling, etc.) and should not affect the correct behavior of the program.
Definition: syscall_emul.cc:67
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i)=0
SyscallReturn getpidFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getpid() handler.
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
ThreadContext is the external interface to all thread state for anything outside of the CPU...
static std::map< int, SyscallDesc > syscallDescs
Array of syscall descriptors, indexed by call number.
Definition: process.hh:59
SyscallReturn getegidFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getegid() handler.
SyscallReturn munmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target munmap() handler.
SyscallReturn writeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target write() handler.
SyscallReturn unimplementedFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Handler for unimplemented syscalls that we haven't thought about.
Definition: syscall_emul.cc:57
SyscallReturn exitGroupFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target exit_group() handler: terminate simulation. (exit all threads)
SyscallReturn lseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target lseek() handler.
SyscallReturn unlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
SyscallReturn geteuidFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target geteuid() handler.
virtual SETranslatingPortProxy & getMemProxy()=0
Warn only once for unimplemented system calls.
Definition: syscall_desc.hh:83
SyscallReturn mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target mkdir() handler.
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:63
virtual SyscallDesc * getDesc(int callnum)
Definition: process.cc:134
SyscallReturn getgidFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getgid() handler.
SyscallReturn fcntl64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target fcntl64() handler.
This file defines objects used to emulate syscalls from the target application on the host machine...
SyscallReturn getuidFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getuid() handler.
SyscallReturn accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, int index)
SyscallReturn exitFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target exit() handler: terminate current context.
SyscallReturn ftruncate64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target ftruncate64() handler.
static SyscallReturn unameFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target uname() handler.
Definition: process.cc:56
SyscallReturn closeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target close() handler.
This class represents the return value from an emulated system call, including any errno setting...
SyscallReturn readFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)

Generated on Fri Jun 9 2017 13:03:35 for gem5 by doxygen 1.8.6