solaris.hh revision 2600
19155SN/A/* 29155SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 39155SN/A * All rights reserved. 49155SN/A * 59155SN/A * Redistribution and use in source and binary forms, with or without 69155SN/A * modification, are permitted provided that the following conditions are 79155SN/A * met: redistributions of source code must retain the above copyright 89155SN/A * notice, this list of conditions and the following disclaimer; 99155SN/A * redistributions in binary form must reproduce the above copyright 109155SN/A * notice, this list of conditions and the following disclaimer in the 119155SN/A * documentation and/or other materials provided with the distribution; 129155SN/A * neither the name of the copyright holders nor the names of its 139155SN/A * contributors may be used to endorse or promote products derived from 149155SN/A * this software without specific prior written permission. 159155SN/A * 169155SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179155SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189155SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199155SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209155SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219155SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229155SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239155SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249155SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259155SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269155SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279155SN/A */ 289155SN/A 299155SN/A#ifndef __SOLARIS_HH__ 309155SN/A#define __SOLARIS_HH__ 319105SN/A#include "config/full_system.hh" 329297SN/A 3310301Snilay@cs.wisc.edu#if FULL_SYSTEM 349297SN/A 359105SN/Aclass Solaris {}; 369297SN/A 3710919Sbrandon.potter@amd.com#else //!FULL_SYSTEM 3810919Sbrandon.potter@amd.com 399105SN/A#include <dirent.h> 409105SN/A#include <errno.h> 419105SN/A#include <fcntl.h> // for host open() flags 429105SN/A#include <string.h> // for memset() 439105SN/A#include <sys/stat.h> 449105SN/A#include <sys/types.h> 459105SN/A#include <unistd.h> 469105SN/A 479105SN/A#include "arch/isa_traits.hh" 489105SN/A#include "sim/syscall_emul.hh" 499105SN/A 509105SN/Aclass TranslatingPort; 519105SN/A 5211061Snilay@cs.wisc.edu/// 539105SN/A/// This class encapsulates the types, structures, constants, 549105SN/A/// functions, and syscall-number mappings specific to the Solaris 559105SN/A/// syscall interface. 569105SN/A/// 579105SN/Aclass Solaris { 589105SN/A 599105SN/A public: 609297SN/A 619105SN/A //@{ 6210978Sdavid.hashe@amd.com /// Basic Solaris types. 6310978Sdavid.hashe@amd.com typedef uint64_t size_t; 6410978Sdavid.hashe@amd.com typedef uint64_t off_t; 6510978Sdavid.hashe@amd.com typedef int64_t time_t; 6610978Sdavid.hashe@amd.com typedef int32_t uid_t; 6710978Sdavid.hashe@amd.com typedef int32_t gid_t; 6811061Snilay@cs.wisc.edu typedef uint64_t rlim_t; 6910978Sdavid.hashe@amd.com typedef uint64_t ino_t; 7010978Sdavid.hashe@amd.com typedef uint64_t dev_t; 7110978Sdavid.hashe@amd.com typedef uint32_t mode_t; 7210978Sdavid.hashe@amd.com typedef uint32_t nlink_t; 7310978Sdavid.hashe@amd.com //@} 7410978Sdavid.hashe@amd.com 7510978Sdavid.hashe@amd.com#if BSD_HOST 7610978Sdavid.hashe@amd.com typedef struct stat hst_stat; 7710978Sdavid.hashe@amd.com typedef struct stat hst_stat64; 7810978Sdavid.hashe@amd.com#else 7910978Sdavid.hashe@amd.com typedef struct stat hst_stat ; 8010978Sdavid.hashe@amd.com typedef struct stat64 hst_stat64; 8110978Sdavid.hashe@amd.com#endif 829105SN/A struct tgt_timespec { 8310978Sdavid.hashe@amd.com int64_t tv_sec; 849105SN/A int64_t tv_nsec; 859105SN/A }; 869105SN/A 879105SN/A /// Stat buffer. Note that we can't call it 'stat' since that 889105SN/A /// gets #defined to something else on some systems. 899297SN/A struct tgt_stat { 9010919Sbrandon.potter@amd.com uint64_t st_dev; //!< device 919105SN/A uint64_t st_ino; //!< inode 929105SN/A uint32_t st_mode; //!< mode 939105SN/A uint32_t st_nlink; //!< link count 9411061Snilay@cs.wisc.edu int32_t st_uid; //!< owner's user ID 959105SN/A int32_t st_gid; //!< owner's group ID 969105SN/A uint64_t st_rdev; //!< device number 979105SN/A int64_t st_size; //!< file size in bytes 989105SN/A struct tgt_timespec st_atimeX; //!< time of last access 999105SN/A struct tgt_timespec st_mtimeX; //!< time of last modification 1009105SN/A 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