gem5  v19.0.0.0
process.cc
Go to the documentation of this file.
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;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Ali Saidi
29  */
30 
32 
33 #include "arch/sparc/isa_traits.hh"
34 #include "arch/sparc/registers.hh"
36 #include "base/trace.hh"
37 #include "cpu/thread_context.hh"
38 #include "kern/solaris/solaris.hh"
39 #include "sim/process.hh"
40 #include "sim/syscall_desc.hh"
41 #include "sim/syscall_emul.hh"
42 
43 using namespace std;
44 using namespace SparcISA;
45 
46 namespace
47 {
48 
49 class SparcSolarisObjectFileLoader : public Process::Loader
50 {
51  public:
52  Process *
53  load(ProcessParams *params, ObjectFile *obj_file) override
54  {
55  auto arch = obj_file->getArch();
56  auto opsys = obj_file->getOpSys();
57 
58  if (arch != ObjectFile::SPARC64 && arch != ObjectFile::SPARC32)
59  return nullptr;
60 
61  if (opsys != ObjectFile::Solaris)
62  return nullptr;
63 
64  return new SparcSolarisProcess(params, obj_file);
65  }
66 };
67 
68 SparcSolarisObjectFileLoader loader;
69 
70 } // anonymous namespace
71 
72 
74 static SyscallReturn
75 unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
76 {
77  int index = 0;
78  auto process = tc->getProcessPtr();
79  TypedBufferArg<Solaris::utsname> name(process->getSyscallArg(tc, index));
80 
81  strcpy(name->sysname, "SunOS");
82  strcpy(name->nodename, "m5.eecs.umich.edu");
83  strcpy(name->release, process->release.c_str());
84  strcpy(name->version, "Generic_118558-21");
85  strcpy(name->machine, "sun4u");
86 
87  name.copyOut(tc->getVirtProxy());
88 
89  return 0;
90 }
91 
92 
93 SyscallDescABI<DefaultSyscallABI> SparcSolarisProcess::syscallDescs[] = {
94  /* 0 */ { "syscall" },
95  /* 1 */ { "exit", exitFunc },
96  /* 2 */ { "fork" },
97  /* 3 */ { "read", readFunc<SparcSolaris> },
98  /* 4 */ { "write", writeFunc<SparcSolaris> },
99  /* 5 */ { "open", openFunc<SparcSolaris> },
100  /* 6 */ { "close", closeFunc },
101  /* 7 */ { "wait" },
102  /* 8 */ { "creat" },
103  /* 9 */ { "link" },
104  /* 10 */ { "unlink", unlinkFunc },
105  /* 11 */ { "exec" },
106  /* 12 */ { "chdir" },
107  /* 13 */ { "time" },
108  /* 14 */ { "mknod" },
109  /* 15 */ { "chmod", chmodFunc<Solaris> },
110  /* 16 */ { "chown", chownFunc },
111  /* 17 */ { "brk", brkFunc },
112  /* 18 */ { "stat" },
113  /* 19 */ { "lseek", lseekFunc },
114  /* 20 */ { "getpid", getpidFunc },
115  /* 21 */ { "mount" },
116  /* 22 */ { "umount" },
117  /* 23 */ { "setuid", ignoreFunc },
118  /* 24 */ { "getuid", getuidFunc },
119  /* 25 */ { "stime" },
120  /* 26 */ { "pcsample" },
121  /* 27 */ { "alarm" },
122  /* 28 */ { "fstat", fstatFunc<SparcSolaris> },
123  /* 29 */ { "pause" },
124  /* 30 */ { "utime" },
125  /* 31 */ { "stty" },
126  /* 32 */ { "gtty" },
127  /* 33 */ { "access" },
128  /* 34 */ { "nice" },
129  /* 35 */ { "statfs" },
130  /* 36 */ { "sync" },
131  /* 37 */ { "kill" },
132  /* 38 */ { "fstatfs" },
133  /* 39 */ { "pgrpsys" },
134  /* 40 */ { "xenix" },
135  /* 41 */ { "dup" },
136  /* 42 */ { "pipe", pipePseudoFunc },
137  /* 43 */ { "times" },
138  /* 44 */ { "profil" },
139  /* 45 */ { "plock" },
140  /* 46 */ { "setgid" },
141  /* 47 */ { "getgid", getgidFunc },
142  /* 48 */ { "signal" },
143  /* 49 */ { "msgsys" },
144  /* 50 */ { "syssun" },
145  /* 51 */ { "acct" },
146  /* 52 */ { "shmsys" },
147  /* 53 */ { "semsys" },
148  /* 54 */ { "ioctl" },
149  /* 55 */ { "uadmin" },
150  /* 56 */ { "RESERVED" },
151  /* 57 */ { "utssys" },
152  /* 58 */ { "fdsync" },
153  /* 59 */ { "execve" },
154  /* 60 */ { "umask", umaskFunc },
155  /* 61 */ { "chroot" },
156  /* 62 */ { "fcntl" },
157  /* 63 */ { "ulimit" },
158  /* 64 */ { "reserved_64" },
159  /* 65 */ { "reserved_65" },
160  /* 66 */ { "reserved_66" },
161  /* 67 */ { "reserved_67" },
162  /* 68 */ { "reserved_68" },
163  /* 69 */ { "reserved_69" },
164  /* 70 */ { "tasksys" },
165  /* 71 */ { "acctctl" },
166  /* 72 */ { "reserved_72" },
167  /* 73 */ { "getpagesizes" },
168  /* 74 */ { "rctlsys" },
169  /* 75 */ { "issetugid" },
170  /* 76 */ { "fsat" },
171  /* 77 */ { "lwp_park" },
172  /* 78 */ { "sendfilev" },
173  /* 79 */ { "rmdir" },
174  /* 80 */ { "mkdir" },
175  /* 81 */ { "getdents" },
176  /* 82 */ { "reserved_82" },
177  /* 83 */ { "reserved_83" },
178  /* 84 */ { "sysfs" },
179  /* 85 */ { "getmsg" },
180  /* 86 */ { "putmsg" },
181  /* 87 */ { "poll" },
182  /* 88 */ { "lstat" },
183  /* 89 */ { "symlink" },
184  /* 90 */ { "readlink", readlinkFunc },
185  /* 91 */ { "setgroups" },
186  /* 92 */ { "getgroups" },
187  /* 93 */ { "fchmod" },
188  /* 94 */ { "fchown" },
189  /* 95 */ { "sigprocmask" },
190  /* 96 */ { "sigsuspend" },
191  /* 97 */ { "sigaltstack" },
192  /* 98 */ { "sigaction" },
193  /* 99 */ { "sigpending" },
194  /* 100 */ { "context" },
195  /* 101 */ { "evsys" },
196  /* 102 */ { "evtrapret" },
197  /* 103 */ { "statvfs" },
198  /* 104 */ { "fstatvfs" },
199  /* 105 */ { "getloadavg" },
200  /* 106 */ { "nfssys" },
201  /* 107 */ { "waitsys" },
202  /* 108 */ { "sigsendsys" },
203  /* 109 */ { "hrtsys" },
204  /* 110 */ { "acancel" },
205  /* 111 */ { "async" },
206  /* 112 */ { "priocntlsys" },
207  /* 113 */ { "pathconf" },
208  /* 114 */ { "mincore" },
209  /* 115 */ { "mmap", mmapFunc<SparcSolaris> },
210  /* 116 */ { "mprotect" },
211  /* 117 */ { "munmap", munmapFunc },
212  /* 118 */ { "fpathconf" },
213  /* 119 */ { "vfork" },
214  /* 120 */ { "fchdir" },
215  /* 121 */ { "readv" },
216  /* 122 */ { "writev" },
217  /* 123 */ { "xstat" },
218  /* 124 */ { "lxstat" },
219  /* 125 */ { "fxstat" },
220  /* 126 */ { "xmknod" },
221  /* 127 */ { "clocal" },
222  /* 128 */ { "setrlimit" },
223  /* 129 */ { "getrlimit" },
224  /* 130 */ { "lchown" },
225  /* 131 */ { "memcntl" },
226  /* 132 */ { "getpmsg" },
227  /* 133 */ { "putpmsg" },
228  /* 134 */ { "rename" },
229  /* 135 */ { "uname", unameFunc },
230  /* 136 */ { "setegid" },
231  /* 137 */ { "sysconfig" },
232  /* 138 */ { "adjtime" },
233  /* 139 */ { "systeminfo" },
234  /* 140 */ { "reserved_140" },
235  /* 141 */ { "seteuid" },
236  /* 142 */ { "vtrace" },
237  /* 143 */ { "fork1" },
238  /* 144 */ { "sigtimedwait" },
239  /* 145 */ { "lwp_info" },
240  /* 146 */ { "yield" },
241  /* 147 */ { "lwp_sema_wait" },
242  /* 148 */ { "lwp_sema_post" },
243  /* 149 */ { "lwp_sema_trywait" },
244  /* 150 */ { "lwp_detach" },
245  /* 151 */ { "corectl" },
246  /* 152 */ { "modctl" },
247  /* 153 */ { "fchroot" },
248  /* 154 */ { "utimes" },
249  /* 155 */ { "vhangup" },
250  /* 156 */ { "gettimeofday" },
251  /* 157 */ { "getitimer" },
252  /* 158 */ { "setitimer" },
253  /* 159 */ { "lwp_create" },
254  /* 160 */ { "lwp_exit" },
255  /* 161 */ { "lwp_suspend" },
256  /* 162 */ { "lwp_continue" },
257  /* 163 */ { "lwp_kill" },
258  /* 164 */ { "lwp_self" },
259  /* 165 */ { "lwp_setprivate" },
260  /* 166 */ { "lwp_getprivate" },
261  /* 167 */ { "lwp_wait" },
262  /* 168 */ { "lwp_mutex_wakeup" },
263  /* 169 */ { "lwp_mutex_lock" },
264  /* 170 */ { "lwp_cond_wait" },
265  /* 171 */ { "lwp_cond_signal" },
266  /* 172 */ { "lwp_cond_broadcast" },
267  /* 173 */ { "pread" },
268  /* 174 */ { "pwrite" },
269  /* 175 */ { "llseek" },
270  /* 176 */ { "inst_sync" },
271  /* 177 */ { "srmlimitsys" },
272  /* 178 */ { "kaio" },
273  /* 179 */ { "cpc" },
274  /* 180 */ { "lgrpsys_meminfosys" },
275  /* 181 */ { "rusagesys" },
276  /* 182 */ { "reserved_182" },
277  /* 183 */ { "reserved_183" },
278  /* 184 */ { "tsolsys" },
279  /* 185 */ { "acl" },
280  /* 186 */ { "auditsys" },
281  /* 187 */ { "processor_bind" },
282  /* 188 */ { "processor_info" },
283  /* 189 */ { "p_online" },
284  /* 190 */ { "sigqueue" },
285  /* 191 */ { "clock_gettime" },
286  /* 192 */ { "clock_settime" },
287  /* 193 */ { "clock_getres" },
288  /* 194 */ { "timer_create" },
289  /* 195 */ { "timer_delete" },
290  /* 196 */ { "timer_settime" },
291  /* 197 */ { "timer_gettime" },
292  /* 198 */ { "timer_getoverrun" },
293  /* 199 */ { "nanosleep" },
294  /* 200 */ { "facl" },
295  /* 201 */ { "door" },
296  /* 202 */ { "setreuid" },
297  /* 203 */ { "setregid" },
298  /* 204 */ { "install_utrap" },
299  /* 205 */ { "signotify" },
300  /* 206 */ { "schedctl" },
301  /* 207 */ { "pset" },
302  /* 208 */ { "sparc_utrap_install" },
303  /* 209 */ { "resolvepath" },
304  /* 210 */ { "signotifywait" },
305  /* 211 */ { "lwp_sigredirect" },
306  /* 212 */ { "lwp_alarm" },
307  /* 213 */ { "getdents64" },
308  /* 214 */ { "mmap64" },
309  /* 215 */ { "stat64" },
310  /* 216 */ { "lstat64" },
311  /* 217 */ { "fstat64" },
312  /* 218 */ { "statvfs64" },
313  /* 219 */ { "fstatvfs64" },
314  /* 220 */ { "setrlimit64" },
315  /* 221 */ { "getrlimit64" },
316  /* 222 */ { "pread64" },
317  /* 223 */ { "pwrite64" },
318  /* 224 */ { "creat64" },
319  /* 225 */ { "open64" },
320  /* 226 */ { "rpcsys" },
321  /* 227 */ { "reserved_227" },
322  /* 228 */ { "reserved_228" },
323  /* 229 */ { "reserved_229" },
324  /* 230 */ { "so_socket" },
325  /* 231 */ { "so_socketpair" },
326  /* 232 */ { "bind" },
327  /* 233 */ { "listen" },
328  /* 234 */ { "accept" },
329  /* 235 */ { "connect" },
330  /* 236 */ { "shutdown" },
331  /* 237 */ { "recv" },
332  /* 238 */ { "recvfrom" },
333  /* 239 */ { "recvmsg" },
334  /* 240 */ { "send" },
335  /* 241 */ { "sendmsg" },
336  /* 242 */ { "sendto" },
337  /* 243 */ { "getpeername" },
338  /* 244 */ { "getsockname" },
339  /* 245 */ { "getsockopt" },
340  /* 246 */ { "setsockopt" },
341  /* 247 */ { "sockconfig" },
342  /* 248 */ { "ntp_gettime" },
343  /* 249 */ { "ntp_adjtime" },
344  /* 250 */ { "lwp_mutex_unlock" },
345  /* 251 */ { "lwp_mutex_trylock" },
346  /* 252 */ { "lwp_mutex_init" },
347  /* 253 */ { "cladm" },
348  /* 254 */ { "lwp_sigtimedwait" },
349  /* 255 */ { "umount2" }
350 };
351 
352 SparcSolarisProcess::SparcSolarisProcess(ProcessParams * params,
353  ObjectFile *objFile)
354  : Sparc64Process(params, objFile),
355  Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc))
356 {
357  // The sparc syscall table must be <= 284 entries because that is all there
358  // is space for.
359  assert(Num_Syscall_Descs <= 284);
360 }
361 
362 
363 
366 {
367  if (callnum < 0 || callnum >= Num_Syscall_Descs)
368  return NULL;
369  return &syscallDescs[callnum];
370 }
371 
372 void
374 {
375  doSyscall(tc->readIntReg(1), tc, fault);
376 }
Bitfield< 30, 0 > index
Arch getArch() const
Definition: object_file.hh:124
const std::string & name()
Definition: trace.cc:54
static SyscallReturn unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target uname() handler.
Definition: process.cc:75
SyscallReturn ignoreFunc(SyscallDesc *desc, int callnum, 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:77
virtual RegVal readIntReg(RegIndex reg_idx) const =0
virtual PortProxy & getVirtProxy()=0
virtual Process * getProcessPtr()=0
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault)
Definition: process.cc:430
A process with emulated SPARC/Solaris syscalls.
Definition: process.hh:42
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...
SyscallReturn closeFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd)
Target close() handler.
SyscallReturn umaskFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Target umask() handler.
SyscallReturn munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Target munmap() handler.
SyscallReturn getuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
SyscallReturn unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname)
Target unlink() handler.
SyscallReturn readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, Addr buf_ptr, size_t bufsiz)
Target readlink() handler.
static SyscallDescABI< DefaultSyscallABI > syscallDescs[]
Array of syscall descriptors, indexed by call number.
Definition: process.hh:56
SyscallReturn brkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr new_brk)
Target brk() handler: set brk address.
SyscallReturn getgidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getgid() handler.
void syscall(ThreadContext *tc, Fault *fault) override
Definition: process.cc:373
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:69
SyscallReturn lseekFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
Target lseek() handler.
This file defines objects used to emulate syscalls from the target application on the host machine...
Definition: asi.cc:34
OpSys getOpSys() const
Definition: object_file.hh:125
SyscallReturn chownFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, uint32_t owner, uint32_t group)
Target chown() handler.
SyscallReturn pipePseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Pseudo Funcs - These functions use a different return convension, returning a second value in a regis...
This class represents the return value from an emulated system call, including any errno setting...
Each instance of a Loader subclass will have a chance to try to load an object file when tryLoaders i...
Definition: process.hh:191
SyscallDesc * getDesc(int callnum) override
Definition: process.cc:365
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
SyscallReturn getpidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getpid() handler.
SyscallReturn exitFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int status)
Target exit() handler: terminate current context.

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13