linux.hh revision 13651
1451SN/A/* 25795Ssaidi@eecs.umich.edu * Copyright (c) 2004-2009 The Regents of The University of Michigan 3451SN/A * All rights reserved. 4451SN/A * 5451SN/A * Redistribution and use in source and binary forms, with or without 6451SN/A * modification, are permitted provided that the following conditions are 7451SN/A * met: redistributions of source code must retain the above copyright 8451SN/A * notice, this list of conditions and the following disclaimer; 9451SN/A * redistributions in binary form must reproduce the above copyright 10451SN/A * notice, this list of conditions and the following disclaimer in the 11451SN/A * documentation and/or other materials provided with the distribution; 12451SN/A * neither the name of the copyright holders nor the names of its 13451SN/A * contributors may be used to endorse or promote products derived from 14451SN/A * this software without specific prior written permission. 15451SN/A * 16451SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17451SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18451SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19451SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20451SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21451SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22451SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23451SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24451SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25451SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26451SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 29451SN/A */ 30451SN/A 31451SN/A#ifndef __LINUX_HH__ 32451SN/A#define __LINUX_HH__ 336215Snate@binkert.org 346215Snate@binkert.org#include "base/types.hh" 352093SN/A 365795Ssaidi@eecs.umich.edu#include <string> 372093SN/A 383113Sgblack@eecs.umich.edu#include "kern/operatingsystem.hh" 3911800Sbrandon.potter@amd.com#include "sim/process.hh" 402423SN/A 415795Ssaidi@eecs.umich.educlass ThreadContext; 425795Ssaidi@eecs.umich.edu 432093SN/A/// 442093SN/A/// This class encapsulates the types, structures, constants, 452093SN/A/// functions, and syscall-number mappings specific to the Alpha Linux 462093SN/A/// syscall interface. 472093SN/A/// 483113Sgblack@eecs.umich.educlass Linux : public OperatingSystem 493113Sgblack@eecs.umich.edu{ 502093SN/A 512093SN/A public: 522093SN/A 532093SN/A //@{ 542093SN/A /// Basic Linux types. 553122Sgblack@eecs.umich.edu typedef uint64_t size_t; 562093SN/A typedef uint64_t off_t; 572093SN/A typedef int64_t time_t; 586684Stjones1@inf.ed.ac.uk typedef int64_t clock_t; 592093SN/A typedef uint32_t uid_t; 603122Sgblack@eecs.umich.edu typedef uint32_t gid_t; 612093SN/A //@} 622093SN/A 632093SN/A /// Stat buffer. Note that we can't call it 'stat' since that 643113Sgblack@eecs.umich.edu /// gets #defined to something else on some systems. This type 653113Sgblack@eecs.umich.edu /// can be specialized by architecture specific "Linux" classes 663113Sgblack@eecs.umich.edu typedef struct { 675543Ssaidi@eecs.umich.edu uint32_t st_dev; //!< device 685543Ssaidi@eecs.umich.edu uint32_t st_ino; //!< inode 695543Ssaidi@eecs.umich.edu uint32_t st_mode; //!< mode 705543Ssaidi@eecs.umich.edu uint32_t st_nlink; //!< link count 715543Ssaidi@eecs.umich.edu uint32_t st_uid; //!< owner's user ID 725543Ssaidi@eecs.umich.edu uint32_t st_gid; //!< owner's group ID 735543Ssaidi@eecs.umich.edu uint32_t st_rdev; //!< device number 745543Ssaidi@eecs.umich.edu int32_t _pad1; //!< for alignment 755543Ssaidi@eecs.umich.edu int64_t st_size; //!< file size in bytes 765543Ssaidi@eecs.umich.edu uint64_t st_atimeX; //!< time of last access 775543Ssaidi@eecs.umich.edu uint64_t st_mtimeX; //!< time of last modification 785543Ssaidi@eecs.umich.edu uint64_t st_ctimeX; //!< time of last status change 795543Ssaidi@eecs.umich.edu uint32_t st_blksize; //!< optimal I/O block size 805543Ssaidi@eecs.umich.edu int32_t st_blocks; //!< number of blocks allocated 815543Ssaidi@eecs.umich.edu uint32_t st_flags; //!< flags 825543Ssaidi@eecs.umich.edu uint32_t st_gen; //!< unknown 833113Sgblack@eecs.umich.edu } tgt_stat; 842093SN/A 852093SN/A // same for stat64 863113Sgblack@eecs.umich.edu typedef struct { 875543Ssaidi@eecs.umich.edu uint64_t st_dev; 885543Ssaidi@eecs.umich.edu uint64_t st_ino; 895543Ssaidi@eecs.umich.edu uint64_t st_rdev; 905543Ssaidi@eecs.umich.edu int64_t st_size; 915543Ssaidi@eecs.umich.edu uint64_t st_blocks; 922093SN/A 935543Ssaidi@eecs.umich.edu uint32_t st_mode; 945543Ssaidi@eecs.umich.edu uint32_t st_uid; 955543Ssaidi@eecs.umich.edu uint32_t st_gid; 965543Ssaidi@eecs.umich.edu uint32_t st_blksize; 975543Ssaidi@eecs.umich.edu uint32_t st_nlink; 985543Ssaidi@eecs.umich.edu uint32_t __pad0; 992093SN/A 1005543Ssaidi@eecs.umich.edu uint64_t st_atimeX; 1015543Ssaidi@eecs.umich.edu uint64_t st_atime_nsec; 1025543Ssaidi@eecs.umich.edu uint64_t st_mtimeX; 1035543Ssaidi@eecs.umich.edu uint64_t st_mtime_nsec; 1045543Ssaidi@eecs.umich.edu uint64_t st_ctimeX; 1055543Ssaidi@eecs.umich.edu uint64_t st_ctime_nsec; 1065543Ssaidi@eecs.umich.edu int64_t ___unused[3]; 1073113Sgblack@eecs.umich.edu } tgt_stat64; 1082093SN/A 1092093SN/A /// Length of strings in struct utsname (plus 1 for null char). 1102093SN/A static const int _SYS_NMLN = 65; 1112093SN/A 1122093SN/A /// Interface struct for uname(). 1132093SN/A struct utsname { 1145543Ssaidi@eecs.umich.edu char sysname[_SYS_NMLN]; //!< System name. 1155543Ssaidi@eecs.umich.edu char nodename[_SYS_NMLN]; //!< Node name. 1165543Ssaidi@eecs.umich.edu char release[_SYS_NMLN]; //!< OS release. 1175543Ssaidi@eecs.umich.edu char version[_SYS_NMLN]; //!< OS version. 1185543Ssaidi@eecs.umich.edu char machine[_SYS_NMLN]; //!< Machine type. 1192093SN/A }; 1202093SN/A 1212093SN/A /// Limit struct for getrlimit/setrlimit. 1222093SN/A struct rlimit { 1235543Ssaidi@eecs.umich.edu uint64_t rlim_cur; //!< soft limit 1245543Ssaidi@eecs.umich.edu uint64_t rlim_max; //!< hard limit 1252093SN/A }; 1262093SN/A 1272093SN/A /// For gettimeofday(). 1282093SN/A struct timeval { 1295543Ssaidi@eecs.umich.edu int64_t tv_sec; //!< seconds 1305543Ssaidi@eecs.umich.edu int64_t tv_usec; //!< microseconds 1312093SN/A }; 1322093SN/A 13310796Sbrandon.potter@amd.com /// For clock_gettime(). 13410796Sbrandon.potter@amd.com struct timespec { 13510796Sbrandon.potter@amd.com time_t tv_sec; //!< seconds 13610796Sbrandon.potter@amd.com int64_t tv_nsec; //!< nanoseconds 13710796Sbrandon.potter@amd.com }; 13810796Sbrandon.potter@amd.com 1396683Stjones1@inf.ed.ac.uk /// Clock ticks per second, for times(). 1406744SAli.Saidi@arm.com static const int M5_SC_CLK_TCK = 100; 1416683Stjones1@inf.ed.ac.uk 1426683Stjones1@inf.ed.ac.uk /// For times(). 1436683Stjones1@inf.ed.ac.uk struct tms { 1446683Stjones1@inf.ed.ac.uk int64_t tms_utime; //!< user time 1456683Stjones1@inf.ed.ac.uk int64_t tms_stime; //!< system time 1466683Stjones1@inf.ed.ac.uk int64_t tms_cutime; //!< user time of children 1476683Stjones1@inf.ed.ac.uk int64_t tms_cstime; //!< system time of children 1486683Stjones1@inf.ed.ac.uk }; 1496683Stjones1@inf.ed.ac.uk 1502093SN/A // For writev/readv 1512093SN/A struct tgt_iovec { 1522093SN/A uint64_t iov_base; // void * 1532093SN/A uint64_t iov_len; 1542093SN/A }; 1552093SN/A 15613570Sbrandon.potter@amd.com // For select(). 15713570Sbrandon.potter@amd.com // linux-3.14-src/include/uapi/linux/posix_types.h 15813570Sbrandon.potter@amd.com struct fd_set{ 15913570Sbrandon.potter@amd.com#ifndef LINUX__FD_SETSIZE 16013570Sbrandon.potter@amd.com#define LINUX__FD_SETSIZE 1024 16113570Sbrandon.potter@amd.com unsigned long fds_bits[LINUX__FD_SETSIZE / (8 * sizeof(long))]; 16213570Sbrandon.potter@amd.com#endif 16313570Sbrandon.potter@amd.com }; 16413570Sbrandon.potter@amd.com 1659141Smarc.orr@gmail.com //@{ 1669141Smarc.orr@gmail.com /// ioctl() command codes. 1679141Smarc.orr@gmail.com static const unsigned TGT_TCGETS = 0x5401; 1689141Smarc.orr@gmail.com static const unsigned TGT_TCGETA = 0x5405; 1699141Smarc.orr@gmail.com static const unsigned TGT_TCSETAW = 0x5407; 1709141Smarc.orr@gmail.com static const unsigned TGT_FIONREAD = 0x541B; 1719141Smarc.orr@gmail.com //@} 1729141Smarc.orr@gmail.com 1739141Smarc.orr@gmail.com /// Return true for the ioctl codes for which we return ENOTTY 1749141Smarc.orr@gmail.com /// *without* printing a warning, since we know that ENOTTY is the 1759141Smarc.orr@gmail.com /// correct thing to return (and not just a sign that we don't 1769141Smarc.orr@gmail.com /// recognize the ioctl code. 1779141Smarc.orr@gmail.com static bool 1789141Smarc.orr@gmail.com isTtyReq(unsigned req) 1799141Smarc.orr@gmail.com { 1809141Smarc.orr@gmail.com switch (req) { 1819141Smarc.orr@gmail.com case TGT_FIONREAD: 1829141Smarc.orr@gmail.com case TGT_TCSETAW: 1839141Smarc.orr@gmail.com case TGT_TCGETS: 1849141Smarc.orr@gmail.com case TGT_TCGETA: 1859141Smarc.orr@gmail.com return true; 1869141Smarc.orr@gmail.com default: 1879141Smarc.orr@gmail.com return false; 1889141Smarc.orr@gmail.com } 1899141Smarc.orr@gmail.com } 1909141Smarc.orr@gmail.com 1912093SN/A 1929146Smarc.orr@gmail.com /// Resource constants for getrlimit(). 1939146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_CPU = 0; 1949146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_FSIZE = 1; 1959146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_DATA = 2; 1969146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_STACK = 3; 1979146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_CORE = 4; 1989146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RSS = 5; 1999146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NPROC = 6; 2009146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NOFILE = 7; 2019146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_MEMLOCK = 8; 2029146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_AS = 9; 2039146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_LOCKS = 10; 2049146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_SIGPENDING = 11; 2059146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_MSGQUEUE = 12; 2069146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NICE = 13; 2079146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RTPRIO = 14; 2089146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RTTIME = 15; 2099146Smarc.orr@gmail.com static const unsigned TGT_RLIM_NLIMITS = 16; 2109146Smarc.orr@gmail.com 2112093SN/A /// For getrusage(). 2129146Smarc.orr@gmail.com static const int TGT_RUSAGE_SELF = 0; 2139146Smarc.orr@gmail.com static const int TGT_RUSAGE_CHILDREN = -1; 2149146Smarc.orr@gmail.com static const int TGT_RUSAGE_BOTH = -2; 2159146Smarc.orr@gmail.com 2162093SN/A struct rusage { 2175543Ssaidi@eecs.umich.edu struct timeval ru_utime; //!< user time used 2185543Ssaidi@eecs.umich.edu struct timeval ru_stime; //!< system time used 2195543Ssaidi@eecs.umich.edu int64_t ru_maxrss; //!< max rss 2205543Ssaidi@eecs.umich.edu int64_t ru_ixrss; //!< integral shared memory size 2215543Ssaidi@eecs.umich.edu int64_t ru_idrss; //!< integral unshared data " 2225543Ssaidi@eecs.umich.edu int64_t ru_isrss; //!< integral unshared stack " 2235543Ssaidi@eecs.umich.edu int64_t ru_minflt; //!< page reclaims - total vmfaults 2245543Ssaidi@eecs.umich.edu int64_t ru_majflt; //!< page faults 2255543Ssaidi@eecs.umich.edu int64_t ru_nswap; //!< swaps 2265543Ssaidi@eecs.umich.edu int64_t ru_inblock; //!< block input operations 2275543Ssaidi@eecs.umich.edu int64_t ru_oublock; //!< block output operations 2285543Ssaidi@eecs.umich.edu int64_t ru_msgsnd; //!< messages sent 2295543Ssaidi@eecs.umich.edu int64_t ru_msgrcv; //!< messages received 2305543Ssaidi@eecs.umich.edu int64_t ru_nsignals; //!< signals received 2315543Ssaidi@eecs.umich.edu int64_t ru_nvcsw; //!< voluntary context switches 2325543Ssaidi@eecs.umich.edu int64_t ru_nivcsw; //!< involuntary " 2332093SN/A }; 2342093SN/A 23511851Sbrandon.potter@amd.com static int openSpecialFile(std::string path, Process *process, 23611851Sbrandon.potter@amd.com ThreadContext *tc); 23711851Sbrandon.potter@amd.com static std::string procMeminfo(Process *process, ThreadContext *tc); 23811907SBrandon.Potter@amd.com static std::string etcPasswd(Process *process, ThreadContext *tc); 23912591Sjason@lowepower.com static std::string cpuOnline(Process *process, ThreadContext *tc); 2405795Ssaidi@eecs.umich.edu 2419112Smarc.orr@gmail.com // For futex system call 24213642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_WAIT = 0; 24313642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_WAKE = 1; 24413650Smw828@cornell.edu static const unsigned TGT_FUTEX_REQUEUE = 3; 24513650Smw828@cornell.edu static const unsigned TGT_FUTEX_CMP_REQUEUE = 4; 24613651Smw828@cornell.edu static const unsigned TGT_FUTEX_WAKE_OP = 5; 24713642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_WAIT_BITSET = 9; 24813642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_WAKE_BITSET = 10; 24913642Sqtt2@cornell.edu static const unsigned TGT_EAGAIN = 11; 25013642Sqtt2@cornell.edu static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN; 25113642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_PRIVATE_FLAG = 128; 25213642Sqtt2@cornell.edu static const unsigned TGT_FUTEX_CLOCK_REALTIME_FLAG = 256; 25313651Smw828@cornell.edu // op field of futex_wake_op operation 25413651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_SET = 0; // uaddr2 = oparg; 25513651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_ADD = 1; // uaddr2 += oparg; 25613651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_OR = 2; // uaddr2 |= oparg; 25713651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_ANDN = 3; // uaddr2 &= ~oparg; 25813651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_XOR = 4; // uaddr2 ^= oparg; 25913651Smw828@cornell.edu // Use (1 << oparg) as operand 26013651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_ARG_SHIFT = 8; 26113651Smw828@cornell.edu // cmp field of futex_wake_op operation 26213651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_EQ = 0; 26313651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_NE = 1; 26413651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_LT = 2; 26513651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_LE = 3; 26613651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_GT = 4; 26713651Smw828@cornell.edu static const unsigned TGT_FUTEX_OP_CMP_GE = 5; 2689112Smarc.orr@gmail.com 26910027SChris.Adeniyi-Jones@arm.com // for *at syscalls 27010027SChris.Adeniyi-Jones@arm.com static const int TGT_AT_FDCWD = -100; 27110027SChris.Adeniyi-Jones@arm.com 27210027SChris.Adeniyi-Jones@arm.com // for MREMAP 27310027SChris.Adeniyi-Jones@arm.com static const unsigned TGT_MREMAP_MAYMOVE = 0x1; 27410027SChris.Adeniyi-Jones@arm.com static const unsigned TGT_MREMAP_FIXED = 0x2; 27511382Sbrandon.potter@amd.com 27611382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_VM = 0x00000100; 27711382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_FS = 0x00000200; 27811382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_FILES = 0x00000400; 27911382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_SIGHAND = 0x00000800; 28011382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_PTRACE = 0x00002000; 28111382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_VFORK = 0x00004000; 28211382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_PARENT = 0x00008000; 28311382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_THREAD = 0x00010000; 28411382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWNS = 0x00020000; 28511382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_SYSVSEM = 0x00040000; 28611382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_SETTLS = 0x00080000; 28711382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_PARENT_SETTID = 0x00100000; 28811382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_CHILD_CLEARTID = 0x00200000; 28911382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_DETACHED = 0x00400000; 29011382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_UNTRACED = 0x00800000; 29111382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_CHILD_SETTID = 0x01000000; 29211382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWUTS = 0x04000000; 29311382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWIPC = 0x08000000; 29411382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWUSER = 0x10000000; 29511382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWPID = 0x20000000; 29611382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_NEWNET = 0x40000000; 29711382Sbrandon.potter@amd.com static const unsigned TGT_CLONE_IO = 0x80000000; 29813570Sbrandon.potter@amd.com 29913570Sbrandon.potter@amd.com // linux-3.13-src/include/uapi/linux/wait.h 30013570Sbrandon.potter@amd.com static const unsigned TGT_WNOHANG = 0x00000001; 30113570Sbrandon.potter@amd.com static const unsigned TGT_WUNTRACED = 0x00000002; 30213570Sbrandon.potter@amd.com static const unsigned TGT_WSTOPPED = TGT_WUNTRACED; 30313570Sbrandon.potter@amd.com static const unsigned TGT_WEXITED = 0x00000004; 30413570Sbrandon.potter@amd.com static const unsigned TGT_WCONTINUED = 0x00000008; 30513570Sbrandon.potter@amd.com static const unsigned TGT_WNOWAIT = 0x01000000; 3062093SN/A}; // class Linux 3072093SN/A 308451SN/A#endif // __LINUX_HH__ 309