operatingsystem.hh (6672:b636411c118e) operatingsystem.hh (8767:e575781f71b8)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 */
30
31#ifndef __KERN_OPERATINGSYSTEM_HH__
32#define __KERN_OPERATINGSYSTEM_HH__
33
34#include "base/types.hh"
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 */
30
31#ifndef __KERN_OPERATINGSYSTEM_HH__
32#define __KERN_OPERATINGSYSTEM_HH__
33
34#include "base/types.hh"
35#include "config/full_system.hh"
36
35
37#if FULL_SYSTEM
38
39class OperatingSystem {};
40
41#else //!FULL_SYSTEM
42#include <string>
43
44class LiveProcess;
45class ThreadContext;
46
47/// This struct is used to build an target-OS-dependent table that
48/// maps the target's open() flags to the host open() flags.
49struct OpenFlagTransTable {
50 int tgtFlag; //!< Target system flag value.
51 int hostFlag; //!< Corresponding host system flag value.
52};
53
54
55///
56/// This class encapsulates the types, structures, constants,
57/// functions, and syscall-number mappings specific to an operating system
58/// syscall interface.
59///
60class OperatingSystem {
61
62 public:
63
64 /// Stat buffer. Note that we can't call it 'stat' since that
65 /// gets #defined to something else on some systems. This type
66 /// can be specialized by architecture specific "Linux" classes
67 typedef void tgt_stat;
68
69 // same for stat64
70 typedef void tgt_stat64;
71
72 /// Length of strings in struct utsname (plus 1 for null char).
73 static const int _SYS_NMLN = 65;
74
75 /// Interface struct for uname().
76 typedef struct {
77 char sysname[_SYS_NMLN]; //!< System name.
78 char nodename[_SYS_NMLN]; //!< Node name.
79 char release[_SYS_NMLN]; //!< OS release.
80 char version[_SYS_NMLN]; //!< OS version.
81 char machine[_SYS_NMLN]; //!< Machine type.
82 } utsname;
83
84 /// Limit struct for getrlimit/setrlimit.
85 typedef struct {
86 uint64_t rlim_cur; //!< soft limit
87 uint64_t rlim_max; //!< hard limit
88 } rlimit;
89
90 /// For gettimeofday().
91 typedef struct {
92 int64_t tv_sec; //!< seconds
93 int64_t tv_usec; //!< microseconds
94 } 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 static const bool mmapGrowsUp = true;
126
127 static bool mmapGrowsDown() { return false; }
128
129}; // class OperatingSystem
130
36#include <string>
37
38class LiveProcess;
39class ThreadContext;
40
41/// This struct is used to build an target-OS-dependent table that
42/// maps the target's open() flags to the host open() flags.
43struct OpenFlagTransTable {
44 int tgtFlag; //!< Target system flag value.
45 int hostFlag; //!< Corresponding host system flag value.
46};
47
48
49///
50/// This class encapsulates the types, structures, constants,
51/// functions, and syscall-number mappings specific to an operating system
52/// syscall interface.
53///
54class OperatingSystem {
55
56 public:
57
58 /// Stat buffer. Note that we can't call it 'stat' since that
59 /// gets #defined to something else on some systems. This type
60 /// can be specialized by architecture specific "Linux" classes
61 typedef void tgt_stat;
62
63 // same for stat64
64 typedef void tgt_stat64;
65
66 /// Length of strings in struct utsname (plus 1 for null char).
67 static const int _SYS_NMLN = 65;
68
69 /// Interface struct for uname().
70 typedef struct {
71 char sysname[_SYS_NMLN]; //!< System name.
72 char nodename[_SYS_NMLN]; //!< Node name.
73 char release[_SYS_NMLN]; //!< OS release.
74 char version[_SYS_NMLN]; //!< OS version.
75 char machine[_SYS_NMLN]; //!< Machine type.
76 } utsname;
77
78 /// Limit struct for getrlimit/setrlimit.
79 typedef struct {
80 uint64_t rlim_cur; //!< soft limit
81 uint64_t rlim_max; //!< hard limit
82 } rlimit;
83
84 /// For gettimeofday().
85 typedef struct {
86 int64_t tv_sec; //!< seconds
87 int64_t tv_usec; //!< microseconds
88 } timeval;
89
90 // For writev/readv
91 typedef struct {
92 uint64_t iov_base; // void *
93 uint64_t iov_len;
94 } tgt_iovec;
95
96
97 /// For getrusage().
98 typedef struct {
99 timeval ru_utime; //!< user time used
100 timeval ru_stime; //!< system time used
101 int64_t ru_maxrss; //!< max rss
102 int64_t ru_ixrss; //!< integral shared memory size
103 int64_t ru_idrss; //!< integral unshared data "
104 int64_t ru_isrss; //!< integral unshared stack "
105 int64_t ru_minflt; //!< page reclaims - total vmfaults
106 int64_t ru_majflt; //!< page faults
107 int64_t ru_nswap; //!< swaps
108 int64_t ru_inblock; //!< block input operations
109 int64_t ru_oublock; //!< block output operations
110 int64_t ru_msgsnd; //!< messages sent
111 int64_t ru_msgrcv; //!< messages received
112 int64_t ru_nsignals; //!< signals received
113 int64_t ru_nvcsw; //!< voluntary context switches
114 int64_t ru_nivcsw; //!< involuntary "
115 } rusage;
116
117 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
118
119 static const bool mmapGrowsUp = true;
120
121 static bool mmapGrowsDown() { return false; }
122
123}; // class OperatingSystem
124
131
132#endif // FULL_SYSTEM
133
134#endif // __OPERATINGSYSTEM_HH__
125#endif // __OPERATINGSYSTEM_HH__