linux.hh (9141:593fe25c86a6) linux.hh (9146:a61fdbbc1d45)
1/*
2 * Copyright (c) 2004-2009 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: Ali Saidi
29 */
30
31#ifndef __LINUX_HH__
32#define __LINUX_HH__
33
34#include "base/types.hh"
35
36#include <string>
37
38#include "kern/operatingsystem.hh"
39
40class ThreadContext;
41class LiveProcess;
42
43///
44/// This class encapsulates the types, structures, constants,
45/// functions, and syscall-number mappings specific to the Alpha Linux
46/// syscall interface.
47///
48class Linux : public OperatingSystem
49{
50
51 public:
52
53 //@{
54 /// Basic Linux types.
55 typedef uint64_t size_t;
56 typedef uint64_t off_t;
57 typedef int64_t time_t;
58 typedef int64_t clock_t;
59 typedef uint32_t uid_t;
60 typedef uint32_t gid_t;
61 //@}
62
63 /// Stat buffer. Note that we can't call it 'stat' since that
64 /// gets #defined to something else on some systems. This type
65 /// can be specialized by architecture specific "Linux" classes
66 typedef struct {
67 uint32_t st_dev; //!< device
68 uint32_t st_ino; //!< inode
69 uint32_t st_mode; //!< mode
70 uint32_t st_nlink; //!< link count
71 uint32_t st_uid; //!< owner's user ID
72 uint32_t st_gid; //!< owner's group ID
73 uint32_t st_rdev; //!< device number
74 int32_t _pad1; //!< for alignment
75 int64_t st_size; //!< file size in bytes
76 uint64_t st_atimeX; //!< time of last access
77 uint64_t st_mtimeX; //!< time of last modification
78 uint64_t st_ctimeX; //!< time of last status change
79 uint32_t st_blksize; //!< optimal I/O block size
80 int32_t st_blocks; //!< number of blocks allocated
81 uint32_t st_flags; //!< flags
82 uint32_t st_gen; //!< unknown
83 } tgt_stat;
84
85 // same for stat64
86 typedef struct {
87 uint64_t st_dev;
88 uint64_t st_ino;
89 uint64_t st_rdev;
90 int64_t st_size;
91 uint64_t st_blocks;
92
93 uint32_t st_mode;
94 uint32_t st_uid;
95 uint32_t st_gid;
96 uint32_t st_blksize;
97 uint32_t st_nlink;
98 uint32_t __pad0;
99
100 uint64_t st_atimeX;
101 uint64_t st_atime_nsec;
102 uint64_t st_mtimeX;
103 uint64_t st_mtime_nsec;
104 uint64_t st_ctimeX;
105 uint64_t st_ctime_nsec;
106 int64_t ___unused[3];
107 } tgt_stat64;
108
109 /// Length of strings in struct utsname (plus 1 for null char).
110 static const int _SYS_NMLN = 65;
111
112 /// Interface struct for uname().
113 struct utsname {
114 char sysname[_SYS_NMLN]; //!< System name.
115 char nodename[_SYS_NMLN]; //!< Node name.
116 char release[_SYS_NMLN]; //!< OS release.
117 char version[_SYS_NMLN]; //!< OS version.
118 char machine[_SYS_NMLN]; //!< Machine type.
119 };
120
121 /// Limit struct for getrlimit/setrlimit.
122 struct rlimit {
123 uint64_t rlim_cur; //!< soft limit
124 uint64_t rlim_max; //!< hard limit
125 };
126
127 /// For gettimeofday().
128 struct timeval {
129 int64_t tv_sec; //!< seconds
130 int64_t tv_usec; //!< microseconds
131 };
132
133 /// Clock ticks per second, for times().
134 static const int M5_SC_CLK_TCK = 100;
135
136 /// For times().
137 struct tms {
138 int64_t tms_utime; //!< user time
139 int64_t tms_stime; //!< system time
140 int64_t tms_cutime; //!< user time of children
141 int64_t tms_cstime; //!< system time of children
142 };
143
144 // For writev/readv
145 struct tgt_iovec {
146 uint64_t iov_base; // void *
147 uint64_t iov_len;
148 };
149
150 //@{
151 /// ioctl() command codes.
152 static const unsigned TGT_TCGETS = 0x5401;
153 static const unsigned TGT_TCGETA = 0x5405;
154 static const unsigned TGT_TCSETAW = 0x5407;
155 static const unsigned TGT_FIONREAD = 0x541B;
156 //@}
157
158 /// Return true for the ioctl codes for which we return ENOTTY
159 /// *without* printing a warning, since we know that ENOTTY is the
160 /// correct thing to return (and not just a sign that we don't
161 /// recognize the ioctl code.
162 static bool
163 isTtyReq(unsigned req)
164 {
165 switch (req) {
166 case TGT_FIONREAD:
167 case TGT_TCSETAW:
168 case TGT_TCGETS:
169 case TGT_TCGETA:
170 return true;
171 default:
172 return false;
173 }
174 }
175
176
1/*
2 * Copyright (c) 2004-2009 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: Ali Saidi
29 */
30
31#ifndef __LINUX_HH__
32#define __LINUX_HH__
33
34#include "base/types.hh"
35
36#include <string>
37
38#include "kern/operatingsystem.hh"
39
40class ThreadContext;
41class LiveProcess;
42
43///
44/// This class encapsulates the types, structures, constants,
45/// functions, and syscall-number mappings specific to the Alpha Linux
46/// syscall interface.
47///
48class Linux : public OperatingSystem
49{
50
51 public:
52
53 //@{
54 /// Basic Linux types.
55 typedef uint64_t size_t;
56 typedef uint64_t off_t;
57 typedef int64_t time_t;
58 typedef int64_t clock_t;
59 typedef uint32_t uid_t;
60 typedef uint32_t gid_t;
61 //@}
62
63 /// Stat buffer. Note that we can't call it 'stat' since that
64 /// gets #defined to something else on some systems. This type
65 /// can be specialized by architecture specific "Linux" classes
66 typedef struct {
67 uint32_t st_dev; //!< device
68 uint32_t st_ino; //!< inode
69 uint32_t st_mode; //!< mode
70 uint32_t st_nlink; //!< link count
71 uint32_t st_uid; //!< owner's user ID
72 uint32_t st_gid; //!< owner's group ID
73 uint32_t st_rdev; //!< device number
74 int32_t _pad1; //!< for alignment
75 int64_t st_size; //!< file size in bytes
76 uint64_t st_atimeX; //!< time of last access
77 uint64_t st_mtimeX; //!< time of last modification
78 uint64_t st_ctimeX; //!< time of last status change
79 uint32_t st_blksize; //!< optimal I/O block size
80 int32_t st_blocks; //!< number of blocks allocated
81 uint32_t st_flags; //!< flags
82 uint32_t st_gen; //!< unknown
83 } tgt_stat;
84
85 // same for stat64
86 typedef struct {
87 uint64_t st_dev;
88 uint64_t st_ino;
89 uint64_t st_rdev;
90 int64_t st_size;
91 uint64_t st_blocks;
92
93 uint32_t st_mode;
94 uint32_t st_uid;
95 uint32_t st_gid;
96 uint32_t st_blksize;
97 uint32_t st_nlink;
98 uint32_t __pad0;
99
100 uint64_t st_atimeX;
101 uint64_t st_atime_nsec;
102 uint64_t st_mtimeX;
103 uint64_t st_mtime_nsec;
104 uint64_t st_ctimeX;
105 uint64_t st_ctime_nsec;
106 int64_t ___unused[3];
107 } tgt_stat64;
108
109 /// Length of strings in struct utsname (plus 1 for null char).
110 static const int _SYS_NMLN = 65;
111
112 /// Interface struct for uname().
113 struct utsname {
114 char sysname[_SYS_NMLN]; //!< System name.
115 char nodename[_SYS_NMLN]; //!< Node name.
116 char release[_SYS_NMLN]; //!< OS release.
117 char version[_SYS_NMLN]; //!< OS version.
118 char machine[_SYS_NMLN]; //!< Machine type.
119 };
120
121 /// Limit struct for getrlimit/setrlimit.
122 struct rlimit {
123 uint64_t rlim_cur; //!< soft limit
124 uint64_t rlim_max; //!< hard limit
125 };
126
127 /// For gettimeofday().
128 struct timeval {
129 int64_t tv_sec; //!< seconds
130 int64_t tv_usec; //!< microseconds
131 };
132
133 /// Clock ticks per second, for times().
134 static const int M5_SC_CLK_TCK = 100;
135
136 /// For times().
137 struct tms {
138 int64_t tms_utime; //!< user time
139 int64_t tms_stime; //!< system time
140 int64_t tms_cutime; //!< user time of children
141 int64_t tms_cstime; //!< system time of children
142 };
143
144 // For writev/readv
145 struct tgt_iovec {
146 uint64_t iov_base; // void *
147 uint64_t iov_len;
148 };
149
150 //@{
151 /// ioctl() command codes.
152 static const unsigned TGT_TCGETS = 0x5401;
153 static const unsigned TGT_TCGETA = 0x5405;
154 static const unsigned TGT_TCSETAW = 0x5407;
155 static const unsigned TGT_FIONREAD = 0x541B;
156 //@}
157
158 /// Return true for the ioctl codes for which we return ENOTTY
159 /// *without* printing a warning, since we know that ENOTTY is the
160 /// correct thing to return (and not just a sign that we don't
161 /// recognize the ioctl code.
162 static bool
163 isTtyReq(unsigned req)
164 {
165 switch (req) {
166 case TGT_FIONREAD:
167 case TGT_TCSETAW:
168 case TGT_TCGETS:
169 case TGT_TCGETA:
170 return true;
171 default:
172 return false;
173 }
174 }
175
176
177 /// Resource constants for getrlimit().
178 static const unsigned TGT_RLIMIT_CPU = 0;
179 static const unsigned TGT_RLIMIT_FSIZE = 1;
180 static const unsigned TGT_RLIMIT_DATA = 2;
181 static const unsigned TGT_RLIMIT_STACK = 3;
182 static const unsigned TGT_RLIMIT_CORE = 4;
183 static const unsigned TGT_RLIMIT_RSS = 5;
184 static const unsigned TGT_RLIMIT_NPROC = 6;
185 static const unsigned TGT_RLIMIT_NOFILE = 7;
186 static const unsigned TGT_RLIMIT_MEMLOCK = 8;
187 static const unsigned TGT_RLIMIT_AS = 9;
188 static const unsigned TGT_RLIMIT_LOCKS = 10;
189 static const unsigned TGT_RLIMIT_SIGPENDING = 11;
190 static const unsigned TGT_RLIMIT_MSGQUEUE = 12;
191 static const unsigned TGT_RLIMIT_NICE = 13;
192 static const unsigned TGT_RLIMIT_RTPRIO = 14;
193 static const unsigned TGT_RLIMIT_RTTIME = 15;
194 static const unsigned TGT_RLIM_NLIMITS = 16;
195
177 /// For getrusage().
196 /// For getrusage().
197 static const int TGT_RUSAGE_SELF = 0;
198 static const int TGT_RUSAGE_CHILDREN = -1;
199 static const int TGT_RUSAGE_BOTH = -2;
200
178 struct rusage {
179 struct timeval ru_utime; //!< user time used
180 struct timeval ru_stime; //!< system time used
181 int64_t ru_maxrss; //!< max rss
182 int64_t ru_ixrss; //!< integral shared memory size
183 int64_t ru_idrss; //!< integral unshared data "
184 int64_t ru_isrss; //!< integral unshared stack "
185 int64_t ru_minflt; //!< page reclaims - total vmfaults
186 int64_t ru_majflt; //!< page faults
187 int64_t ru_nswap; //!< swaps
188 int64_t ru_inblock; //!< block input operations
189 int64_t ru_oublock; //!< block output operations
190 int64_t ru_msgsnd; //!< messages sent
191 int64_t ru_msgrcv; //!< messages received
192 int64_t ru_nsignals; //!< signals received
193 int64_t ru_nvcsw; //!< voluntary context switches
194 int64_t ru_nivcsw; //!< involuntary "
195 };
196
197 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
198 static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
199
200 // For futex system call
201 static const unsigned TGT_FUTEX_WAIT = 0;
202 static const unsigned TGT_FUTEX_WAKE = 1;
203 static const unsigned TGT_EAGAIN = 11;
204 static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN;
205
206}; // class Linux
207
208#endif // __LINUX_HH__
201 struct rusage {
202 struct timeval ru_utime; //!< user time used
203 struct timeval ru_stime; //!< system time used
204 int64_t ru_maxrss; //!< max rss
205 int64_t ru_ixrss; //!< integral shared memory size
206 int64_t ru_idrss; //!< integral unshared data "
207 int64_t ru_isrss; //!< integral unshared stack "
208 int64_t ru_minflt; //!< page reclaims - total vmfaults
209 int64_t ru_majflt; //!< page faults
210 int64_t ru_nswap; //!< swaps
211 int64_t ru_inblock; //!< block input operations
212 int64_t ru_oublock; //!< block output operations
213 int64_t ru_msgsnd; //!< messages sent
214 int64_t ru_msgrcv; //!< messages received
215 int64_t ru_nsignals; //!< signals received
216 int64_t ru_nvcsw; //!< voluntary context switches
217 int64_t ru_nivcsw; //!< involuntary "
218 };
219
220 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
221 static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
222
223 // For futex system call
224 static const unsigned TGT_FUTEX_WAIT = 0;
225 static const unsigned TGT_FUTEX_WAKE = 1;
226 static const unsigned TGT_EAGAIN = 11;
227 static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN;
228
229}; // class Linux
230
231#endif // __LINUX_HH__