linux.hh (6744:408673e38566) linux.hh (8767:e575781f71b8)
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#include "config/full_system.hh"
36
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#include "config/full_system.hh"
36
37#if FULL_SYSTEM
38
39class Linux {};
40
41#else //!FULL_SYSTEM
42
43#include <string>
44
45#include "kern/operatingsystem.hh"
46
47class ThreadContext;
48class LiveProcess;
49
50///
51/// This class encapsulates the types, structures, constants,
52/// functions, and syscall-number mappings specific to the Alpha Linux
53/// syscall interface.
54///
55class Linux : public OperatingSystem
56{
57
58 public:
59
60 //@{
61 /// Basic Linux types.
62 typedef uint64_t size_t;
63 typedef uint64_t off_t;
64 typedef int64_t time_t;
65 typedef int64_t clock_t;
66 typedef uint32_t uid_t;
67 typedef uint32_t gid_t;
68 //@}
69
70 /// Stat buffer. Note that we can't call it 'stat' since that
71 /// gets #defined to something else on some systems. This type
72 /// can be specialized by architecture specific "Linux" classes
73 typedef struct {
74 uint32_t st_dev; //!< device
75 uint32_t st_ino; //!< inode
76 uint32_t st_mode; //!< mode
77 uint32_t st_nlink; //!< link count
78 uint32_t st_uid; //!< owner's user ID
79 uint32_t st_gid; //!< owner's group ID
80 uint32_t st_rdev; //!< device number
81 int32_t _pad1; //!< for alignment
82 int64_t st_size; //!< file size in bytes
83 uint64_t st_atimeX; //!< time of last access
84 uint64_t st_mtimeX; //!< time of last modification
85 uint64_t st_ctimeX; //!< time of last status change
86 uint32_t st_blksize; //!< optimal I/O block size
87 int32_t st_blocks; //!< number of blocks allocated
88 uint32_t st_flags; //!< flags
89 uint32_t st_gen; //!< unknown
90 } tgt_stat;
91
92 // same for stat64
93 typedef struct {
94 uint64_t st_dev;
95 uint64_t st_ino;
96 uint64_t st_rdev;
97 int64_t st_size;
98 uint64_t st_blocks;
99
100 uint32_t st_mode;
101 uint32_t st_uid;
102 uint32_t st_gid;
103 uint32_t st_blksize;
104 uint32_t st_nlink;
105 uint32_t __pad0;
106
107 uint64_t st_atimeX;
108 uint64_t st_atime_nsec;
109 uint64_t st_mtimeX;
110 uint64_t st_mtime_nsec;
111 uint64_t st_ctimeX;
112 uint64_t st_ctime_nsec;
113 int64_t ___unused[3];
114 } tgt_stat64;
115
116 /// Length of strings in struct utsname (plus 1 for null char).
117 static const int _SYS_NMLN = 65;
118
119 /// Interface struct for uname().
120 struct utsname {
121 char sysname[_SYS_NMLN]; //!< System name.
122 char nodename[_SYS_NMLN]; //!< Node name.
123 char release[_SYS_NMLN]; //!< OS release.
124 char version[_SYS_NMLN]; //!< OS version.
125 char machine[_SYS_NMLN]; //!< Machine type.
126 };
127
128 /// Limit struct for getrlimit/setrlimit.
129 struct rlimit {
130 uint64_t rlim_cur; //!< soft limit
131 uint64_t rlim_max; //!< hard limit
132 };
133
134 /// For gettimeofday().
135 struct timeval {
136 int64_t tv_sec; //!< seconds
137 int64_t tv_usec; //!< microseconds
138 };
139
140 /// Clock ticks per second, for times().
141 static const int M5_SC_CLK_TCK = 100;
142
143 /// For times().
144 struct tms {
145 int64_t tms_utime; //!< user time
146 int64_t tms_stime; //!< system time
147 int64_t tms_cutime; //!< user time of children
148 int64_t tms_cstime; //!< system time of children
149 };
150
151 // For writev/readv
152 struct tgt_iovec {
153 uint64_t iov_base; // void *
154 uint64_t iov_len;
155 };
156
157
158 /// For getrusage().
159 struct rusage {
160 struct timeval ru_utime; //!< user time used
161 struct timeval ru_stime; //!< system time used
162 int64_t ru_maxrss; //!< max rss
163 int64_t ru_ixrss; //!< integral shared memory size
164 int64_t ru_idrss; //!< integral unshared data "
165 int64_t ru_isrss; //!< integral unshared stack "
166 int64_t ru_minflt; //!< page reclaims - total vmfaults
167 int64_t ru_majflt; //!< page faults
168 int64_t ru_nswap; //!< swaps
169 int64_t ru_inblock; //!< block input operations
170 int64_t ru_oublock; //!< block output operations
171 int64_t ru_msgsnd; //!< messages sent
172 int64_t ru_msgrcv; //!< messages received
173 int64_t ru_nsignals; //!< signals received
174 int64_t ru_nvcsw; //!< voluntary context switches
175 int64_t ru_nivcsw; //!< involuntary "
176 };
177
178 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
179 static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
180
181}; // class Linux
182
37#include <string>
38
39#include "kern/operatingsystem.hh"
40
41class ThreadContext;
42class LiveProcess;
43
44///
45/// This class encapsulates the types, structures, constants,
46/// functions, and syscall-number mappings specific to the Alpha Linux
47/// syscall interface.
48///
49class Linux : public OperatingSystem
50{
51
52 public:
53
54 //@{
55 /// Basic Linux types.
56 typedef uint64_t size_t;
57 typedef uint64_t off_t;
58 typedef int64_t time_t;
59 typedef int64_t clock_t;
60 typedef uint32_t uid_t;
61 typedef uint32_t gid_t;
62 //@}
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 struct {
68 uint32_t st_dev; //!< device
69 uint32_t st_ino; //!< inode
70 uint32_t st_mode; //!< mode
71 uint32_t st_nlink; //!< link count
72 uint32_t st_uid; //!< owner's user ID
73 uint32_t st_gid; //!< owner's group ID
74 uint32_t st_rdev; //!< device number
75 int32_t _pad1; //!< for alignment
76 int64_t st_size; //!< file size in bytes
77 uint64_t st_atimeX; //!< time of last access
78 uint64_t st_mtimeX; //!< time of last modification
79 uint64_t st_ctimeX; //!< time of last status change
80 uint32_t st_blksize; //!< optimal I/O block size
81 int32_t st_blocks; //!< number of blocks allocated
82 uint32_t st_flags; //!< flags
83 uint32_t st_gen; //!< unknown
84 } tgt_stat;
85
86 // same for stat64
87 typedef struct {
88 uint64_t st_dev;
89 uint64_t st_ino;
90 uint64_t st_rdev;
91 int64_t st_size;
92 uint64_t st_blocks;
93
94 uint32_t st_mode;
95 uint32_t st_uid;
96 uint32_t st_gid;
97 uint32_t st_blksize;
98 uint32_t st_nlink;
99 uint32_t __pad0;
100
101 uint64_t st_atimeX;
102 uint64_t st_atime_nsec;
103 uint64_t st_mtimeX;
104 uint64_t st_mtime_nsec;
105 uint64_t st_ctimeX;
106 uint64_t st_ctime_nsec;
107 int64_t ___unused[3];
108 } tgt_stat64;
109
110 /// Length of strings in struct utsname (plus 1 for null char).
111 static const int _SYS_NMLN = 65;
112
113 /// Interface struct for uname().
114 struct utsname {
115 char sysname[_SYS_NMLN]; //!< System name.
116 char nodename[_SYS_NMLN]; //!< Node name.
117 char release[_SYS_NMLN]; //!< OS release.
118 char version[_SYS_NMLN]; //!< OS version.
119 char machine[_SYS_NMLN]; //!< Machine type.
120 };
121
122 /// Limit struct for getrlimit/setrlimit.
123 struct rlimit {
124 uint64_t rlim_cur; //!< soft limit
125 uint64_t rlim_max; //!< hard limit
126 };
127
128 /// For gettimeofday().
129 struct timeval {
130 int64_t tv_sec; //!< seconds
131 int64_t tv_usec; //!< microseconds
132 };
133
134 /// Clock ticks per second, for times().
135 static const int M5_SC_CLK_TCK = 100;
136
137 /// For times().
138 struct tms {
139 int64_t tms_utime; //!< user time
140 int64_t tms_stime; //!< system time
141 int64_t tms_cutime; //!< user time of children
142 int64_t tms_cstime; //!< system time of children
143 };
144
145 // For writev/readv
146 struct tgt_iovec {
147 uint64_t iov_base; // void *
148 uint64_t iov_len;
149 };
150
151
152 /// For getrusage().
153 struct rusage {
154 struct timeval ru_utime; //!< user time used
155 struct timeval ru_stime; //!< system time used
156 int64_t ru_maxrss; //!< max rss
157 int64_t ru_ixrss; //!< integral shared memory size
158 int64_t ru_idrss; //!< integral unshared data "
159 int64_t ru_isrss; //!< integral unshared stack "
160 int64_t ru_minflt; //!< page reclaims - total vmfaults
161 int64_t ru_majflt; //!< page faults
162 int64_t ru_nswap; //!< swaps
163 int64_t ru_inblock; //!< block input operations
164 int64_t ru_oublock; //!< block output operations
165 int64_t ru_msgsnd; //!< messages sent
166 int64_t ru_msgrcv; //!< messages received
167 int64_t ru_nsignals; //!< signals received
168 int64_t ru_nvcsw; //!< voluntary context switches
169 int64_t ru_nivcsw; //!< involuntary "
170 };
171
172 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
173 static std::string procMeminfo(LiveProcess *process, ThreadContext *tc);
174
175}; // class Linux
176
183
184#endif // FULL_SYSTEM
185
186#endif // __LINUX_HH__
177#endif // __LINUX_HH__