42 #include <sys/syscall.h> 65 load(ProcessParams *params,
ObjectFile *obj_file)
override 67 auto arch = obj_file->
getArch();
74 warn(
"Unknown operating system; assuming Linux.");
88 X86LinuxObjectFileLoader loader;
100 strcpy(
name->sysname,
"Linux");
101 strcpy(
name->nodename,
"sim.gem5.org");
102 strcpy(
name->release, process->release.c_str());
103 strcpy(
name->version,
"#1 Mon Aug 18 11:32:15 EDT 2003");
104 strcpy(
name->machine,
"x86_64");
126 uint64_t
addr = process->getSyscallArg(tc, index);
127 uint64_t fsBase, gsBase;
138 p.
write(addr, fsBase);
146 p.
write(addr, gsBase);
154 Bitfield<0> seg_32bit;
163 uint32_t entry_number;
180 const int minTLSEntry = 6;
181 const int numTLSEntries = 3;
182 const int maxTLSEntry = minTLSEntry + numTLSEntries - 1;
189 assert((maxTLSEntry + 1) *
sizeof(uint64_t) <= x86p->
gdtSize());
194 gdt(x86p->
gdtStart() + minTLSEntry *
sizeof(uint64_t),
195 numTLSEntries *
sizeof(uint64_t));
201 panic(
"Failed to copy in GDT for %s.\n", desc->
name());
203 if (userDesc->entry_number == (uint32_t)(-1)) {
205 for (
int i = 0;
i < numTLSEntries;
i++) {
207 userDesc->entry_number =
i + minTLSEntry;
212 if (userDesc->entry_number == (uint32_t)(-1))
216 int index = userDesc->entry_number;
218 if (index < minTLSEntry || index > maxTLSEntry)
221 index -= minTLSEntry;
224 SegDescriptor segDesc = 0;
225 UserDescFlags flags = userDesc->flags;
227 segDesc.limitLow =
bits(userDesc->limit, 15, 0);
228 segDesc.baseLow =
bits(userDesc->base_addr, 23, 0);
230 if (!flags.read_exec_only)
232 if (
bits((uint8_t)flags.contents, 0))
234 if (
bits((uint8_t)flags.contents, 1))
235 segDesc.type.codeOrData = 1;
238 if (!flags.seg_not_present)
240 segDesc.limitHigh =
bits(userDesc->limit, 19, 16);
246 if (flags.limit_in_pages)
248 segDesc.baseHigh =
bits(userDesc->base_addr, 31, 24);
250 gdt[
index] = (uint64_t)segDesc;
255 panic(
"Failed to copy out GDT for %s.\n", desc->
name());
261 {
"read", readFunc<X86Linux64> },
262 {
"write", writeFunc<X86Linux64> },
263 {
"open", openFunc<X86Linux64> },
265 {
"stat", stat64Func<X86Linux64> },
266 {
"fstat", fstat64Func<X86Linux64> },
267 {
"lstat", lstat64Func<X86Linux64> },
268 {
"poll", pollFunc<X86Linux64> },
270 {
"mmap", mmapFunc<X86Linux64> },
277 {
"ioctl", ioctlFunc<X86Linux64> },
279 {
"pwrite64", pwrite64Func<X86Linux64> },
280 {
"readv", readvFunc<X86Linux64> },
281 {
"writev", writevFunc<X86Linux64> },
284 {
"select", selectFunc<X86Linux64> },
286 {
"mremap", mremapFunc<X86Linux64> },
302 {
"socket", socketFunc<X86Linux64> },
304 {
"accept", acceptFunc<X86Linux64> },
314 {
"socketpair", socketpairFunc<X86Linux64> },
317 {
"clone", cloneFunc<X86Linux64> },
320 {
"execve", execveFunc<X86Linux64> },
322 {
"wait4", wait4Func<X86Linux64> },
339 #if defined(SYS_getdents) 340 {
"getdents", getdentsFunc },
361 {
"gettimeofday", gettimeofdayFunc<X86Linux64> },
362 {
"getrlimit", getrlimitFunc<X86Linux64> },
363 {
"getrusage", getrusageFunc<X86Linux64> },
364 {
"sysinfo", sysinfoFunc<X86Linux64> },
365 {
"times", timesFunc<X86Linux64> },
393 {
"rt_sigtimedwait" },
394 {
"rt_sigqueueinfo" },
402 {
"statfs", statfsFunc<X86Linux64> },
403 {
"fstatfs", fstatfsFunc<X86Linux64> },
407 {
"sched_setparam" },
408 {
"sched_getparam" },
409 {
"sched_setscheduler" },
410 {
"sched_getscheduler" },
411 {
"sched_get_priority_max" },
412 {
"sched_get_priority_min" },
413 {
"sched_rr_get_interval" },
442 {
"get_kernel_syms" },
466 {
"time", timeFunc<X86Linux64> },
467 {
"futex", futexFunc<X86Linux64> },
468 {
"sched_setaffinity" },
470 {
"set_thread_area" },
476 {
"get_thread_area" },
477 {
"lookup_dcookie" },
480 {
"epoll_wait_old" },
481 {
"remap_file_pages" },
484 {
"restart_syscall" },
490 {
"timer_getoverrun" },
493 {
"clock_gettime", clock_gettimeFunc<X86Linux64> },
494 {
"clock_getres", clock_getresFunc<X86Linux64> },
495 {
"clock_nanosleep" },
499 {
"tgkill", tgkillFunc<X86Linux64> },
508 {
"mq_timedreceive" },
519 {
"inotify_add_watch" },
520 {
"inotify_rm_watch" },
522 {
"openat", openatFunc<X86Linux64> },
539 {
"get_robust_list" },
542 {
"sync_file_range" },
548 {
"timerfd_create" },
549 {
"eventfd", eventfdFunc<X86Linux64> },
551 {
"timerfd_settime" },
552 {
"timerfd_gettime" },
555 {
"eventfd2", eventfdFunc<X86Linux64> },
562 {
"rt_tgsigqueueinfo" },
563 {
"perf_event_open" },
567 {
"prlimit64", prlimitFunc<X86Linux64> },
568 {
"name_to_handle_at" },
569 {
"open_by_handle_at" },
575 {
"proess_vm_readv" },
576 {
"proess_vm_writev" },
581 X86_64LinuxProcess::X86_64LinuxProcess(ProcessParams * params,
601 {
"restart_syscall" },
604 {
"read", readFunc<X86Linux32> },
605 {
"write", writeFunc<X86Linux32> },
606 {
"open", openFunc<X86Linux32> },
612 {
"execve", execveFunc<X86Linux32> },
614 {
"time", timeFunc<X86Linux32> },
644 {
"times", timesFunc<X86Linux32> },
655 {
"ioctl", ioctlFunc<X86Linux32> },
677 {
"getrlimit", getrlimitFunc<X86Linux32> },
678 {
"getrusage", getrusageFunc<X86Linux32> },
683 {
"select", selectFunc<X86Linux32> },
715 {
"wait4", wait4Func<X86Linux32> },
717 {
"sysinfo", sysinfoFunc<X86Linux32> },
721 {
"clone", cloneFunc<X86Linux32> },
731 {
"get_kernel_syms" },
742 #if defined(SYS_getdents) 743 {
"getdents", getdentsFunc },
750 {
"readv", readvFunc<X86Linux32> },
751 {
"writev", writevFunc<X86Linux32> },
759 {
"sched_setparam" },
760 {
"sched_getparam" },
761 {
"sched_setscheduler" },
762 {
"sched_getscheduler" },
764 {
"sched_get_priority_max" },
765 {
"sched_get_priority_min" },
766 {
"sched_rr_get_interval" },
773 {
"poll", pollFunc<X86Linux32> },
782 {
"rt_sigtimedwait" },
783 {
"rt_sigqueueinfo" },
797 {
"mmap2", mmap2Func<X86Linux32> },
800 {
"stat64", stat64Func<X86Linux32> },
802 {
"fstat64", fstat64Func<X86Linux32> },
846 {
"sched_setaffinity" },
849 {
"get_thread_area" },
858 {
"lookup_dcookie" },
862 {
"remap_file_pages" },
867 {
"timer_getoverrun" },
870 {
"clock_gettime", clock_gettimeFunc<X86Linux32> },
872 {
"clock_nanosleep" },
875 {
"tgkill", tgkillFunc<X86Linux32> },
885 {
"mq_timedreceive" },
890 {
"sys_setaltroot" },
897 {
"inotify_add_watch" },
898 {
"inotify_rm_watch" },
900 {
"openat", openatFunc<X86Linux32> },
919 {
"sync_file_range" },
928 {
"eventfd", eventfdFunc<X86Linux32> }
#define panic(...)
This implements a cprintf based panic() function.
VSyscallPage vsyscallPage
const std::string & name()
EndBitUnion(UserDescFlags) struct UserDesc32
SyscallReturn geteuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target geteuid() handler.
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.
SyscallReturn dup2Func(SyscallDesc *desc, int num, ThreadContext *tc, int old_tgt_fd, int new_tgt_fd)
Target dup2() handler.
SyscallReturn getcwdFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr buf_ptr, unsigned long size)
Target getcwd() handler.
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual PortProxy & getVirtProxy()=0
Bitfield< 2, 1 > contents
virtual Process * getProcessPtr()=0
SyscallReturn fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Target fcntl() handler.
Overload hash function for BasicBlockRange type.
void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault)
static SyscallReturn unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target uname() handler.
static SyscallReturn archPrctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
SyscallReturn fallocateFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int tgt_fd, int mode, off_t offset, off_t len)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
SyscallReturn sendtoFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, socklen_t addrLen)
SyscallReturn closeFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd)
Target close() handler.
static SyscallDescABI< DefaultSyscallABI > syscallDescs32[]
SyscallReturn getegidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getegid() handler.
SyscallReturn renameFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr oldpath, Addr newpath)
Target rename() handler.
static SyscallReturn setThreadArea32Func(SyscallDesc *desc, int callnum, ThreadContext *tc)
SyscallReturn umaskFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Target umask() handler.
SyscallReturn pipe2Func(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target pipe() handler.
SyscallReturn munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Target munmap() handler.
SyscallReturn chdirFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname)
Target chdir() handler.
SyscallReturn getuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Bitfield< 4 > limit_in_pages
SyscallReturn getpeernameFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr sockAddrPtr, Addr addrlenPtr)
SyscallReturn unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname)
Target unlink() handler.
Bitfield< 3 > read_exec_only
SyscallReturn exitGroupFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int status)
Target exit_group() handler: terminate simulation. (exit all threads)
SyscallReturn mkdirFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, mode_t mode)
Target mkdir() handler.
SyscallReturn getsocknameFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
void syscall(ThreadContext *tc, Fault *fault) override
SyscallReturn _llseekFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, uint64_t offset_high, uint32_t offset_low, Addr result_ptr, int whence)
Target _llseek() handler.
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, RegVal flags) override
SyscallReturn shutdownFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, int how)
Target shutdown() handler.
SyscallReturn recvfromFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, Addr addrlenPtr)
SyscallReturn setsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, socklen_t len)
SyscallReturn readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, Addr buf_ptr, size_t bufsiz)
Target readlink() handler.
SyscallReturn mknodFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, mode_t mode, dev_t dev)
Target mknod() handler.
virtual RegVal getSyscallArg(ThreadContext *tc, int &i)=0
SyscallReturn rmdirFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname)
SyscallReturn ftruncateFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, off_t length)
Target ftruncate() handler.
SyscallReturn getppidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getppid() handler.
SyscallReturn brkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr new_brk)
Target brk() handler: set brk address.
static SyscallDescABI< DefaultSyscallABI > syscallDescs64[]
SyscallReturn ignoreWarnOnceFunc(SyscallDesc *desc, int num, ThreadContext *tc)
Like above, but only prints a warning once per syscall desc it's used with.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
SyscallReturn dupFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd)
FIXME: The file description is not shared among file descriptors created with dup.
SyscallReturn getgidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getgid() handler.
SyscallReturn linkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target link() handler.
SyscallReturn sendmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, RegVal flags) override
SyscallReturn listenFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, int backlog)
SyscallReturn getpgrpFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target getpgrpFunc() handler.
This class provides the wrapper interface for the system call implementations which are defined in th...
SyscallReturn gettidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target gettid() handler.
This object is a proxy for a port or other object which implements the functional response protocol...
SyscallReturn truncateFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, off_t length)
Target truncate() handler.
SyscallReturn getsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, Addr lenPtr)
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, RegVal flags) override
SyscallReturn lseekFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
Target lseek() handler.
BitfieldType< SegDescriptorLimit > limit
SyscallReturn pipeFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
Target pipe() handler.
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
SyscallReturn symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target symlink() handler.
This file defines objects used to emulate syscalls from the target application on the host machine...
This is exposed globally, independent of the ISA.
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, RegVal flags) override
SyscallReturn setTidAddressFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, uint64_t tidPtr)
Target set_tid_address() handler.
SyscallReturn connectFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
SyscallReturn setpgidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int pid, int pgid)
Target setpgid() handler.
SyscallReturn recvmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
SyscallReturn truncate64Func(SyscallDesc *desc, int num, ThreadContext *tc, Addr pathname, int64_t length)
Target truncate64() handler.
SyscallReturn bindFunc(SyscallDesc *desc, int num, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
void write(Addr address, const T &data) const
Write object T to address.
BitUnion32(UserDescFlags) Bitfield< 0 > seg_32bit
This class represents the return value from an emulated system call, including any errno setting...
Bitfield< 5 > seg_not_present
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
Each instance of a Loader subclass will have a chance to try to load an object file when tryLoaders i...
std::shared_ptr< FaultBase > Fault
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.
I386LinuxProcess(ProcessParams *params, ObjectFile *objFile)
Constructor.
void syscall(ThreadContext *tc, Fault *fault) override
SyscallReturn ftruncate64Func(SyscallDesc *desc, int num, ThreadContext *tc)
Target ftruncate64() handler.