solaris.hh (2764:e6fea7527b3c) solaris.hh (3113:a6811aaea654)
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;

--- 24 unchanged lines hidden (view full) ---

33#include "config/full_system.hh"
34
35#if FULL_SYSTEM
36
37class Solaris {};
38
39#else //!FULL_SYSTEM
40
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;

--- 24 unchanged lines hidden (view full) ---

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