gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
linux.hh
Go to the documentation of this file.
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 #include "sim/process.hh"
40 
41 class ThreadContext;
42 
48 class Linux : public OperatingSystem
49 {
50 
51  public:
52 
54  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;
62 
66  typedef struct {
67  uint32_t st_dev;
68  uint32_t st_ino;
69  uint32_t st_mode;
70  uint32_t st_nlink;
71  uint32_t st_uid;
72  uint32_t st_gid;
73  uint32_t st_rdev;
74  int32_t _pad1;
75  int64_t st_size;
76  uint64_t st_atimeX;
77  uint64_t st_mtimeX;
78  uint64_t st_ctimeX;
79  uint32_t st_blksize;
80  int32_t st_blocks;
81  uint32_t st_flags;
82  uint32_t st_gen;
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 
110  static const int _SYS_NMLN = 65;
111 
113  struct utsname {
119  };
120 
122  struct rlimit {
123  uint64_t rlim_cur;
124  uint64_t rlim_max;
125  };
126 
128  struct timeval {
129  int64_t tv_sec;
130  int64_t tv_usec;
131  };
132 
134  struct timespec {
136  int64_t tv_nsec;
137  };
138 
140  static const int M5_SC_CLK_TCK = 100;
141 
143  struct tms {
144  int64_t tms_utime;
145  int64_t tms_stime;
146  int64_t tms_cutime;
147  int64_t tms_cstime;
148  };
149 
150  // For writev/readv
151  struct tgt_iovec {
152  uint64_t iov_base; // void *
153  uint64_t iov_len;
154  };
155 
157  static const unsigned TGT_TCGETS = 0x5401;
159  static const unsigned TGT_TCGETA = 0x5405;
160  static const unsigned TGT_TCSETAW = 0x5407;
161  static const unsigned TGT_FIONREAD = 0x541B;
163 
168  static bool
169  isTtyReq(unsigned req)
170  {
171  switch (req) {
172  case TGT_FIONREAD:
173  case TGT_TCSETAW:
174  case TGT_TCGETS:
175  case TGT_TCGETA:
176  return true;
177  default:
178  return false;
179  }
180  }
181 
182 
184  static const unsigned TGT_RLIMIT_CPU = 0;
185  static const unsigned TGT_RLIMIT_FSIZE = 1;
186  static const unsigned TGT_RLIMIT_DATA = 2;
187  static const unsigned TGT_RLIMIT_STACK = 3;
188  static const unsigned TGT_RLIMIT_CORE = 4;
189  static const unsigned TGT_RLIMIT_RSS = 5;
190  static const unsigned TGT_RLIMIT_NPROC = 6;
191  static const unsigned TGT_RLIMIT_NOFILE = 7;
192  static const unsigned TGT_RLIMIT_MEMLOCK = 8;
193  static const unsigned TGT_RLIMIT_AS = 9;
194  static const unsigned TGT_RLIMIT_LOCKS = 10;
195  static const unsigned TGT_RLIMIT_SIGPENDING = 11;
196  static const unsigned TGT_RLIMIT_MSGQUEUE = 12;
197  static const unsigned TGT_RLIMIT_NICE = 13;
198  static const unsigned TGT_RLIMIT_RTPRIO = 14;
199  static const unsigned TGT_RLIMIT_RTTIME = 15;
200  static const unsigned TGT_RLIM_NLIMITS = 16;
201 
203  static const int TGT_RUSAGE_SELF = 0;
204  static const int TGT_RUSAGE_CHILDREN = -1;
205  static const int TGT_RUSAGE_BOTH = -2;
206 
207  struct rusage {
208  struct timeval ru_utime;
209  struct timeval ru_stime;
210  int64_t ru_maxrss;
211  int64_t ru_ixrss;
212  int64_t ru_idrss;
213  int64_t ru_isrss;
214  int64_t ru_minflt;
215  int64_t ru_majflt;
216  int64_t ru_nswap;
217  int64_t ru_inblock;
218  int64_t ru_oublock;
219  int64_t ru_msgsnd;
220  int64_t ru_msgrcv;
221  int64_t ru_nsignals;
222  int64_t ru_nvcsw;
223  int64_t ru_nivcsw;
224  };
225 
226  static int openSpecialFile(std::string path, Process *process,
227  ThreadContext *tc);
228  static std::string procMeminfo(Process *process, ThreadContext *tc);
229  static std::string etcPasswd(Process *process, ThreadContext *tc);
230 
231  // For futex system call
232  static const unsigned TGT_FUTEX_WAIT = 0;
233  static const unsigned TGT_FUTEX_WAKE = 1;
234  static const unsigned TGT_EAGAIN = 11;
235  static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN;
236  static const unsigned TGT_FUTEX_PRIVATE_FLAG = 128;
237 
238  // for *at syscalls
239  static const int TGT_AT_FDCWD = -100;
240 
241  // for MREMAP
242  static const unsigned TGT_MREMAP_MAYMOVE = 0x1;
243  static const unsigned TGT_MREMAP_FIXED = 0x2;
244 
245  static const unsigned TGT_CLONE_VM = 0x00000100;
246  static const unsigned TGT_CLONE_FS = 0x00000200;
247  static const unsigned TGT_CLONE_FILES = 0x00000400;
248  static const unsigned TGT_CLONE_SIGHAND = 0x00000800;
249  static const unsigned TGT_CLONE_PTRACE = 0x00002000;
250  static const unsigned TGT_CLONE_VFORK = 0x00004000;
251  static const unsigned TGT_CLONE_PARENT = 0x00008000;
252  static const unsigned TGT_CLONE_THREAD = 0x00010000;
253  static const unsigned TGT_CLONE_NEWNS = 0x00020000;
254  static const unsigned TGT_CLONE_SYSVSEM = 0x00040000;
255  static const unsigned TGT_CLONE_SETTLS = 0x00080000;
256  static const unsigned TGT_CLONE_PARENT_SETTID = 0x00100000;
257  static const unsigned TGT_CLONE_CHILD_CLEARTID = 0x00200000;
258  static const unsigned TGT_CLONE_DETACHED = 0x00400000;
259  static const unsigned TGT_CLONE_UNTRACED = 0x00800000;
260  static const unsigned TGT_CLONE_CHILD_SETTID = 0x01000000;
261  static const unsigned TGT_CLONE_NEWUTS = 0x04000000;
262  static const unsigned TGT_CLONE_NEWIPC = 0x08000000;
263  static const unsigned TGT_CLONE_NEWUSER = 0x10000000;
264  static const unsigned TGT_CLONE_NEWPID = 0x20000000;
265  static const unsigned TGT_CLONE_NEWNET = 0x40000000;
266  static const unsigned TGT_CLONE_IO = 0x80000000;
267 }; // class Linux
268 
269 #endif // __LINUX_HH__
static const unsigned TGT_CLONE_IO
Definition: linux.hh:266
Limit struct for getrlimit/setrlimit.
Definition: linux.hh:122
int64_t ru_nvcsw
voluntary context switches
Definition: linux.hh:222
uint64_t st_mtimeX
time of last modification
Definition: linux.hh:77
static const unsigned TGT_CLONE_SYSVSEM
Definition: linux.hh:254
static const unsigned TGT_CLONE_NEWNS
Definition: linux.hh:253
static const unsigned TGT_CLONE_CHILD_SETTID
Definition: linux.hh:260
int64_t tv_sec
seconds
Definition: linux.hh:129
int64_t tms_stime
system time
Definition: linux.hh:145
int64_t st_size
Definition: linux.hh:90
uint64_t rlim_cur
soft limit
Definition: linux.hh:123
static const unsigned TGT_RLIMIT_FSIZE
Definition: linux.hh:185
int32_t _pad1
for alignment
Definition: linux.hh:74
uint32_t st_gen
unknown
Definition: linux.hh:82
This class encapsulates the types, structures, constants, functions, and syscall-number mappings spec...
static std::string etcPasswd(Process *process, ThreadContext *tc)
Definition: linux.cc:85
int64_t ru_majflt
page faults
Definition: linux.hh:215
static const int M5_SC_CLK_TCK
Clock ticks per second, for times().
Definition: linux.hh:140
static const unsigned TGT_CLONE_SIGHAND
Definition: linux.hh:248
static const unsigned TGT_EWOULDBLOCK
Definition: linux.hh:235
static const unsigned TGT_CLONE_NEWNET
Definition: linux.hh:265
static const unsigned TGT_RLIMIT_DATA
Definition: linux.hh:186
static const unsigned TGT_FUTEX_PRIVATE_FLAG
Definition: linux.hh:236
uint32_t gid_t
Definition: linux.hh:60
For clock_gettime().
Definition: linux.hh:134
static const unsigned TGT_CLONE_PARENT_SETTID
Definition: linux.hh:256
static const unsigned TGT_TCGETA
Definition: linux.hh:159
static const unsigned TGT_RLIMIT_RSS
Definition: linux.hh:189
int64_t tv_nsec
nanoseconds
Definition: linux.hh:136
static bool isTtyReq(unsigned req)
Return true for the ioctl codes for which we return ENOTTY without printing a warning, since we know that ENOTTY is the correct thing to return (and not just a sign that we don't recognize the ioctl code.
Definition: linux.hh:169
uint32_t st_mode
Definition: linux.hh:93
static const unsigned TGT_RLIMIT_RTPRIO
Definition: linux.hh:198
int64_t ru_ixrss
integral shared memory size
Definition: linux.hh:211
char version[_SYS_NMLN]
OS version.
Definition: linux.hh:117
uint32_t __pad0
Definition: linux.hh:98
static const unsigned TGT_FIONREAD
Definition: linux.hh:161
int64_t st_size
file size in bytes
Definition: linux.hh:75
uint64_t iov_len
Definition: linux.hh:153
ThreadContext is the external interface to all thread state for anything outside of the CPU...
uint32_t uid_t
Definition: linux.hh:59
static const unsigned TGT_RLIMIT_SIGPENDING
Definition: linux.hh:195
static const unsigned TGT_RLIMIT_MEMLOCK
Definition: linux.hh:192
int64_t ru_nivcsw
involuntary "
Definition: linux.hh:223
static const unsigned TGT_RLIMIT_AS
Definition: linux.hh:193
char release[_SYS_NMLN]
OS release.
Definition: linux.hh:116
uint64_t st_rdev
Definition: linux.hh:89
static const unsigned TGT_RLIMIT_MSGQUEUE
Definition: linux.hh:196
static const unsigned TGT_TCSETAW
Definition: linux.hh:160
static const unsigned TGT_CLONE_VFORK
Definition: linux.hh:250
static const unsigned TGT_FUTEX_WAKE
Definition: linux.hh:233
static const unsigned TGT_CLONE_DETACHED
Definition: linux.hh:258
static const unsigned TGT_CLONE_FILES
Definition: linux.hh:247
int64_t ru_idrss
integral unshared data "
Definition: linux.hh:212
For times().
Definition: linux.hh:143
static const int TGT_RUSAGE_SELF
For getrusage().
Definition: linux.hh:203
This class encapsulates the types, structures, constants, functions, and syscall-number mappings spec...
Definition: linux.hh:48
static const unsigned TGT_MREMAP_FIXED
Definition: linux.hh:243
int64_t ru_inblock
block input operations
Definition: linux.hh:217
static const unsigned TGT_RLIMIT_NOFILE
Definition: linux.hh:191
static const unsigned TGT_CLONE_CHILD_CLEARTID
Definition: linux.hh:257
static const unsigned TGT_MREMAP_MAYMOVE
Definition: linux.hh:242
static const unsigned TGT_EAGAIN
Definition: linux.hh:234
uint64_t st_atimeX
Definition: linux.hh:100
static const unsigned TGT_CLONE_SETTLS
Definition: linux.hh:255
void tgt_stat
Stat buffer.
uint64_t iov_base
Definition: linux.hh:152
uint32_t st_uid
Definition: linux.hh:94
int64_t clock_t
Definition: linux.hh:58
uint64_t st_ctimeX
Definition: linux.hh:104
static const unsigned TGT_CLONE_VM
Definition: linux.hh:245
int64_t tms_cutime
user time of children
Definition: linux.hh:146
static const unsigned TGT_RLIMIT_CORE
Definition: linux.hh:188
static const unsigned TGT_TCGETS
ioctl() command codes.
Definition: linux.hh:158
uint64_t st_dev
Definition: linux.hh:87
uint64_t st_atime_nsec
Definition: linux.hh:101
struct timeval ru_stime
system time used
Definition: linux.hh:209
static const unsigned TGT_RLIMIT_NPROC
Definition: linux.hh:190
int64_t ru_oublock
block output operations
Definition: linux.hh:218
uint32_t st_ino
inode
Definition: linux.hh:68
static const unsigned TGT_CLONE_PARENT
Definition: linux.hh:251
static const unsigned TGT_RLIMIT_CPU
Resource constants for getrlimit().
Definition: linux.hh:184
static const unsigned TGT_RLIMIT_STACK
Definition: linux.hh:187
int64_t ru_msgrcv
messages received
Definition: linux.hh:220
int32_t st_blocks
number of blocks allocated
Definition: linux.hh:80
static const unsigned TGT_CLONE_UNTRACED
Definition: linux.hh:259
uint32_t st_flags
flags
Definition: linux.hh:81
char sysname[_SYS_NMLN]
System name.
Definition: linux.hh:114
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint32_t st_nlink
Definition: linux.hh:97
struct timeval ru_utime
user time used
Definition: linux.hh:208
static const unsigned TGT_CLONE_NEWUTS
Definition: linux.hh:261
Interface struct for uname().
Definition: linux.hh:113
static const int _SYS_NMLN
Length of strings in struct utsname (plus 1 for null char).
Definition: linux.hh:110
static int openSpecialFile(std::string path, Process *process, ThreadContext *tc)
Definition: linux.cc:42
uint32_t st_dev
device
Definition: linux.hh:67
uint32_t st_uid
owner's user ID
Definition: linux.hh:71
static const unsigned TGT_CLONE_THREAD
Definition: linux.hh:252
uint32_t st_blksize
optimal I/O block size
Definition: linux.hh:79
uint32_t st_mode
mode
Definition: linux.hh:69
int64_t tms_cstime
system time of children
Definition: linux.hh:147
uint32_t st_nlink
link count
Definition: linux.hh:70
int64_t ru_nswap
swaps
Definition: linux.hh:216
int64_t ru_msgsnd
messages sent
Definition: linux.hh:219
uint64_t st_ctimeX
time of last status change
Definition: linux.hh:78
uint32_t st_blksize
Definition: linux.hh:96
int64_t time_t
Definition: linux.hh:57
uint64_t st_mtimeX
Definition: linux.hh:102
int64_t ru_maxrss
max rss
Definition: linux.hh:210
static const unsigned TGT_CLONE_PTRACE
Definition: linux.hh:249
static const unsigned TGT_RLIMIT_RTTIME
Definition: linux.hh:199
uint32_t st_gid
Definition: linux.hh:95
uint64_t st_atimeX
time of last access
Definition: linux.hh:76
static const unsigned TGT_RLIMIT_NICE
Definition: linux.hh:197
static const int TGT_RUSAGE_BOTH
Definition: linux.hh:205
int64_t tv_usec
microseconds
Definition: linux.hh:130
char nodename[_SYS_NMLN]
Node name.
Definition: linux.hh:115
static const unsigned TGT_RLIMIT_LOCKS
Definition: linux.hh:194
uint64_t off_t
Definition: linux.hh:56
uint32_t st_rdev
device number
Definition: linux.hh:73
uint64_t st_mtime_nsec
Definition: linux.hh:103
static const int TGT_RUSAGE_CHILDREN
Definition: linux.hh:204
int64_t ru_nsignals
signals received
Definition: linux.hh:221
int64_t tms_utime
user time
Definition: linux.hh:144
static const int TGT_AT_FDCWD
Definition: linux.hh:239
char machine[_SYS_NMLN]
Machine type.
Definition: linux.hh:118
static const unsigned TGT_FUTEX_WAIT
Definition: linux.hh:232
uint64_t st_ctime_nsec
Definition: linux.hh:105
static const unsigned TGT_CLONE_NEWIPC
Definition: linux.hh:262
uint32_t st_gid
owner's group ID
Definition: linux.hh:72
int64_t ru_minflt
page reclaims - total vmfaults
Definition: linux.hh:214
static const unsigned TGT_RLIM_NLIMITS
Definition: linux.hh:200
static const unsigned TGT_CLONE_NEWPID
Definition: linux.hh:264
static const unsigned TGT_CLONE_FS
Definition: linux.hh:246
uint64_t size_t
Basic Linux types.
Definition: linux.hh:55
uint64_t st_blocks
Definition: linux.hh:91
time_t tv_sec
seconds
Definition: linux.hh:135
int64_t ru_isrss
integral unshared stack "
Definition: linux.hh:213
static const unsigned TGT_CLONE_NEWUSER
Definition: linux.hh:263
For gettimeofday().
Definition: linux.hh:128
uint64_t st_ino
Definition: linux.hh:88
static std::string procMeminfo(Process *process, ThreadContext *tc)
Definition: linux.cc:77
uint64_t rlim_max
hard limit
Definition: linux.hh:124

Generated on Fri Jun 9 2017 13:03:35 for gem5 by doxygen 1.8.6