linux.hh revision 6684
14120Sgblack@eecs.umich.edu/*
24120Sgblack@eecs.umich.edu * Copyright (c) 2004-2009 The Regents of The University of Michigan
34120Sgblack@eecs.umich.edu * All rights reserved.
44120Sgblack@eecs.umich.edu *
54120Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
64120Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
74120Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
84120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
94120Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
104120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
114120Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
124120Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
134120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
144120Sgblack@eecs.umich.edu * this software without specific prior written permission.
154120Sgblack@eecs.umich.edu *
164120Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174120Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184120Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194120Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204120Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214120Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234120Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274120Sgblack@eecs.umich.edu *
284120Sgblack@eecs.umich.edu * Authors: Ali Saidi
294120Sgblack@eecs.umich.edu */
304120Sgblack@eecs.umich.edu
314120Sgblack@eecs.umich.edu#ifndef __LINUX_HH__
324120Sgblack@eecs.umich.edu#define __LINUX_HH__
334120Sgblack@eecs.umich.edu
344120Sgblack@eecs.umich.edu#include "base/types.hh"
354120Sgblack@eecs.umich.edu#include "config/full_system.hh"
364120Sgblack@eecs.umich.edu
374120Sgblack@eecs.umich.edu#if FULL_SYSTEM
384120Sgblack@eecs.umich.edu
394120Sgblack@eecs.umich.educlass Linux {};
404120Sgblack@eecs.umich.edu
414120Sgblack@eecs.umich.edu#else //!FULL_SYSTEM
424120Sgblack@eecs.umich.edu
434120Sgblack@eecs.umich.edu#include <string>
444120Sgblack@eecs.umich.edu
454120Sgblack@eecs.umich.edu#include "kern/operatingsystem.hh"
464120Sgblack@eecs.umich.edu
474120Sgblack@eecs.umich.educlass ThreadContext;
484120Sgblack@eecs.umich.educlass LiveProcess;
494120Sgblack@eecs.umich.edu
504120Sgblack@eecs.umich.edu///
514120Sgblack@eecs.umich.edu/// This class encapsulates the types, structures, constants,
524120Sgblack@eecs.umich.edu/// functions, and syscall-number mappings specific to the Alpha Linux
534120Sgblack@eecs.umich.edu/// syscall interface.
544120Sgblack@eecs.umich.edu///
554120Sgblack@eecs.umich.educlass Linux : public OperatingSystem
564120Sgblack@eecs.umich.edu{
574120Sgblack@eecs.umich.edu
584120Sgblack@eecs.umich.edu  public:
594120Sgblack@eecs.umich.edu
604120Sgblack@eecs.umich.edu    //@{
615857Sgblack@eecs.umich.edu    /// Basic Linux types.
624139Sgblack@eecs.umich.edu    typedef uint64_t size_t;
634135Sgblack@eecs.umich.edu    typedef uint64_t off_t;
646023Snate@binkert.org    typedef int64_t time_t;
654120Sgblack@eecs.umich.edu    typedef int64_t clock_t;
665909Sgblack@eecs.umich.edu    typedef uint32_t uid_t;
675909Sgblack@eecs.umich.edu    typedef uint32_t gid_t;
684120Sgblack@eecs.umich.edu    //@}
694120Sgblack@eecs.umich.edu
705114Sgblack@eecs.umich.edu    /// Stat buffer.  Note that we can't call it 'stat' since that
715114Sgblack@eecs.umich.edu    /// gets #defined to something else on some systems. This type
724135Sgblack@eecs.umich.edu    /// can be specialized by architecture specific "Linux" classes
734365Sgblack@eecs.umich.edu    typedef struct {
745114Sgblack@eecs.umich.edu        uint32_t        st_dev;         //!< device
755114Sgblack@eecs.umich.edu        uint32_t        st_ino;         //!< inode
765851Sgblack@eecs.umich.edu        uint32_t        st_mode;        //!< mode
775139Sgblack@eecs.umich.edu        uint32_t        st_nlink;       //!< link count
785114Sgblack@eecs.umich.edu        uint32_t        st_uid;         //!< owner's user ID
795139Sgblack@eecs.umich.edu        uint32_t        st_gid;         //!< owner's group ID
806009Snate@binkert.org        uint32_t        st_rdev;        //!< device number
816009Snate@binkert.org        int32_t         _pad1;          //!< for alignment
826009Snate@binkert.org        int64_t         st_size;        //!< file size in bytes
835114Sgblack@eecs.umich.edu        uint64_t        st_atimeX;      //!< time of last access
845114Sgblack@eecs.umich.edu        uint64_t        st_mtimeX;      //!< time of last modification
855114Sgblack@eecs.umich.edu        uint64_t        st_ctimeX;      //!< time of last status change
864729Sgblack@eecs.umich.edu        uint32_t        st_blksize;     //!< optimal I/O block size
874365Sgblack@eecs.umich.edu        int32_t         st_blocks;      //!< number of blocks allocated
885114Sgblack@eecs.umich.edu        uint32_t        st_flags;       //!< flags
894365Sgblack@eecs.umich.edu        uint32_t        st_gen;         //!< unknown
904365Sgblack@eecs.umich.edu    } tgt_stat;
915114Sgblack@eecs.umich.edu
925114Sgblack@eecs.umich.edu    // same for stat64
935114Sgblack@eecs.umich.edu    typedef struct {
945114Sgblack@eecs.umich.edu        uint64_t        st_dev;
955114Sgblack@eecs.umich.edu        uint64_t        st_ino;
965114Sgblack@eecs.umich.edu        uint64_t        st_rdev;
975114Sgblack@eecs.umich.edu        int64_t         st_size;
985114Sgblack@eecs.umich.edu        uint64_t        st_blocks;
995114Sgblack@eecs.umich.edu
1005684Sgblack@eecs.umich.edu        uint32_t        st_mode;
1015858Sgblack@eecs.umich.edu        uint32_t        st_uid;
1025684Sgblack@eecs.umich.edu        uint32_t        st_gid;
1035858Sgblack@eecs.umich.edu        uint32_t        st_blksize;
1045684Sgblack@eecs.umich.edu        uint32_t        st_nlink;
1055858Sgblack@eecs.umich.edu        uint32_t        __pad0;
1065858Sgblack@eecs.umich.edu
1075858Sgblack@eecs.umich.edu        uint64_t        st_atimeX;
1085909Sgblack@eecs.umich.edu        uint64_t        st_atime_nsec;
1095909Sgblack@eecs.umich.edu        uint64_t        st_mtimeX;
1105858Sgblack@eecs.umich.edu        uint64_t        st_mtime_nsec;
1115114Sgblack@eecs.umich.edu        uint64_t        st_ctimeX;
1125114Sgblack@eecs.umich.edu        uint64_t        st_ctime_nsec;
1135114Sgblack@eecs.umich.edu        int64_t         ___unused[3];
1145114Sgblack@eecs.umich.edu    } tgt_stat64;
1155114Sgblack@eecs.umich.edu
1165114Sgblack@eecs.umich.edu    /// Length of strings in struct utsname (plus 1 for null char).
1175114Sgblack@eecs.umich.edu    static const int _SYS_NMLN = 65;
1185139Sgblack@eecs.umich.edu
1196009Snate@binkert.org    /// Interface struct for uname().
1206009Snate@binkert.org    struct utsname {
1215114Sgblack@eecs.umich.edu        char sysname[_SYS_NMLN];        //!< System name.
1225114Sgblack@eecs.umich.edu        char nodename[_SYS_NMLN];       //!< Node name.
1235114Sgblack@eecs.umich.edu        char release[_SYS_NMLN];        //!< OS release.
1245114Sgblack@eecs.umich.edu        char version[_SYS_NMLN];        //!< OS version.
1255114Sgblack@eecs.umich.edu        char machine[_SYS_NMLN];        //!< Machine type.
1265114Sgblack@eecs.umich.edu    };
1275114Sgblack@eecs.umich.edu
1285114Sgblack@eecs.umich.edu    /// Limit struct for getrlimit/setrlimit.
1295139Sgblack@eecs.umich.edu    struct rlimit {
1306009Snate@binkert.org        uint64_t  rlim_cur;     //!< soft limit
1316009Snate@binkert.org        uint64_t  rlim_max;     //!< hard limit
1325114Sgblack@eecs.umich.edu    };
1335114Sgblack@eecs.umich.edu
1345114Sgblack@eecs.umich.edu    /// For gettimeofday().
1355124Sgblack@eecs.umich.edu    struct timeval {
1365114Sgblack@eecs.umich.edu        int64_t tv_sec;         //!< seconds
1375114Sgblack@eecs.umich.edu        int64_t tv_usec;        //!< microseconds
1385114Sgblack@eecs.umich.edu    };
1395114Sgblack@eecs.umich.edu
1405114Sgblack@eecs.umich.edu    /// Clock ticks per second, for times().
1415114Sgblack@eecs.umich.edu    static const int _SC_CLK_TCK = 100;
1425114Sgblack@eecs.umich.edu
1435139Sgblack@eecs.umich.edu    /// For times().
1446009Snate@binkert.org    struct tms {
1456009Snate@binkert.org        int64_t tms_utime;      //!< user time
1465114Sgblack@eecs.umich.edu        int64_t tms_stime;      //!< system time
1475114Sgblack@eecs.umich.edu        int64_t tms_cutime;     //!< user time of children
1485114Sgblack@eecs.umich.edu        int64_t tms_cstime;     //!< system time of children
1495124Sgblack@eecs.umich.edu    };
1505114Sgblack@eecs.umich.edu
1515114Sgblack@eecs.umich.edu    // For writev/readv
1525114Sgblack@eecs.umich.edu    struct tgt_iovec {
1535114Sgblack@eecs.umich.edu        uint64_t iov_base; // void *
1545114Sgblack@eecs.umich.edu        uint64_t iov_len;
1555114Sgblack@eecs.umich.edu    };
1565114Sgblack@eecs.umich.edu
1575851Sgblack@eecs.umich.edu
1586009Snate@binkert.org    /// For getrusage().
1596009Snate@binkert.org    struct rusage {
1605114Sgblack@eecs.umich.edu        struct timeval ru_utime;        //!< user time used
1614135Sgblack@eecs.umich.edu        struct timeval ru_stime;        //!< system time used
1624150Sgblack@eecs.umich.edu        int64_t ru_maxrss;              //!< max rss
1634365Sgblack@eecs.umich.edu        int64_t ru_ixrss;               //!< integral shared memory size
1644365Sgblack@eecs.umich.edu        int64_t ru_idrss;               //!< integral unshared data "
1654365Sgblack@eecs.umich.edu        int64_t ru_isrss;               //!< integral unshared stack "
1664729Sgblack@eecs.umich.edu        int64_t ru_minflt;              //!< page reclaims - total vmfaults
1674365Sgblack@eecs.umich.edu        int64_t ru_majflt;              //!< page faults
1684365Sgblack@eecs.umich.edu        int64_t ru_nswap;               //!< swaps
1694365Sgblack@eecs.umich.edu        int64_t ru_inblock;             //!< block input operations
1704365Sgblack@eecs.umich.edu        int64_t ru_oublock;             //!< block output operations
1714365Sgblack@eecs.umich.edu        int64_t ru_msgsnd;              //!< messages sent
1724365Sgblack@eecs.umich.edu        int64_t ru_msgrcv;              //!< messages received
1734365Sgblack@eecs.umich.edu        int64_t ru_nsignals;            //!< signals received
1744365Sgblack@eecs.umich.edu        int64_t ru_nvcsw;               //!< voluntary context switches
1754365Sgblack@eecs.umich.edu        int64_t ru_nivcsw;              //!< involuntary "
1764365Sgblack@eecs.umich.edu    };
1774150Sgblack@eecs.umich.edu
1784150Sgblack@eecs.umich.edu    static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
1794150Sgblack@eecs.umich.edu    static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
1804150Sgblack@eecs.umich.edu
1815114Sgblack@eecs.umich.edu};  // class Linux
1825114Sgblack@eecs.umich.edu
1835114Sgblack@eecs.umich.edu
1845114Sgblack@eecs.umich.edu#endif // FULL_SYSTEM
1855114Sgblack@eecs.umich.edu
1865114Sgblack@eecs.umich.edu#endif // __LINUX_HH__
1875114Sgblack@eecs.umich.edu