linux.hh (2632:1bb2f91485ea) linux.hh (2665:a124942bacb8)
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.
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: Ali Saidi
27 */
28
29#ifndef __LINUX_HH__
30#define __LINUX_HH__
31#include "config/full_system.hh"
32
33#if FULL_SYSTEM
34
35class Linux {};
36
37#else //!FULL_SYSTEM
38
39#include <dirent.h>
40#include <errno.h>
41#include <fcntl.h> // for host open() flags
42#include <string.h> // for memset()
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <unistd.h>
46
47#include "arch/isa_traits.hh"
48#include "sim/syscall_emul.hh"
49
50class TranslatingPort;
51
52///
53/// This class encapsulates the types, structures, constants,
54/// functions, and syscall-number mappings specific to the Alpha Linux
55/// syscall interface.
56///
57class Linux {
58
59 public:
60
61 //@{
62 /// Basic Linux types.
63 typedef uint64_t size_t;
64 typedef uint64_t off_t;
65 typedef int64_t time_t;
66 typedef uint32_t uid_t;
67 typedef uint32_t gid_t;
68 //@}
69
70#if BSD_HOST
71 typedef struct stat hst_stat;
72 typedef struct stat hst_stat64;
73#else
74 typedef struct stat hst_stat ;
75 typedef struct stat64 hst_stat64;
76#endif
77
78 /// Stat buffer. Note that we can't call it 'stat' since that
79 /// gets #defined to something else on some systems.
80 struct tgt_stat {
81 uint32_t st_dev; //!< device
82 uint32_t st_ino; //!< inode
83 uint32_t st_mode; //!< mode
84 uint32_t st_nlink; //!< link count
85 uint32_t st_uid; //!< owner's user ID
86 uint32_t st_gid; //!< owner's group ID
87 uint32_t st_rdev; //!< device number
88 int32_t _pad1; //!< for alignment
89 int64_t st_size; //!< file size in bytes
90 uint64_t st_atimeX; //!< time of last access
91 uint64_t st_mtimeX; //!< time of last modification
92 uint64_t st_ctimeX; //!< time of last status change
93 uint32_t st_blksize; //!< optimal I/O block size
94 int32_t st_blocks; //!< number of blocks allocated
95 uint32_t st_flags; //!< flags
96 uint32_t st_gen; //!< unknown
97 };
98
99 // same for stat64
100 struct tgt_stat64 {
101 uint64_t st_dev;
102 uint64_t st_ino;
103 uint64_t st_rdev;
104 int64_t st_size;
105 uint64_t st_blocks;
106
107 uint32_t st_mode;
108 uint32_t st_uid;
109 uint32_t st_gid;
110 uint32_t st_blksize;
111 uint32_t st_nlink;
112 uint32_t __pad0;
113
114 uint64_t tgt_st_atime;
115 uint64_t st_atime_nsec;
116 uint64_t tgt_st_mtime;
117 uint64_t st_mtime_nsec;
118 uint64_t tgt_st_ctime;
119 uint64_t st_ctime_nsec;
120 int64_t ___unused[3];
121 };
122
123 /// Length of strings in struct utsname (plus 1 for null char).
124 static const int _SYS_NMLN = 65;
125
126 /// Interface struct for uname().
127 struct utsname {
128 char sysname[_SYS_NMLN]; //!< System name.
129 char nodename[_SYS_NMLN]; //!< Node name.
130 char release[_SYS_NMLN]; //!< OS release.
131 char version[_SYS_NMLN]; //!< OS version.
132 char machine[_SYS_NMLN]; //!< Machine type.
133 };
134
135 /// Limit struct for getrlimit/setrlimit.
136 struct rlimit {
137 uint64_t rlim_cur; //!< soft limit
138 uint64_t rlim_max; //!< hard limit
139 };
140
141 /// For gettimeofday().
142 struct timeval {
143 int64_t tv_sec; //!< seconds
144 int64_t tv_usec; //!< microseconds
145 };
146
147 // For writev/readv
148 struct tgt_iovec {
149 uint64_t iov_base; // void *
150 uint64_t iov_len;
151 };
152
153
154 /// For getrusage().
155 struct rusage {
156 struct timeval ru_utime; //!< user time used
157 struct timeval ru_stime; //!< system time used
158 int64_t ru_maxrss; //!< max rss
159 int64_t ru_ixrss; //!< integral shared memory size
160 int64_t ru_idrss; //!< integral unshared data "
161 int64_t ru_isrss; //!< integral unshared stack "
162 int64_t ru_minflt; //!< page reclaims - total vmfaults
163 int64_t ru_majflt; //!< page faults
164 int64_t ru_nswap; //!< swaps
165 int64_t ru_inblock; //!< block input operations
166 int64_t ru_oublock; //!< block output operations
167 int64_t ru_msgsnd; //!< messages sent
168 int64_t ru_msgrcv; //!< messages received
169 int64_t ru_nsignals; //!< signals received
170 int64_t ru_nvcsw; //!< voluntary context switches
171 int64_t ru_nivcsw; //!< involuntary "
172 };
173
174 /// Helper function to convert a host stat buffer to a target stat
175 /// buffer. Also copies the target buffer out to the simulated
176 /// memory space. Used by stat(), fstat(), and lstat().
177#if !BSD_HOST
178 static void
179 copyOutStatBuf(TranslatingPort *mem, Addr addr, hst_stat *host)
180 {
181 using namespace TheISA;
182
183 TypedBufferArg<Linux::tgt_stat> tgt(addr);
184
185 tgt->st_dev = htog(host->st_dev);
186 tgt->st_ino = htog(host->st_ino);
187 tgt->st_mode = htog(host->st_mode);
188 tgt->st_nlink = htog(host->st_nlink);
189 tgt->st_uid = htog(host->st_uid);
190 tgt->st_gid = htog(host->st_gid);
191 tgt->st_rdev = htog(host->st_rdev);
192 tgt->st_size = htog(host->st_size);
193 tgt->st_atimeX = htog(host->st_atime);
194 tgt->st_mtimeX = htog(host->st_mtime);
195 tgt->st_ctimeX = htog(host->st_ctime);
196 tgt->st_blksize = htog(host->st_blksize);
197 tgt->st_blocks = htog(host->st_blocks);
198
199 tgt.copyOut(mem);
200 }
201#else
202 // Third version for bsd systems which no longer have any support for
203 // the old stat() call and stat() is actually a stat64()
204 static void
205 copyOutStatBuf(TranslatingPort *mem, Addr addr, hst_stat64 *host)
206 {
207 using namespace TheISA;
208
209 TypedBufferArg<Linux::tgt_stat> tgt(addr);
210
211 tgt->st_dev = htog(host->st_dev);
212 tgt->st_ino = htog(host->st_ino);
213 tgt->st_mode = htog(host->st_mode);
214 tgt->st_nlink = htog(host->st_nlink);
215 tgt->st_uid = htog(host->st_uid);
216 tgt->st_gid = htog(host->st_gid);
217 tgt->st_rdev = htog(host->st_rdev);
218 tgt->st_size = htog(host->st_size);
219 tgt->st_atimeX = htog(host->st_atime);
220 tgt->st_mtimeX = htog(host->st_mtime);
221 tgt->st_ctimeX = htog(host->st_ctime);
222 tgt->st_blksize = htog(host->st_blksize);
223 tgt->st_blocks = htog(host->st_blocks);
224
225 tgt.copyOut(mem);
226 }
227#endif
228
229
230 // Same for stat64
231 static void
232 copyOutStat64Buf(TranslatingPort *mem, int fd, Addr addr, hst_stat64 *host)
233 {
234 using namespace TheISA;
235
236 TypedBufferArg<Linux::tgt_stat64> tgt(addr);
237
238 // fd == 1 checks are because libc does some checks
239 // that the stdout is interactive vs. a file
240 // this makes it work on non-linux systems
241 if (fd == 1)
242 tgt->st_dev = htog((uint64_t)0xA);
243 else
244 tgt->st_dev = htog((uint64_t)host->st_dev);
245 // XXX What about STAT64_HAS_BROKEN_ST_INO ???
246 tgt->st_ino = htog((uint64_t)host->st_ino);
247 if (fd == 1)
248 tgt->st_rdev = htog((uint64_t)0x880d);
249 else
250 tgt->st_rdev = htog((uint64_t)host->st_rdev);
251 tgt->st_size = htog((int64_t)host->st_size);
252 tgt->st_blocks = htog((uint64_t)host->st_blocks);
253
254 if (fd == 1)
255 tgt->st_mode = htog((uint32_t)0x2190);
256 else
257 tgt->st_mode = htog((uint32_t)host->st_mode);
258 tgt->st_uid = htog((uint32_t)host->st_uid);
259 tgt->st_gid = htog((uint32_t)host->st_gid);
260 tgt->st_blksize = htog((uint32_t)host->st_blksize);
261 tgt->st_nlink = htog((uint32_t)host->st_nlink);
262 tgt->tgt_st_atime = htog((uint64_t)host->st_atime);
263 tgt->tgt_st_mtime = htog((uint64_t)host->st_mtime);
264 tgt->tgt_st_ctime = htog((uint64_t)host->st_ctime);
265#if defined(STAT_HAVE_NSEC)
266 tgt->st_atime_nsec = htog(host->st_atime_nsec);
267 tgt->st_mtime_nsec = htog(host->st_mtime_nsec);
268 tgt->st_ctime_nsec = htog(host->st_ctime_nsec);
269#else
270 tgt->st_atime_nsec = 0;
271 tgt->st_mtime_nsec = 0;
272 tgt->st_ctime_nsec = 0;
273#endif
274
275 tgt.copyOut(mem);
276 }
277
278}; // class Linux
279
280
281#endif // FULL_SYSTEM
282
283#endif // __LINUX_HH__
29 */
30
31#ifndef __LINUX_HH__
32#define __LINUX_HH__
33#include "config/full_system.hh"
34
35#if FULL_SYSTEM
36
37class Linux {};
38
39#else //!FULL_SYSTEM
40
41#include <dirent.h>
42#include <errno.h>
43#include <fcntl.h> // for host open() flags
44#include <string.h> // for memset()
45#include <sys/stat.h>
46#include <sys/types.h>
47#include <unistd.h>
48
49#include "arch/isa_traits.hh"
50#include "sim/syscall_emul.hh"
51
52class TranslatingPort;
53
54///
55/// This class encapsulates the types, structures, constants,
56/// functions, and syscall-number mappings specific to the Alpha Linux
57/// syscall interface.
58///
59class Linux {
60
61 public:
62
63 //@{
64 /// Basic Linux types.
65 typedef uint64_t size_t;
66 typedef uint64_t off_t;
67 typedef int64_t time_t;
68 typedef uint32_t uid_t;
69 typedef uint32_t gid_t;
70 //@}
71
72#if BSD_HOST
73 typedef struct stat hst_stat;
74 typedef struct stat hst_stat64;
75#else
76 typedef struct stat hst_stat ;
77 typedef struct stat64 hst_stat64;
78#endif
79
80 /// Stat buffer. Note that we can't call it 'stat' since that
81 /// gets #defined to something else on some systems.
82 struct tgt_stat {
83 uint32_t st_dev; //!< device
84 uint32_t st_ino; //!< inode
85 uint32_t st_mode; //!< mode
86 uint32_t st_nlink; //!< link count
87 uint32_t st_uid; //!< owner's user ID
88 uint32_t st_gid; //!< owner's group ID
89 uint32_t st_rdev; //!< device number
90 int32_t _pad1; //!< for alignment
91 int64_t st_size; //!< file size in bytes
92 uint64_t st_atimeX; //!< time of last access
93 uint64_t st_mtimeX; //!< time of last modification
94 uint64_t st_ctimeX; //!< time of last status change
95 uint32_t st_blksize; //!< optimal I/O block size
96 int32_t st_blocks; //!< number of blocks allocated
97 uint32_t st_flags; //!< flags
98 uint32_t st_gen; //!< unknown
99 };
100
101 // same for stat64
102 struct tgt_stat64 {
103 uint64_t st_dev;
104 uint64_t st_ino;
105 uint64_t st_rdev;
106 int64_t st_size;
107 uint64_t st_blocks;
108
109 uint32_t st_mode;
110 uint32_t st_uid;
111 uint32_t st_gid;
112 uint32_t st_blksize;
113 uint32_t st_nlink;
114 uint32_t __pad0;
115
116 uint64_t tgt_st_atime;
117 uint64_t st_atime_nsec;
118 uint64_t tgt_st_mtime;
119 uint64_t st_mtime_nsec;
120 uint64_t tgt_st_ctime;
121 uint64_t st_ctime_nsec;
122 int64_t ___unused[3];
123 };
124
125 /// Length of strings in struct utsname (plus 1 for null char).
126 static const int _SYS_NMLN = 65;
127
128 /// Interface struct for uname().
129 struct utsname {
130 char sysname[_SYS_NMLN]; //!< System name.
131 char nodename[_SYS_NMLN]; //!< Node name.
132 char release[_SYS_NMLN]; //!< OS release.
133 char version[_SYS_NMLN]; //!< OS version.
134 char machine[_SYS_NMLN]; //!< Machine type.
135 };
136
137 /// Limit struct for getrlimit/setrlimit.
138 struct rlimit {
139 uint64_t rlim_cur; //!< soft limit
140 uint64_t rlim_max; //!< hard limit
141 };
142
143 /// For gettimeofday().
144 struct timeval {
145 int64_t tv_sec; //!< seconds
146 int64_t tv_usec; //!< microseconds
147 };
148
149 // For writev/readv
150 struct tgt_iovec {
151 uint64_t iov_base; // void *
152 uint64_t iov_len;
153 };
154
155
156 /// For getrusage().
157 struct rusage {
158 struct timeval ru_utime; //!< user time used
159 struct timeval ru_stime; //!< system time used
160 int64_t ru_maxrss; //!< max rss
161 int64_t ru_ixrss; //!< integral shared memory size
162 int64_t ru_idrss; //!< integral unshared data "
163 int64_t ru_isrss; //!< integral unshared stack "
164 int64_t ru_minflt; //!< page reclaims - total vmfaults
165 int64_t ru_majflt; //!< page faults
166 int64_t ru_nswap; //!< swaps
167 int64_t ru_inblock; //!< block input operations
168 int64_t ru_oublock; //!< block output operations
169 int64_t ru_msgsnd; //!< messages sent
170 int64_t ru_msgrcv; //!< messages received
171 int64_t ru_nsignals; //!< signals received
172 int64_t ru_nvcsw; //!< voluntary context switches
173 int64_t ru_nivcsw; //!< involuntary "
174 };
175
176 /// Helper function to convert a host stat buffer to a target stat
177 /// buffer. Also copies the target buffer out to the simulated
178 /// memory space. Used by stat(), fstat(), and lstat().
179#if !BSD_HOST
180 static void
181 copyOutStatBuf(TranslatingPort *mem, Addr addr, hst_stat *host)
182 {
183 using namespace TheISA;
184
185 TypedBufferArg<Linux::tgt_stat> tgt(addr);
186
187 tgt->st_dev = htog(host->st_dev);
188 tgt->st_ino = htog(host->st_ino);
189 tgt->st_mode = htog(host->st_mode);
190 tgt->st_nlink = htog(host->st_nlink);
191 tgt->st_uid = htog(host->st_uid);
192 tgt->st_gid = htog(host->st_gid);
193 tgt->st_rdev = htog(host->st_rdev);
194 tgt->st_size = htog(host->st_size);
195 tgt->st_atimeX = htog(host->st_atime);
196 tgt->st_mtimeX = htog(host->st_mtime);
197 tgt->st_ctimeX = htog(host->st_ctime);
198 tgt->st_blksize = htog(host->st_blksize);
199 tgt->st_blocks = htog(host->st_blocks);
200
201 tgt.copyOut(mem);
202 }
203#else
204 // Third version for bsd systems which no longer have any support for
205 // the old stat() call and stat() is actually a stat64()
206 static void
207 copyOutStatBuf(TranslatingPort *mem, Addr addr, hst_stat64 *host)
208 {
209 using namespace TheISA;
210
211 TypedBufferArg<Linux::tgt_stat> tgt(addr);
212
213 tgt->st_dev = htog(host->st_dev);
214 tgt->st_ino = htog(host->st_ino);
215 tgt->st_mode = htog(host->st_mode);
216 tgt->st_nlink = htog(host->st_nlink);
217 tgt->st_uid = htog(host->st_uid);
218 tgt->st_gid = htog(host->st_gid);
219 tgt->st_rdev = htog(host->st_rdev);
220 tgt->st_size = htog(host->st_size);
221 tgt->st_atimeX = htog(host->st_atime);
222 tgt->st_mtimeX = htog(host->st_mtime);
223 tgt->st_ctimeX = htog(host->st_ctime);
224 tgt->st_blksize = htog(host->st_blksize);
225 tgt->st_blocks = htog(host->st_blocks);
226
227 tgt.copyOut(mem);
228 }
229#endif
230
231
232 // Same for stat64
233 static void
234 copyOutStat64Buf(TranslatingPort *mem, int fd, Addr addr, hst_stat64 *host)
235 {
236 using namespace TheISA;
237
238 TypedBufferArg<Linux::tgt_stat64> tgt(addr);
239
240 // fd == 1 checks are because libc does some checks
241 // that the stdout is interactive vs. a file
242 // this makes it work on non-linux systems
243 if (fd == 1)
244 tgt->st_dev = htog((uint64_t)0xA);
245 else
246 tgt->st_dev = htog((uint64_t)host->st_dev);
247 // XXX What about STAT64_HAS_BROKEN_ST_INO ???
248 tgt->st_ino = htog((uint64_t)host->st_ino);
249 if (fd == 1)
250 tgt->st_rdev = htog((uint64_t)0x880d);
251 else
252 tgt->st_rdev = htog((uint64_t)host->st_rdev);
253 tgt->st_size = htog((int64_t)host->st_size);
254 tgt->st_blocks = htog((uint64_t)host->st_blocks);
255
256 if (fd == 1)
257 tgt->st_mode = htog((uint32_t)0x2190);
258 else
259 tgt->st_mode = htog((uint32_t)host->st_mode);
260 tgt->st_uid = htog((uint32_t)host->st_uid);
261 tgt->st_gid = htog((uint32_t)host->st_gid);
262 tgt->st_blksize = htog((uint32_t)host->st_blksize);
263 tgt->st_nlink = htog((uint32_t)host->st_nlink);
264 tgt->tgt_st_atime = htog((uint64_t)host->st_atime);
265 tgt->tgt_st_mtime = htog((uint64_t)host->st_mtime);
266 tgt->tgt_st_ctime = htog((uint64_t)host->st_ctime);
267#if defined(STAT_HAVE_NSEC)
268 tgt->st_atime_nsec = htog(host->st_atime_nsec);
269 tgt->st_mtime_nsec = htog(host->st_mtime_nsec);
270 tgt->st_ctime_nsec = htog(host->st_ctime_nsec);
271#else
272 tgt->st_atime_nsec = 0;
273 tgt->st_mtime_nsec = 0;
274 tgt->st_ctime_nsec = 0;
275#endif
276
277 tgt.copyOut(mem);
278 }
279
280}; // class Linux
281
282
283#endif // FULL_SYSTEM
284
285#endif // __LINUX_HH__