linux.hh revision 11907
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
1569141Smarc.orr@gmail.com    //@{
1579141Smarc.orr@gmail.com    /// ioctl() command codes.
1589141Smarc.orr@gmail.com    static const unsigned TGT_TCGETS     = 0x5401;
1599141Smarc.orr@gmail.com    static const unsigned TGT_TCGETA     = 0x5405;
1609141Smarc.orr@gmail.com    static const unsigned TGT_TCSETAW    = 0x5407;
1619141Smarc.orr@gmail.com    static const unsigned TGT_FIONREAD   = 0x541B;
1629141Smarc.orr@gmail.com    //@}
1639141Smarc.orr@gmail.com
1649141Smarc.orr@gmail.com    /// Return true for the ioctl codes for which we return ENOTTY
1659141Smarc.orr@gmail.com    /// *without* printing a warning, since we know that ENOTTY is the
1669141Smarc.orr@gmail.com    /// correct thing to return (and not just a sign that we don't
1679141Smarc.orr@gmail.com    /// recognize the ioctl code.
1689141Smarc.orr@gmail.com    static bool
1699141Smarc.orr@gmail.com    isTtyReq(unsigned req)
1709141Smarc.orr@gmail.com    {
1719141Smarc.orr@gmail.com        switch (req) {
1729141Smarc.orr@gmail.com          case TGT_FIONREAD:
1739141Smarc.orr@gmail.com          case TGT_TCSETAW:
1749141Smarc.orr@gmail.com          case TGT_TCGETS:
1759141Smarc.orr@gmail.com          case TGT_TCGETA:
1769141Smarc.orr@gmail.com            return true;
1779141Smarc.orr@gmail.com          default:
1789141Smarc.orr@gmail.com            return false;
1799141Smarc.orr@gmail.com        }
1809141Smarc.orr@gmail.com    }
1819141Smarc.orr@gmail.com
1822093SN/A
1839146Smarc.orr@gmail.com    /// Resource constants for getrlimit().
1849146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_CPU = 0;
1859146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_FSIZE = 1;
1869146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_DATA = 2;
1879146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_STACK = 3;
1889146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_CORE = 4;
1899146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_RSS = 5;
1909146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_NPROC = 6;
1919146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_NOFILE = 7;
1929146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_MEMLOCK = 8;
1939146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_AS = 9;
1949146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_LOCKS = 10;
1959146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_SIGPENDING = 11;
1969146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_MSGQUEUE = 12;
1979146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_NICE = 13;
1989146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_RTPRIO = 14;
1999146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_RTTIME = 15;
2009146Smarc.orr@gmail.com    static const unsigned TGT_RLIM_NLIMITS = 16;
2019146Smarc.orr@gmail.com
2022093SN/A    /// For getrusage().
2039146Smarc.orr@gmail.com    static const int TGT_RUSAGE_SELF     = 0;
2049146Smarc.orr@gmail.com    static const int TGT_RUSAGE_CHILDREN = -1;
2059146Smarc.orr@gmail.com    static const int TGT_RUSAGE_BOTH     = -2;
2069146Smarc.orr@gmail.com
2072093SN/A    struct rusage {
2085543Ssaidi@eecs.umich.edu        struct timeval ru_utime;        //!< user time used
2095543Ssaidi@eecs.umich.edu        struct timeval ru_stime;        //!< system time used
2105543Ssaidi@eecs.umich.edu        int64_t ru_maxrss;              //!< max rss
2115543Ssaidi@eecs.umich.edu        int64_t ru_ixrss;               //!< integral shared memory size
2125543Ssaidi@eecs.umich.edu        int64_t ru_idrss;               //!< integral unshared data "
2135543Ssaidi@eecs.umich.edu        int64_t ru_isrss;               //!< integral unshared stack "
2145543Ssaidi@eecs.umich.edu        int64_t ru_minflt;              //!< page reclaims - total vmfaults
2155543Ssaidi@eecs.umich.edu        int64_t ru_majflt;              //!< page faults
2165543Ssaidi@eecs.umich.edu        int64_t ru_nswap;               //!< swaps
2175543Ssaidi@eecs.umich.edu        int64_t ru_inblock;             //!< block input operations
2185543Ssaidi@eecs.umich.edu        int64_t ru_oublock;             //!< block output operations
2195543Ssaidi@eecs.umich.edu        int64_t ru_msgsnd;              //!< messages sent
2205543Ssaidi@eecs.umich.edu        int64_t ru_msgrcv;              //!< messages received
2215543Ssaidi@eecs.umich.edu        int64_t ru_nsignals;            //!< signals received
2225543Ssaidi@eecs.umich.edu        int64_t ru_nvcsw;               //!< voluntary context switches
2235543Ssaidi@eecs.umich.edu        int64_t ru_nivcsw;              //!< involuntary "
2242093SN/A    };
2252093SN/A
22611851Sbrandon.potter@amd.com    static int openSpecialFile(std::string path, Process *process,
22711851Sbrandon.potter@amd.com                               ThreadContext *tc);
22811851Sbrandon.potter@amd.com    static std::string procMeminfo(Process *process, ThreadContext *tc);
22911907SBrandon.Potter@amd.com    static std::string etcPasswd(Process *process, ThreadContext *tc);
2305795Ssaidi@eecs.umich.edu
2319112Smarc.orr@gmail.com    // For futex system call
2329112Smarc.orr@gmail.com    static const unsigned TGT_FUTEX_WAIT  = 0;
2339112Smarc.orr@gmail.com    static const unsigned TGT_FUTEX_WAKE  = 1;
2349112Smarc.orr@gmail.com    static const unsigned TGT_EAGAIN      = 11;
2359112Smarc.orr@gmail.com    static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN;
2369238Slluc.alvarez@bsc.es    static const unsigned TGT_FUTEX_PRIVATE_FLAG = 128;
2379112Smarc.orr@gmail.com
23810027SChris.Adeniyi-Jones@arm.com    // for *at syscalls
23910027SChris.Adeniyi-Jones@arm.com    static const int TGT_AT_FDCWD   = -100;
24010027SChris.Adeniyi-Jones@arm.com
24110027SChris.Adeniyi-Jones@arm.com    // for MREMAP
24210027SChris.Adeniyi-Jones@arm.com    static const unsigned TGT_MREMAP_MAYMOVE    = 0x1;
24310027SChris.Adeniyi-Jones@arm.com    static const unsigned TGT_MREMAP_FIXED      = 0x2;
24411382Sbrandon.potter@amd.com
24511382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_VM              = 0x00000100;
24611382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_FS              = 0x00000200;
24711382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_FILES           = 0x00000400;
24811382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_SIGHAND         = 0x00000800;
24911382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_PTRACE          = 0x00002000;
25011382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_VFORK           = 0x00004000;
25111382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_PARENT          = 0x00008000;
25211382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_THREAD          = 0x00010000;
25311382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWNS           = 0x00020000;
25411382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_SYSVSEM         = 0x00040000;
25511382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_SETTLS          = 0x00080000;
25611382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_PARENT_SETTID   = 0x00100000;
25711382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_CHILD_CLEARTID  = 0x00200000;
25811382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_DETACHED        = 0x00400000;
25911382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_UNTRACED        = 0x00800000;
26011382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_CHILD_SETTID    = 0x01000000;
26111382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWUTS          = 0x04000000;
26211382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWIPC          = 0x08000000;
26311382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWUSER         = 0x10000000;
26411382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWPID          = 0x20000000;
26511382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_NEWNET          = 0x40000000;
26611382Sbrandon.potter@amd.com    static const unsigned TGT_CLONE_IO              = 0x80000000;
2672093SN/A};  // class Linux
2682093SN/A
269451SN/A#endif // __LINUX_HH__
270