operatingsystem.hh revision 6215
1720SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3720SN/A * All rights reserved.
4720SN/A *
5720SN/A * Redistribution and use in source and binary forms, with or without
6720SN/A * modification, are permitted provided that the following conditions are
7720SN/A * met: redistributions of source code must retain the above copyright
8720SN/A * notice, this list of conditions and the following disclaimer;
9720SN/A * redistributions in binary form must reproduce the above copyright
10720SN/A * notice, this list of conditions and the following disclaimer in the
11720SN/A * documentation and/or other materials provided with the distribution;
12720SN/A * neither the name of the copyright holders nor the names of its
13720SN/A * contributors may be used to endorse or promote products derived from
14720SN/A * this software without specific prior written permission.
15720SN/A *
16720SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17720SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18720SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19720SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20720SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21720SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22720SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23720SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24720SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25720SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26720SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
292665Ssaidi@eecs.umich.edu */
30720SN/A
31720SN/A#ifndef __KERN_OPERATINGSYSTEM_HH__
322518SN/A#define __KERN_OPERATINGSYSTEM_HH__
332518SN/A
341070SN/A#include "base/types.hh"
352518SN/A#include "config/full_system.hh"
362518SN/A
37720SN/A#if FULL_SYSTEM
382107SN/A
392107SN/Aclass OperatingSystem {};
40720SN/A
41720SN/A#else //!FULL_SYSTEM
42720SN/A#include <string>
432190SN/A
44720SN/Aclass LiveProcess;
45720SN/Aclass ThreadContext;
462190SN/A
47720SN/A/// This struct is used to build an target-OS-dependent table that
482190SN/A/// maps the target's open() flags to the host open() flags.
492190SN/Astruct OpenFlagTransTable {
502518SN/A    int tgtFlag;        //!< Target system flag value.
512190SN/A    int hostFlag;       //!< Corresponding host system flag value.
52720SN/A};
532190SN/A
54720SN/A
552518SN/A///
56720SN/A/// This class encapsulates the types, structures, constants,
57720SN/A/// functions, and syscall-number mappings specific to an operating system
58720SN/A/// syscall interface.
591885SN/A///
601885SN/Aclass OperatingSystem {
611885SN/A
62720SN/A  public:
63720SN/A
64720SN/A    /// Stat buffer.  Note that we can't call it 'stat' since that
65720SN/A    /// gets #defined to something else on some systems. This type
66720SN/A    /// can be specialized by architecture specific "Linux" classes
67720SN/A    typedef void tgt_stat;
68720SN/A
69720SN/A    // same for stat64
70720SN/A    typedef void tgt_stat64;
712190SN/A
721070SN/A    /// Length of strings in struct utsname (plus 1 for null char).
73720SN/A    static const int _SYS_NMLN = 65;
741070SN/A
751070SN/A    /// Interface struct for uname().
761070SN/A    typedef struct {
772190SN/A        char sysname[_SYS_NMLN];        //!< System name.
782190SN/A        char nodename[_SYS_NMLN];       //!< Node name.
791096SN/A        char release[_SYS_NMLN];        //!< OS release.
80720SN/A        char version[_SYS_NMLN];        //!< OS version.
811082SN/A        char machine[_SYS_NMLN];        //!< Machine type.
821082SN/A    } utsname;
831082SN/A
841082SN/A    /// Limit struct for getrlimit/setrlimit.
852190SN/A    typedef struct {
861082SN/A        uint64_t  rlim_cur;     //!< soft limit
871082SN/A        uint64_t  rlim_max;     //!< hard limit
881082SN/A    } rlimit;
891082SN/A
901082SN/A    /// For gettimeofday().
911082SN/A    typedef struct {
921082SN/A        int64_t tv_sec;         //!< seconds
932190SN/A        int64_t tv_usec;        //!< microseconds
941082SN/A    } timeval;
95
96    // For writev/readv
97    typedef struct {
98        uint64_t iov_base; // void *
99        uint64_t iov_len;
100    } tgt_iovec;
101
102
103    /// For getrusage().
104    typedef struct {
105        timeval ru_utime;       //!< user time used
106        timeval ru_stime;       //!< system time used
107        int64_t ru_maxrss;              //!< max rss
108        int64_t ru_ixrss;               //!< integral shared memory size
109        int64_t ru_idrss;               //!< integral unshared data "
110        int64_t ru_isrss;               //!< integral unshared stack "
111        int64_t ru_minflt;              //!< page reclaims - total vmfaults
112        int64_t ru_majflt;              //!< page faults
113        int64_t ru_nswap;               //!< swaps
114        int64_t ru_inblock;             //!< block input operations
115        int64_t ru_oublock;             //!< block output operations
116        int64_t ru_msgsnd;              //!< messages sent
117        int64_t ru_msgrcv;              //!< messages received
118        int64_t ru_nsignals;            //!< signals received
119        int64_t ru_nvcsw;               //!< voluntary context switches
120        int64_t ru_nivcsw;              //!< involuntary "
121    } rusage;
122
123    static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
124
125};  // class OperatingSystem
126
127
128#endif // FULL_SYSTEM
129
130#endif // __OPERATINGSYSTEM_HH__
131