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