linux.hh revision 6215
16700Snate@binkert.org/*
26700Snate@binkert.org * Copyright (c) 2004-2009 The Regents of The University of Michigan
36700Snate@binkert.org * All rights reserved.
46700Snate@binkert.org *
56700Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66700Snate@binkert.org * modification, are permitted provided that the following conditions are
76700Snate@binkert.org * met: redistributions of source code must retain the above copyright
86700Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96700Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106700Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116700Snate@binkert.org * documentation and/or other materials provided with the distribution;
126700Snate@binkert.org * neither the name of the copyright holders nor the names of its
136700Snate@binkert.org * contributors may be used to endorse or promote products derived from
146700Snate@binkert.org * this software without specific prior written permission.
156700Snate@binkert.org *
166700Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176700Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186700Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196700Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206700Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216700Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226700Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236700Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246700Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256700Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266700Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276700Snate@binkert.org *
286285Snate@binkert.org * Authors: Ali Saidi
297805Snilay@cs.wisc.edu */
306285Snate@binkert.org
316285Snate@binkert.org#ifndef __LINUX_HH__
326881SBrad.Beckmann@amd.com#define __LINUX_HH__
336285Snate@binkert.org
346876Ssteve.reinhardt@amd.com#include "base/types.hh"
356876Ssteve.reinhardt@amd.com#include "config/full_system.hh"
366285Snate@binkert.org
376876Ssteve.reinhardt@amd.com#if FULL_SYSTEM
386876Ssteve.reinhardt@amd.com
396876Ssteve.reinhardt@amd.comclass Linux {};
406876Ssteve.reinhardt@amd.com
416876Ssteve.reinhardt@amd.com#else //!FULL_SYSTEM
426876Ssteve.reinhardt@amd.com
436876Ssteve.reinhardt@amd.com#include <string>
446876Ssteve.reinhardt@amd.com
456881SBrad.Beckmann@amd.com#include "kern/operatingsystem.hh"
466881SBrad.Beckmann@amd.com
477054Snate@binkert.orgclass ThreadContext;
486881SBrad.Beckmann@amd.comclass LiveProcess;
496881SBrad.Beckmann@amd.com
506876Ssteve.reinhardt@amd.com///
516876Ssteve.reinhardt@amd.com/// This class encapsulates the types, structures, constants,
526881SBrad.Beckmann@amd.com/// functions, and syscall-number mappings specific to the Alpha Linux
536881SBrad.Beckmann@amd.com/// syscall interface.
546881SBrad.Beckmann@amd.com///
556285Snate@binkert.orgclass Linux : public OperatingSystem
566285Snate@binkert.org{
577054Snate@binkert.org
587054Snate@binkert.org  public:
596285Snate@binkert.org
607054Snate@binkert.org    //@{
616285Snate@binkert.org    /// Basic Linux types.
626493STushar.Krishna@amd.com    typedef uint64_t size_t;
637054Snate@binkert.org    typedef uint64_t off_t;
647054Snate@binkert.org    typedef int64_t time_t;
656493STushar.Krishna@amd.com    typedef uint32_t uid_t;
667054Snate@binkert.org    typedef uint32_t gid_t;
677054Snate@binkert.org    //@}
687805Snilay@cs.wisc.edu
697054Snate@binkert.org    /// Stat buffer.  Note that we can't call it 'stat' since that
707054Snate@binkert.org    /// gets #defined to something else on some systems. This type
717054Snate@binkert.org    /// can be specialized by architecture specific "Linux" classes
727054Snate@binkert.org    typedef struct {
737054Snate@binkert.org        uint32_t        st_dev;         //!< device
747054Snate@binkert.org        uint32_t        st_ino;         //!< inode
757548SBrad.Beckmann@amd.com        uint32_t        st_mode;        //!< mode
767904SBrad.Beckmann@amd.com        uint32_t        st_nlink;       //!< link count
777054Snate@binkert.org        uint32_t        st_uid;         //!< owner's user ID
787054Snate@binkert.org        uint32_t        st_gid;         //!< owner's group ID
797054Snate@binkert.org        uint32_t        st_rdev;        //!< device number
807054Snate@binkert.org        int32_t         _pad1;          //!< for alignment
817054Snate@binkert.org        int64_t         st_size;        //!< file size in bytes
827054Snate@binkert.org        uint64_t        st_atimeX;      //!< time of last access
837054Snate@binkert.org        uint64_t        st_mtimeX;      //!< time of last modification
847054Snate@binkert.org        uint64_t        st_ctimeX;      //!< time of last status change
857054Snate@binkert.org        uint32_t        st_blksize;     //!< optimal I/O block size
867054Snate@binkert.org        int32_t         st_blocks;      //!< number of blocks allocated
877054Snate@binkert.org        uint32_t        st_flags;       //!< flags
887054Snate@binkert.org        uint32_t        st_gen;         //!< unknown
897054Snate@binkert.org    } tgt_stat;
907805Snilay@cs.wisc.edu
917054Snate@binkert.org    // same for stat64
927054Snate@binkert.org    typedef struct {
936493STushar.Krishna@amd.com        uint64_t        st_dev;
947054Snate@binkert.org        uint64_t        st_ino;
957454Snate@binkert.org        uint64_t        st_rdev;
967054Snate@binkert.org        int64_t         st_size;
977054Snate@binkert.org        uint64_t        st_blocks;
987054Snate@binkert.org
997054Snate@binkert.org        uint32_t        st_mode;
100        uint32_t        st_uid;
101        uint32_t        st_gid;
102        uint32_t        st_blksize;
103        uint32_t        st_nlink;
104        uint32_t        __pad0;
105
106        uint64_t        st_atimeX;
107        uint64_t        st_atime_nsec;
108        uint64_t        st_mtimeX;
109        uint64_t        st_mtime_nsec;
110        uint64_t        st_ctimeX;
111        uint64_t        st_ctime_nsec;
112        int64_t         ___unused[3];
113    } tgt_stat64;
114
115    /// Length of strings in struct utsname (plus 1 for null char).
116    static const int _SYS_NMLN = 65;
117
118    /// Interface struct for uname().
119    struct utsname {
120        char sysname[_SYS_NMLN];        //!< System name.
121        char nodename[_SYS_NMLN];       //!< Node name.
122        char release[_SYS_NMLN];        //!< OS release.
123        char version[_SYS_NMLN];        //!< OS version.
124        char machine[_SYS_NMLN];        //!< Machine type.
125    };
126
127    /// Limit struct for getrlimit/setrlimit.
128    struct rlimit {
129        uint64_t  rlim_cur;     //!< soft limit
130        uint64_t  rlim_max;     //!< hard limit
131    };
132
133    /// For gettimeofday().
134    struct timeval {
135        int64_t tv_sec;         //!< seconds
136        int64_t tv_usec;        //!< microseconds
137    };
138
139    // For writev/readv
140    struct tgt_iovec {
141        uint64_t iov_base; // void *
142        uint64_t iov_len;
143    };
144
145
146    /// For getrusage().
147    struct rusage {
148        struct timeval ru_utime;        //!< user time used
149        struct timeval ru_stime;        //!< system time used
150        int64_t ru_maxrss;              //!< max rss
151        int64_t ru_ixrss;               //!< integral shared memory size
152        int64_t ru_idrss;               //!< integral unshared data "
153        int64_t ru_isrss;               //!< integral unshared stack "
154        int64_t ru_minflt;              //!< page reclaims - total vmfaults
155        int64_t ru_majflt;              //!< page faults
156        int64_t ru_nswap;               //!< swaps
157        int64_t ru_inblock;             //!< block input operations
158        int64_t ru_oublock;             //!< block output operations
159        int64_t ru_msgsnd;              //!< messages sent
160        int64_t ru_msgrcv;              //!< messages received
161        int64_t ru_nsignals;            //!< signals received
162        int64_t ru_nvcsw;               //!< voluntary context switches
163        int64_t ru_nivcsw;              //!< involuntary "
164    };
165
166    static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
167    static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
168
169};  // class Linux
170
171
172#endif // FULL_SYSTEM
173
174#endif // __LINUX_HH__
175