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 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>
|
41#include <inttypes.h> |
42
|
49#include "arch/isa_traits.hh"
50#include "sim/syscall_emul.hh"
|
43#include "kern/operatingsystem.hh" |
44
|
52class TranslatingPort;
53
|
45/// 46/// This class encapsulates the types, structures, constants, 47/// functions, and syscall-number mappings specific to the Alpha Linux 48/// syscall interface. 49///
|
59class Linux {
|
50class Linux : public OperatingSystem 51{ |
52 53 public: 54 55 //@{ 56 /// Basic Linux types.
|
65 typedef uint64_t size_t;
|
57/* typedef uint64_t size_t; |
58 typedef uint64_t off_t; 59 typedef int64_t time_t; 60 typedef uint32_t uid_t;
|
69 typedef uint32_t gid_t;
|
61 typedef uint32_t gid_t;*/ |
62 //@} 63
|
72#if NO_STAT64
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
|
64 /// 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 {
|
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
|
99 };
|
84 } tgt_stat; |
85 86 // same for stat64
|
102 struct tgt_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
|
116 uint64_t tgt_st_atime;
|
101 uint64_t st_atimeX; |
102 uint64_t st_atime_nsec;
|
118 uint64_t tgt_st_mtime;
|
103 uint64_t st_mtimeX; |
104 uint64_t st_mtime_nsec;
|
120 uint64_t tgt_st_ctime;
|
105 uint64_t st_ctimeX; |
106 uint64_t st_ctime_nsec; 107 int64_t ___unused[3];
|
123 };
|
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 // For writev/readv 135 struct tgt_iovec { 136 uint64_t iov_base; // void * 137 uint64_t iov_len; 138 }; 139 140 141 /// For getrusage(). 142 struct rusage { 143 struct timeval ru_utime; //!< user time used 144 struct timeval ru_stime; //!< system time used 145 int64_t ru_maxrss; //!< max rss 146 int64_t ru_ixrss; //!< integral shared memory size 147 int64_t ru_idrss; //!< integral unshared data " 148 int64_t ru_isrss; //!< integral unshared stack " 149 int64_t ru_minflt; //!< page reclaims - total vmfaults 150 int64_t ru_majflt; //!< page faults 151 int64_t ru_nswap; //!< swaps 152 int64_t ru_inblock; //!< block input operations 153 int64_t ru_oublock; //!< block output operations 154 int64_t ru_msgsnd; //!< messages sent 155 int64_t ru_msgrcv; //!< messages received 156 int64_t ru_nsignals; //!< signals received 157 int64_t ru_nvcsw; //!< voluntary context switches 158 int64_t ru_nivcsw; //!< involuntary " 159 }; 160
|
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 !NO_STAT64
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
|
161}; // class Linux 162 163 164#endif // FULL_SYSTEM 165 166#endif // __LINUX_HH__
|