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