arch,sim: Convert clone to GuestABI and define a cloneBackwardsFunc.
[gem5.git] / src / arch / riscv / linux / process.cc
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
31 #include "arch/riscv/linux/process.hh"
32
33 #include <map>
34
35 #include "arch/riscv/isa_traits.hh"
36 #include "arch/riscv/linux/linux.hh"
37 #include "base/loader/object_file.hh"
38 #include "base/trace.hh"
39 #include "cpu/thread_context.hh"
40 #include "debug/SyscallVerbose.hh"
41 #include "kern/linux/linux.hh"
42 #include "sim/eventq.hh"
43 #include "sim/process.hh"
44 #include "sim/syscall_desc.hh"
45 #include "sim/syscall_emul.hh"
46 #include "sim/system.hh"
47
48 using namespace std;
49 using namespace RiscvISA;
50
51 namespace
52 {
53
54 class RiscvLinuxObjectFileLoader : public Process::Loader
55 {
56 public:
57 Process *
58 load(ProcessParams *params, ObjectFile *obj_file) override
59 {
60 auto arch = obj_file->getArch();
61 auto opsys = obj_file->getOpSys();
62
63 if (arch != ObjectFile::Riscv64 && arch != ObjectFile::Riscv32)
64 return nullptr;
65
66 if (opsys == ObjectFile::UnknownOpSys) {
67 warn("Unknown operating system; assuming Linux.");
68 opsys = ObjectFile::Linux;
69 }
70
71 if (opsys != ObjectFile::Linux)
72 return nullptr;
73
74 if (arch == ObjectFile::Riscv64)
75 return new RiscvLinuxProcess64(params, obj_file);
76 else
77 return new RiscvLinuxProcess32(params, obj_file);
78 }
79 };
80
81 RiscvLinuxObjectFileLoader loader;
82
83 } // anonymous namespace
84
85 /// Target uname() handler.
86 static SyscallReturn
87 unameFunc64(SyscallDesc *desc, int callnum, ThreadContext *tc)
88 {
89 int index = 0;
90 auto process = tc->getProcessPtr();
91 TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
92
93 strcpy(name->sysname, "Linux");
94 strcpy(name->nodename,"sim.gem5.org");
95 strcpy(name->release, process->release.c_str());
96 strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
97 strcpy(name->machine, "riscv64");
98
99 name.copyOut(tc->getVirtProxy());
100 return 0;
101 }
102
103 /// Target uname() handler.
104 static SyscallReturn
105 unameFunc32(SyscallDesc *desc, int callnum, ThreadContext *tc)
106 {
107 int index = 0;
108 auto process = tc->getProcessPtr();
109 TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
110
111 strcpy(name->sysname, "Linux");
112 strcpy(name->nodename,"sim.gem5.org");
113 strcpy(name->release, process->release.c_str());
114 strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
115 strcpy(name->machine, "riscv32");
116
117 name.copyOut(tc->getVirtProxy());
118 return 0;
119 }
120
121 std::map<int, SyscallDescABI<DefaultSyscallABI>>
122 RiscvLinuxProcess64::syscallDescs = {
123 {0, { "io_setup" }},
124 {1, { "io_destroy" }},
125 {2, { "io_submit" }},
126 {3, { "io_cancel" }},
127 {4, { "io_getevents" }},
128 {5, { "setxattr" }},
129 {6, { "lsetxattr" }},
130 {7, { "fsetxattr" }},
131 {8, { "getxattr" }},
132 {9, { "lgetxattr" }},
133 {10, { "fgetxattr" }},
134 {11, { "listxattr" }},
135 {12, { "llistxattr" }},
136 {13, { "flistxattr" }},
137 {14, { "removexattr" }},
138 {15, { "lremovexattr" }},
139 {16, { "fremovexattr" }},
140 {17, { "getcwd", getcwdFunc }},
141 {18, { "lookup_dcookie" }},
142 {19, { "eventfd2" }},
143 {20, { "epoll_create1" }},
144 {21, { "epoll_ctl" }},
145 {22, { "epoll_pwait" }},
146 {23, { "dup", dupFunc }},
147 {24, { "dup3" }},
148 {25, { "fcntl", fcntl64Func }},
149 {26, { "inotify_init1" }},
150 {27, { "inotify_add_watch" }},
151 {28, { "inotify_rm_watch" }},
152 {29, { "ioctl", ioctlFunc<RiscvLinux64> }},
153 {30, { "ioprio_get" }},
154 {31, { "ioprio_set" }},
155 {32, { "flock" }},
156 {33, { "mknodat" }},
157 {34, { "mkdirat" }},
158 {35, { "unlinkat", unlinkatFunc<RiscvLinux64> }},
159 {36, { "symlinkat" }},
160 {37, { "linkat" }},
161 {38, { "renameat", renameatFunc<RiscvLinux64> }},
162 {39, { "umount2" }},
163 {40, { "mount" }},
164 {41, { "pivot_root" }},
165 {42, { "nfsservctl" }},
166 {43, { "statfs", statfsFunc<RiscvLinux64> }},
167 {44, { "fstatfs", fstatfsFunc<RiscvLinux64> }},
168 {45, { "truncate", truncateFunc }},
169 {46, { "ftruncate", ftruncate64Func }},
170 {47, { "fallocate", fallocateFunc }},
171 {48, { "faccessat", faccessatFunc<RiscvLinux64> }},
172 {49, { "chdir" }},
173 {50, { "fchdir" }},
174 {51, { "chroot" }},
175 {52, { "fchmod", fchmodFunc<RiscvLinux64> }},
176 {53, { "fchmodat" }},
177 {54, { "fchownat" }},
178 {55, { "fchown", fchownFunc }},
179 {56, { "openat", openatFunc<RiscvLinux64> }},
180 {57, { "close", closeFunc }},
181 {58, { "vhangup" }},
182 {59, { "pipe2" }},
183 {60, { "quotactl" }},
184 {61, { "getdents64" }},
185 {62, { "lseek", lseekFunc }},
186 {63, { "read", readFunc<RiscvLinux64> }},
187 {64, { "write", writeFunc<RiscvLinux64> }},
188 {66, { "writev", writevFunc<RiscvLinux64> }},
189 {67, { "pread64" }},
190 {68, { "pwrite64", pwrite64Func<RiscvLinux64> }},
191 {69, { "preadv" }},
192 {70, { "pwritev" }},
193 {71, { "sendfile" }},
194 {72, { "pselect6" }},
195 {73, { "ppoll" }},
196 {74, { "signalfd64" }},
197 {75, { "vmsplice" }},
198 {76, { "splice" }},
199 {77, { "tee" }},
200 {78, { "readlinkat", readlinkatFunc<RiscvLinux64> }},
201 {79, { "fstatat", fstatat64Func<RiscvLinux64> }},
202 {80, { "fstat", fstat64Func<RiscvLinux64> }},
203 {81, { "sync" }},
204 {82, { "fsync" }},
205 {83, { "fdatasync" }},
206 {84, { "sync_file_range2" }},
207 {85, { "timerfd_create" }},
208 {86, { "timerfd_settime" }},
209 {87, { "timerfd_gettime" }},
210 {88, { "utimensat" }},
211 {89, { "acct" }},
212 {90, { "capget" }},
213 {91, { "capset" }},
214 {92, { "personality" }},
215 {93, { "exit", exitFunc }},
216 {94, { "exit_group", exitGroupFunc }},
217 {95, { "waitid" }},
218 {96, { "set_tid_address", setTidAddressFunc }},
219 {97, { "unshare" }},
220 {98, { "futex", futexFunc<RiscvLinux64> }},
221 {99, { "set_robust_list", ignoreWarnOnceFunc }},
222 {100, { "get_robust_list", ignoreWarnOnceFunc }},
223 {101, { "nanosleep", ignoreWarnOnceFunc }},
224 {102, { "getitimer" }},
225 {103, { "setitimer" }},
226 {104, { "kexec_load" }},
227 {105, { "init_module" }},
228 {106, { "delete_module" }},
229 {107, { "timer_create" }},
230 {108, { "timer_gettime" }},
231 {109, { "timer_getoverrun" }},
232 {110, { "timer_settime" }},
233 {111, { "timer_delete" }},
234 {112, { "clock_settime" }},
235 {113, { "clock_gettime", clock_gettimeFunc<RiscvLinux64> }},
236 {114, { "clock_getres", clock_getresFunc<RiscvLinux64> }},
237 {115, { "clock_nanosleep" }},
238 {116, { "syslog" }},
239 {117, { "ptrace" }},
240 {118, { "sched_setparam" }},
241 {119, { "sched_setscheduler" }},
242 {120, { "sched_getscheduler" }},
243 {121, { "sched_getparam" }},
244 {122, { "sched_setaffinity" }},
245 {123, { "sched_getaffinity" }},
246 {124, { "sched_yield", ignoreWarnOnceFunc }},
247 {125, { "sched_get_priority_max" }},
248 {126, { "sched_get_priority_min" }},
249 {127, { "scheD_rr_get_interval" }},
250 {128, { "restart_syscall" }},
251 {129, { "kill" }},
252 {130, { "tkill" }},
253 {131, { "tgkill", tgkillFunc<RiscvLinux64> }},
254 {132, { "sigaltstack" }},
255 {133, { "rt_sigsuspend", ignoreWarnOnceFunc }},
256 {134, { "rt_sigaction", ignoreWarnOnceFunc }},
257 {135, { "rt_sigprocmask", ignoreWarnOnceFunc }},
258 {136, { "rt_sigpending", ignoreWarnOnceFunc }},
259 {137, { "rt_sigtimedwait", ignoreWarnOnceFunc }},
260 {138, { "rt_sigqueueinfo", ignoreWarnOnceFunc }},
261 {139, { "rt_sigreturn", ignoreWarnOnceFunc }},
262 {140, { "setpriority" }},
263 {141, { "getpriority" }},
264 {142, { "reboot" }},
265 {143, { "setregid" }},
266 {144, { "setgid" }},
267 {145, { "setreuid" }},
268 {146, { "setuid", ignoreFunc }},
269 {147, { "setresuid" }},
270 {148, { "getresuid" }},
271 {149, { "getresgid" }},
272 {150, { "getresgid" }},
273 {151, { "setfsuid" }},
274 {152, { "setfsgid" }},
275 {153, { "times", timesFunc<RiscvLinux64> }},
276 {154, { "setpgid", setpgidFunc }},
277 {155, { "getpgid" }},
278 {156, { "getsid" }},
279 {157, { "setsid" }},
280 {158, { "getgroups" }},
281 {159, { "setgroups" }},
282 {160, { "uname", unameFunc64 }},
283 {161, { "sethostname" }},
284 {162, { "setdomainname" }},
285 {163, { "getrlimit", getrlimitFunc<RiscvLinux64> }},
286 {164, { "setrlimit", ignoreFunc }},
287 {165, { "getrusage", getrusageFunc<RiscvLinux64> }},
288 {166, { "umask", umaskFunc }},
289 {167, { "prctl" }},
290 {168, { "getcpu" }},
291 {169, { "gettimeofday", gettimeofdayFunc<RiscvLinux64> }},
292 {170, { "settimeofday" }},
293 {171, { "adjtimex" }},
294 {172, { "getpid", getpidFunc }},
295 {173, { "getppid", getppidFunc }},
296 {174, { "getuid", getuidFunc }},
297 {175, { "geteuid", geteuidFunc }},
298 {176, { "getgid", getgidFunc }},
299 {177, { "getegid", getegidFunc }},
300 {178, { "gettid", gettidFunc }},
301 {179, { "sysinfo", sysinfoFunc<RiscvLinux64> }},
302 {180, { "mq_open" }},
303 {181, { "mq_unlink" }},
304 {182, { "mq_timedsend" }},
305 {183, { "mq_timedrecieve" }},
306 {184, { "mq_notify" }},
307 {185, { "mq_getsetattr" }},
308 {186, { "msgget" }},
309 {187, { "msgctl" }},
310 {188, { "msgrcv" }},
311 {189, { "msgsnd" }},
312 {190, { "semget" }},
313 {191, { "semctl" }},
314 {192, { "semtimedop" }},
315 {193, { "semop" }},
316 {194, { "shmget" }},
317 {195, { "shmctl" }},
318 {196, { "shmat" }},
319 {197, { "shmdt" }},
320 {198, { "socket" }},
321 {199, { "socketpair" }},
322 {200, { "bind" }},
323 {201, { "listen" }},
324 {202, { "accept" }},
325 {203, { "connect" }},
326 {204, { "getsockname" }},
327 {205, { "getpeername" }},
328 {206, { "sendo" }},
329 {207, { "recvfrom" }},
330 {208, { "setsockopt" }},
331 {209, { "getsockopt" }},
332 {210, { "shutdown" }},
333 {211, { "sendmsg" }},
334 {212, { "recvmsg" }},
335 {213, { "readahead" }},
336 {214, { "brk", brkFunc }},
337 {215, { "munmap", munmapFunc }},
338 {216, { "mremap", mremapFunc<RiscvLinux64> }},
339 {217, { "add_key" }},
340 {218, { "request_key" }},
341 {219, { "keyctl" }},
342 {220, { "clone", cloneBackwardsFunc<RiscvLinux64> }},
343 {221, { "execve", execveFunc<RiscvLinux64> }},
344 {222, { "mmap", mmapFunc<RiscvLinux64> }},
345 {223, { "fadvise64" }},
346 {224, { "swapon" }},
347 {225, { "swapoff" }},
348 {226, { "mprotect", ignoreFunc }},
349 {227, { "msync", ignoreFunc }},
350 {228, { "mlock", ignoreFunc }},
351 {229, { "munlock", ignoreFunc }},
352 {230, { "mlockall", ignoreFunc }},
353 {231, { "munlockall", ignoreFunc }},
354 {232, { "mincore", ignoreFunc }},
355 {233, { "madvise", ignoreFunc }},
356 {234, { "remap_file_pages" }},
357 {235, { "mbind", ignoreFunc }},
358 {236, { "get_mempolicy" }},
359 {237, { "set_mempolicy" }},
360 {238, { "migrate_pages" }},
361 {239, { "move_pages" }},
362 {240, { "tgsigqueueinfo" }},
363 {241, { "perf_event_open" }},
364 {242, { "accept4" }},
365 {243, { "recvmmsg" }},
366 {260, { "wait4" }},
367 {261, { "prlimit64", prlimitFunc<RiscvLinux64> }},
368 {262, { "fanotify_init" }},
369 {263, { "fanotify_mark" }},
370 {264, { "name_to_handle_at" }},
371 {265, { "open_by_handle_at" }},
372 {266, { "clock_adjtime" }},
373 {267, { "syncfs" }},
374 {268, { "setns" }},
375 {269, { "sendmmsg" }},
376 {270, { "process_vm_ready" }},
377 {271, { "process_vm_writev" }},
378 {272, { "kcmp" }},
379 {273, { "finit_module" }},
380 {274, { "sched_setattr" }},
381 {275, { "sched_getattr" }},
382 {276, { "renameat2" }},
383 {277, { "seccomp" }},
384 {278, { "getrandom" }},
385 {279, { "memfd_create" }},
386 {280, { "bpf" }},
387 {281, { "execveat" }},
388 {282, { "userfaultid" }},
389 {283, { "membarrier" }},
390 {284, { "mlock2" }},
391 {285, { "copy_file_range" }},
392 {286, { "preadv2" }},
393 {287, { "pwritev2" }},
394 {1024, { "open", openFunc<RiscvLinux64> }},
395 {1025, { "link" }},
396 {1026, { "unlink", unlinkFunc }},
397 {1027, { "mknod" }},
398 {1028, { "chmod", chmodFunc<RiscvLinux64> }},
399 {1029, { "chown", chownFunc }},
400 {1030, { "mkdir", mkdirFunc }},
401 {1031, { "rmdir" }},
402 {1032, { "lchown" }},
403 {1033, { "access", accessFunc }},
404 {1034, { "rename", renameFunc }},
405 {1035, { "readlink", readlinkFunc }},
406 {1036, { "symlink" }},
407 {1037, { "utimes", utimesFunc<RiscvLinux64> }},
408 {1038, { "stat", stat64Func<RiscvLinux64> }},
409 {1039, { "lstat", lstat64Func<RiscvLinux64> }},
410 {1040, { "pipe", pipeFunc }},
411 {1041, { "dup2", dup2Func }},
412 {1042, { "epoll_create" }},
413 {1043, { "inotifiy_init" }},
414 {1044, { "eventfd" }},
415 {1045, { "signalfd" }},
416 {1046, { "sendfile" }},
417 {1047, { "ftruncate", ftruncate64Func }},
418 {1048, { "truncate", truncate64Func }},
419 {1049, { "stat", stat64Func<RiscvLinux64> }},
420 {1050, { "lstat", lstat64Func<RiscvLinux64> }},
421 {1051, { "fstat", fstat64Func<RiscvLinux64> }},
422 {1052, { "fcntl", fcntl64Func }},
423 {1053, { "fadvise64" }},
424 {1054, { "newfstatat" }},
425 {1055, { "fstatfs", fstatfsFunc<RiscvLinux64> }},
426 {1056, { "statfs", statfsFunc<RiscvLinux64> }},
427 {1057, { "lseek", lseekFunc }},
428 {1058, { "mmap", mmapFunc<RiscvLinux64> }},
429 {1059, { "alarm" }},
430 {1060, { "getpgrp" }},
431 {1061, { "pause" }},
432 {1062, { "time", timeFunc<RiscvLinux64> }},
433 {1063, { "utime" }},
434 {1064, { "creat" }},
435 {1065, { "getdents" }},
436 {1066, { "futimesat" }},
437 {1067, { "select" }},
438 {1068, { "poll" }},
439 {1069, { "epoll_wait" }},
440 {1070, { "ustat" }},
441 {1071, { "vfork" }},
442 {1072, { "oldwait4" }},
443 {1073, { "recv" }},
444 {1074, { "send" }},
445 {1075, { "bdflush" }},
446 {1076, { "umount" }},
447 {1077, { "uselib" }},
448 {1078, { "sysctl" }},
449 {1079, { "fork" }},
450 {2011, { "getmainvars" }}
451 };
452
453 std::map<int, SyscallDescABI<DefaultSyscallABI>>
454 RiscvLinuxProcess32::syscallDescs = {
455 {0, { "io_setup" }},
456 {1, { "io_destroy" }},
457 {2, { "io_submit" }},
458 {3, { "io_cancel" }},
459 {4, { "io_getevents" }},
460 {5, { "setxattr" }},
461 {6, { "lsetxattr" }},
462 {7, { "fsetxattr" }},
463 {8, { "getxattr" }},
464 {9, { "lgetxattr" }},
465 {10, { "fgetxattr" }},
466 {11, { "listxattr" }},
467 {12, { "llistxattr" }},
468 {13, { "flistxattr" }},
469 {14, { "removexattr" }},
470 {15, { "lremovexattr" }},
471 {16, { "fremovexattr" }},
472 {17, { "getcwd", getcwdFunc }},
473 {18, { "lookup_dcookie" }},
474 {19, { "eventfd2" }},
475 {20, { "epoll_create1" }},
476 {21, { "epoll_ctl" }},
477 {22, { "epoll_pwait" }},
478 {23, { "dup", dupFunc }},
479 {24, { "dup3" }},
480 {25, { "fcntl", fcntlFunc }},
481 {26, { "inotify_init1" }},
482 {27, { "inotify_add_watch" }},
483 {28, { "inotify_rm_watch" }},
484 {29, { "ioctl", ioctlFunc<RiscvLinux32> }},
485 {30, { "ioprio_get" }},
486 {31, { "ioprio_set" }},
487 {32, { "flock" }},
488 {33, { "mknodat" }},
489 {34, { "mkdirat" }},
490 {35, { "unlinkat", unlinkatFunc<RiscvLinux32> }},
491 {36, { "symlinkat" }},
492 {37, { "linkat" }},
493 {38, { "renameat", renameatFunc<RiscvLinux32> }},
494 {39, { "umount2" }},
495 {40, { "mount" }},
496 {41, { "pivot_root" }},
497 {42, { "nfsservctl" }},
498 {43, { "statfs", statfsFunc<RiscvLinux32> }},
499 {44, { "fstatfs", fstatfsFunc<RiscvLinux32> }},
500 {45, { "truncate", truncateFunc }},
501 {46, { "ftruncate", ftruncateFunc }},
502 {47, { "fallocate", fallocateFunc }},
503 {48, { "faccessat", faccessatFunc<RiscvLinux32> }},
504 {49, { "chdir" }},
505 {50, { "fchdir" }},
506 {51, { "chroot" }},
507 {52, { "fchmod", fchmodFunc<RiscvLinux32> }},
508 {53, { "fchmodat" }},
509 {54, { "fchownat" }},
510 {55, { "fchown", fchownFunc }},
511 {56, { "openat", openatFunc<RiscvLinux32> }},
512 {57, { "close", closeFunc }},
513 {58, { "vhangup" }},
514 {59, { "pipe2" }},
515 {60, { "quotactl" }},
516 {61, { "getdents64" }},
517 {62, { "lseek", lseekFunc }},
518 {63, { "read", readFunc<RiscvLinux32> }},
519 {64, { "write", writeFunc<RiscvLinux32> }},
520 {66, { "writev", writevFunc<RiscvLinux32> }},
521 {67, { "pread64" }},
522 {68, { "pwrite64", pwrite64Func<RiscvLinux32> }},
523 {69, { "preadv" }},
524 {70, { "pwritev" }},
525 {71, { "sendfile" }},
526 {72, { "pselect6" }},
527 {73, { "ppoll" }},
528 {74, { "signalfd64" }},
529 {75, { "vmsplice" }},
530 {76, { "splice" }},
531 {77, { "tee" }},
532 {78, { "readlinkat", readlinkatFunc<RiscvLinux32> }},
533 {79, { "fstatat" }},
534 {80, { "fstat", fstatFunc<RiscvLinux32> }},
535 {81, { "sync" }},
536 {82, { "fsync" }},
537 {83, { "fdatasync" }},
538 {84, { "sync_file_range2" }},
539 {85, { "timerfd_create" }},
540 {86, { "timerfd_settime" }},
541 {87, { "timerfd_gettime" }},
542 {88, { "utimensat" }},
543 {89, { "acct" }},
544 {90, { "capget" }},
545 {91, { "capset" }},
546 {92, { "personality" }},
547 {93, { "exit", exitFunc }},
548 {94, { "exit_group", exitGroupFunc }},
549 {95, { "waitid" }},
550 {96, { "set_tid_address", setTidAddressFunc }},
551 {97, { "unshare" }},
552 {98, { "futex", futexFunc<RiscvLinux32> }},
553 {99, { "set_robust_list", ignoreWarnOnceFunc }},
554 {100, { "get_robust_list", ignoreWarnOnceFunc }},
555 {101, { "nanosleep" }},
556 {102, { "getitimer" }},
557 {103, { "setitimer" }},
558 {104, { "kexec_load" }},
559 {105, { "init_module" }},
560 {106, { "delete_module" }},
561 {107, { "timer_create" }},
562 {108, { "timer_gettime" }},
563 {109, { "timer_getoverrun" }},
564 {110, { "timer_settime" }},
565 {111, { "timer_delete" }},
566 {112, { "clock_settime" }},
567 {113, { "clock_gettime", clock_gettimeFunc<RiscvLinux32> }},
568 {114, { "clock_getres", clock_getresFunc<RiscvLinux32> }},
569 {115, { "clock_nanosleep" }},
570 {116, { "syslog" }},
571 {117, { "ptrace" }},
572 {118, { "sched_setparam" }},
573 {119, { "sched_setscheduler" }},
574 {120, { "sched_getscheduler" }},
575 {121, { "sched_getparam" }},
576 {122, { "sched_setaffinity" }},
577 {123, { "sched_getaffinity" }},
578 {124, { "sched_yield", ignoreWarnOnceFunc }},
579 {125, { "sched_get_priority_max" }},
580 {126, { "sched_get_priority_min" }},
581 {127, { "scheD_rr_get_interval" }},
582 {128, { "restart_syscall" }},
583 {129, { "kill" }},
584 {130, { "tkill" }},
585 {131, { "tgkill", tgkillFunc<RiscvLinux32> }},
586 {132, { "sigaltstack" }},
587 {133, { "rt_sigsuspend", ignoreWarnOnceFunc }},
588 {134, { "rt_sigaction", ignoreWarnOnceFunc }},
589 {135, { "rt_sigprocmask", ignoreWarnOnceFunc }},
590 {136, { "rt_sigpending", ignoreWarnOnceFunc }},
591 {137, { "rt_sigtimedwait", ignoreWarnOnceFunc }},
592 {138, { "rt_sigqueueinfo", ignoreWarnOnceFunc }},
593 {139, { "rt_sigreturn", ignoreWarnOnceFunc }},
594 {140, { "setpriority" }},
595 {141, { "getpriority" }},
596 {142, { "reboot" }},
597 {143, { "setregid" }},
598 {144, { "setgid" }},
599 {145, { "setreuid" }},
600 {146, { "setuid", ignoreFunc }},
601 {147, { "setresuid" }},
602 {148, { "getresuid" }},
603 {149, { "getresgid" }},
604 {150, { "getresgid" }},
605 {151, { "setfsuid" }},
606 {152, { "setfsgid" }},
607 {153, { "times", timesFunc<RiscvLinux32> }},
608 {154, { "setpgid", setpgidFunc }},
609 {155, { "getpgid" }},
610 {156, { "getsid" }},
611 {157, { "setsid" }},
612 {158, { "getgroups" }},
613 {159, { "setgroups" }},
614 {160, { "uname", unameFunc32 }},
615 {161, { "sethostname" }},
616 {162, { "setdomainname" }},
617 {163, { "getrlimit", getrlimitFunc<RiscvLinux32> }},
618 {164, { "setrlimit", ignoreFunc }},
619 {165, { "getrusage", getrusageFunc<RiscvLinux32> }},
620 {166, { "umask", umaskFunc }},
621 {167, { "prctl" }},
622 {168, { "getcpu" }},
623 {169, { "gettimeofday", gettimeofdayFunc<RiscvLinux32> }},
624 {170, { "settimeofday" }},
625 {171, { "adjtimex" }},
626 {172, { "getpid", getpidFunc }},
627 {173, { "getppid", getppidFunc }},
628 {174, { "getuid", getuidFunc }},
629 {175, { "geteuid", geteuidFunc }},
630 {176, { "getgid", getgidFunc }},
631 {177, { "getegid", getegidFunc }},
632 {178, { "gettid", gettidFunc }},
633 {179, { "sysinfo", sysinfoFunc<RiscvLinux32> }},
634 {180, { "mq_open" }},
635 {181, { "mq_unlink" }},
636 {182, { "mq_timedsend" }},
637 {183, { "mq_timedrecieve" }},
638 {184, { "mq_notify" }},
639 {185, { "mq_getsetattr" }},
640 {186, { "msgget" }},
641 {187, { "msgctl" }},
642 {188, { "msgrcv" }},
643 {189, { "msgsnd" }},
644 {190, { "semget" }},
645 {191, { "semctl" }},
646 {192, { "semtimedop" }},
647 {193, { "semop" }},
648 {194, { "shmget" }},
649 {195, { "shmctl" }},
650 {196, { "shmat" }},
651 {197, { "shmdt" }},
652 {198, { "socket" }},
653 {199, { "socketpair" }},
654 {200, { "bind" }},
655 {201, { "listen" }},
656 {202, { "accept" }},
657 {203, { "connect" }},
658 {204, { "getsockname" }},
659 {205, { "getpeername" }},
660 {206, { "sendo" }},
661 {207, { "recvfrom" }},
662 {208, { "setsockopt" }},
663 {209, { "getsockopt" }},
664 {210, { "shutdown" }},
665 {211, { "sendmsg" }},
666 {212, { "recvmsg" }},
667 {213, { "readahead" }},
668 {214, { "brk", brkFunc }},
669 {215, { "munmap", munmapFunc }},
670 {216, { "mremap", mremapFunc<RiscvLinux32> }},
671 {217, { "add_key" }},
672 {218, { "request_key" }},
673 {219, { "keyctl" }},
674 {220, { "clone", cloneBackwardsFunc<RiscvLinux32> }},
675 {221, { "execve", execveFunc<RiscvLinux32> }},
676 {222, { "mmap", mmapFunc<RiscvLinux32> }},
677 {223, { "fadvise64" }},
678 {224, { "swapon" }},
679 {225, { "swapoff" }},
680 {226, { "mprotect", ignoreFunc }},
681 {227, { "msync", ignoreFunc }},
682 {228, { "mlock", ignoreFunc }},
683 {229, { "munlock", ignoreFunc }},
684 {230, { "mlockall", ignoreFunc }},
685 {231, { "munlockall", ignoreFunc }},
686 {232, { "mincore", ignoreFunc }},
687 {233, { "madvise", ignoreFunc }},
688 {234, { "remap_file_pages" }},
689 {235, { "mbind", ignoreFunc }},
690 {236, { "get_mempolicy" }},
691 {237, { "set_mempolicy" }},
692 {238, { "migrate_pages" }},
693 {239, { "move_pages" }},
694 {240, { "tgsigqueueinfo" }},
695 {241, { "perf_event_open" }},
696 {242, { "accept4" }},
697 {243, { "recvmmsg" }},
698 {260, { "wait4" }},
699 {261, { "prlimit64", prlimitFunc<RiscvLinux32> }},
700 {262, { "fanotify_init" }},
701 {263, { "fanotify_mark" }},
702 {264, { "name_to_handle_at" }},
703 {265, { "open_by_handle_at" }},
704 {266, { "clock_adjtime" }},
705 {267, { "syncfs" }},
706 {268, { "setns" }},
707 {269, { "sendmmsg" }},
708 {270, { "process_vm_ready" }},
709 {271, { "process_vm_writev" }},
710 {272, { "kcmp" }},
711 {273, { "finit_module" }},
712 {274, { "sched_setattr" }},
713 {275, { "sched_getattr" }},
714 {276, { "renameat2" }},
715 {277, { "seccomp" }},
716 {278, { "getrandom" }},
717 {279, { "memfd_create" }},
718 {280, { "bpf" }},
719 {281, { "execveat" }},
720 {282, { "userfaultid" }},
721 {283, { "membarrier" }},
722 {284, { "mlock2" }},
723 {285, { "copy_file_range" }},
724 {286, { "preadv2" }},
725 {287, { "pwritev2" }},
726 {1024, { "open", openFunc<RiscvLinux32> }},
727 {1025, { "link" }},
728 {1026, { "unlink", unlinkFunc }},
729 {1027, { "mknod" }},
730 {1028, { "chmod", chmodFunc<RiscvLinux32> }},
731 {1029, { "chown", chownFunc }},
732 {1030, { "mkdir", mkdirFunc }},
733 {1031, { "rmdir" }},
734 {1032, { "lchown" }},
735 {1033, { "access", accessFunc }},
736 {1034, { "rename", renameFunc }},
737 {1035, { "readlink", readlinkFunc }},
738 {1036, { "symlink" }},
739 {1037, { "utimes", utimesFunc<RiscvLinux32> }},
740 {1038, { "stat", statFunc<RiscvLinux32> }},
741 {1039, { "lstat", lstatFunc<RiscvLinux32> }},
742 {1040, { "pipe", pipeFunc }},
743 {1041, { "dup2", dup2Func }},
744 {1042, { "epoll_create" }},
745 {1043, { "inotifiy_init" }},
746 {1044, { "eventfd" }},
747 {1045, { "signalfd" }},
748 {1046, { "sendfile" }},
749 {1047, { "ftruncate", ftruncateFunc }},
750 {1048, { "truncate", truncateFunc }},
751 {1049, { "stat", statFunc<RiscvLinux32> }},
752 {1050, { "lstat", lstatFunc<RiscvLinux32> }},
753 {1051, { "fstat", fstatFunc<RiscvLinux32> }},
754 {1052, { "fcntl", fcntlFunc }},
755 {1053, { "fadvise64" }},
756 {1054, { "newfstatat" }},
757 {1055, { "fstatfs", fstatfsFunc<RiscvLinux32> }},
758 {1056, { "statfs", statfsFunc<RiscvLinux32> }},
759 {1057, { "lseek", lseekFunc }},
760 {1058, { "mmap", mmapFunc<RiscvLinux32> }},
761 {1059, { "alarm" }},
762 {1060, { "getpgrp" }},
763 {1061, { "pause" }},
764 {1062, { "time", timeFunc<RiscvLinux32> }},
765 {1063, { "utime" }},
766 {1064, { "creat" }},
767 {1065, { "getdents" }},
768 {1066, { "futimesat" }},
769 {1067, { "select" }},
770 {1068, { "poll" }},
771 {1069, { "epoll_wait" }},
772 {1070, { "ustat" }},
773 {1071, { "vfork" }},
774 {1072, { "oldwait4" }},
775 {1073, { "recv" }},
776 {1074, { "send" }},
777 {1075, { "bdflush" }},
778 {1076, { "umount" }},
779 {1077, { "uselib" }},
780 {1078, { "sysctl" }},
781 {1079, { "fork" }},
782 {2011, { "getmainvars" }}
783 };
784
785 RiscvLinuxProcess64::RiscvLinuxProcess64(ProcessParams * params,
786 ObjectFile *objFile) : RiscvProcess64(params, objFile)
787 {}
788
789 SyscallDesc*
790 RiscvLinuxProcess64::getDesc(int callnum)
791 {
792 return syscallDescs.find(callnum) != syscallDescs.end() ?
793 &syscallDescs.at(callnum) : nullptr;
794 }
795
796 void
797 RiscvLinuxProcess64::syscall(ThreadContext *tc, Fault *fault)
798 {
799 doSyscall(tc->readIntReg(SyscallNumReg), tc, fault);
800 }
801
802 RiscvLinuxProcess32::RiscvLinuxProcess32(ProcessParams * params,
803 ObjectFile *objFile) : RiscvProcess32(params, objFile)
804 {}
805
806 SyscallDesc*
807 RiscvLinuxProcess32::getDesc(int callnum)
808 {
809 return syscallDescs.find(callnum) != syscallDescs.end() ?
810 &syscallDescs.at(callnum) : nullptr;
811 }
812
813 void
814 RiscvLinuxProcess32::syscall(ThreadContext *tc, Fault *fault)
815 {
816 doSyscall(tc->readIntReg(SyscallNumReg), tc, fault);
817 }