linux.hh revision 10027
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" 392423SN/A 405795Ssaidi@eecs.umich.educlass ThreadContext; 415795Ssaidi@eecs.umich.educlass LiveProcess; 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 1336683Stjones1@inf.ed.ac.uk /// Clock ticks per second, for times(). 1346744SAli.Saidi@arm.com static const int M5_SC_CLK_TCK = 100; 1356683Stjones1@inf.ed.ac.uk 1366683Stjones1@inf.ed.ac.uk /// For times(). 1376683Stjones1@inf.ed.ac.uk struct tms { 1386683Stjones1@inf.ed.ac.uk int64_t tms_utime; //!< user time 1396683Stjones1@inf.ed.ac.uk int64_t tms_stime; //!< system time 1406683Stjones1@inf.ed.ac.uk int64_t tms_cutime; //!< user time of children 1416683Stjones1@inf.ed.ac.uk int64_t tms_cstime; //!< system time of children 1426683Stjones1@inf.ed.ac.uk }; 1436683Stjones1@inf.ed.ac.uk 1442093SN/A // For writev/readv 1452093SN/A struct tgt_iovec { 1462093SN/A uint64_t iov_base; // void * 1472093SN/A uint64_t iov_len; 1482093SN/A }; 1492093SN/A 1509141Smarc.orr@gmail.com //@{ 1519141Smarc.orr@gmail.com /// ioctl() command codes. 1529141Smarc.orr@gmail.com static const unsigned TGT_TCGETS = 0x5401; 1539141Smarc.orr@gmail.com static const unsigned TGT_TCGETA = 0x5405; 1549141Smarc.orr@gmail.com static const unsigned TGT_TCSETAW = 0x5407; 1559141Smarc.orr@gmail.com static const unsigned TGT_FIONREAD = 0x541B; 1569141Smarc.orr@gmail.com //@} 1579141Smarc.orr@gmail.com 1589141Smarc.orr@gmail.com /// Return true for the ioctl codes for which we return ENOTTY 1599141Smarc.orr@gmail.com /// *without* printing a warning, since we know that ENOTTY is the 1609141Smarc.orr@gmail.com /// correct thing to return (and not just a sign that we don't 1619141Smarc.orr@gmail.com /// recognize the ioctl code. 1629141Smarc.orr@gmail.com static bool 1639141Smarc.orr@gmail.com isTtyReq(unsigned req) 1649141Smarc.orr@gmail.com { 1659141Smarc.orr@gmail.com switch (req) { 1669141Smarc.orr@gmail.com case TGT_FIONREAD: 1679141Smarc.orr@gmail.com case TGT_TCSETAW: 1689141Smarc.orr@gmail.com case TGT_TCGETS: 1699141Smarc.orr@gmail.com case TGT_TCGETA: 1709141Smarc.orr@gmail.com return true; 1719141Smarc.orr@gmail.com default: 1729141Smarc.orr@gmail.com return false; 1739141Smarc.orr@gmail.com } 1749141Smarc.orr@gmail.com } 1759141Smarc.orr@gmail.com 1762093SN/A 1779146Smarc.orr@gmail.com /// Resource constants for getrlimit(). 1789146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_CPU = 0; 1799146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_FSIZE = 1; 1809146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_DATA = 2; 1819146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_STACK = 3; 1829146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_CORE = 4; 1839146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RSS = 5; 1849146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NPROC = 6; 1859146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NOFILE = 7; 1869146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_MEMLOCK = 8; 1879146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_AS = 9; 1889146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_LOCKS = 10; 1899146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_SIGPENDING = 11; 1909146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_MSGQUEUE = 12; 1919146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_NICE = 13; 1929146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RTPRIO = 14; 1939146Smarc.orr@gmail.com static const unsigned TGT_RLIMIT_RTTIME = 15; 1949146Smarc.orr@gmail.com static const unsigned TGT_RLIM_NLIMITS = 16; 1959146Smarc.orr@gmail.com 1962093SN/A /// For getrusage(). 1979146Smarc.orr@gmail.com static const int TGT_RUSAGE_SELF = 0; 1989146Smarc.orr@gmail.com static const int TGT_RUSAGE_CHILDREN = -1; 1999146Smarc.orr@gmail.com static const int TGT_RUSAGE_BOTH = -2; 2009146Smarc.orr@gmail.com 2012093SN/A struct rusage { 2025543Ssaidi@eecs.umich.edu struct timeval ru_utime; //!< user time used 2035543Ssaidi@eecs.umich.edu struct timeval ru_stime; //!< system time used 2045543Ssaidi@eecs.umich.edu int64_t ru_maxrss; //!< max rss 2055543Ssaidi@eecs.umich.edu int64_t ru_ixrss; //!< integral shared memory size 2065543Ssaidi@eecs.umich.edu int64_t ru_idrss; //!< integral unshared data " 2075543Ssaidi@eecs.umich.edu int64_t ru_isrss; //!< integral unshared stack " 2085543Ssaidi@eecs.umich.edu int64_t ru_minflt; //!< page reclaims - total vmfaults 2095543Ssaidi@eecs.umich.edu int64_t ru_majflt; //!< page faults 2105543Ssaidi@eecs.umich.edu int64_t ru_nswap; //!< swaps 2115543Ssaidi@eecs.umich.edu int64_t ru_inblock; //!< block input operations 2125543Ssaidi@eecs.umich.edu int64_t ru_oublock; //!< block output operations 2135543Ssaidi@eecs.umich.edu int64_t ru_msgsnd; //!< messages sent 2145543Ssaidi@eecs.umich.edu int64_t ru_msgrcv; //!< messages received 2155543Ssaidi@eecs.umich.edu int64_t ru_nsignals; //!< signals received 2165543Ssaidi@eecs.umich.edu int64_t ru_nvcsw; //!< voluntary context switches 2175543Ssaidi@eecs.umich.edu int64_t ru_nivcsw; //!< involuntary " 2182093SN/A }; 2192093SN/A 2205795Ssaidi@eecs.umich.edu static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc); 2215795Ssaidi@eecs.umich.edu static std::string procMeminfo(LiveProcess *process, ThreadContext *tc); 2225795Ssaidi@eecs.umich.edu 2239112Smarc.orr@gmail.com // For futex system call 2249112Smarc.orr@gmail.com static const unsigned TGT_FUTEX_WAIT = 0; 2259112Smarc.orr@gmail.com static const unsigned TGT_FUTEX_WAKE = 1; 2269112Smarc.orr@gmail.com static const unsigned TGT_EAGAIN = 11; 2279112Smarc.orr@gmail.com static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN; 2289238Slluc.alvarez@bsc.es static const unsigned TGT_FUTEX_PRIVATE_FLAG = 128; 2299112Smarc.orr@gmail.com 23010027SChris.Adeniyi-Jones@arm.com // for *at syscalls 23110027SChris.Adeniyi-Jones@arm.com static const int TGT_AT_FDCWD = -100; 23210027SChris.Adeniyi-Jones@arm.com 23310027SChris.Adeniyi-Jones@arm.com // for MREMAP 23410027SChris.Adeniyi-Jones@arm.com static const unsigned TGT_MREMAP_MAYMOVE = 0x1; 23510027SChris.Adeniyi-Jones@arm.com static const unsigned TGT_MREMAP_FIXED = 0x2; 2362093SN/A}; // class Linux 2372093SN/A 238451SN/A#endif // __LINUX_HH__ 239