linux.hh revision 9141
1451SN/A/* 25795Ssaidi@eecs.umich.edu * Copyright (c) 2004-2009 The Regents of The University of Michigan 3451SN/A * All rights reserved. 4451SN/A * 5451SN/A * Redistribution and use in source and binary forms, with or without 6451SN/A * modification, are permitted provided that the following conditions are 7451SN/A * met: redistributions of source code must retain the above copyright 8451SN/A * notice, this list of conditions and the following disclaimer; 9451SN/A * redistributions in binary form must reproduce the above copyright 10451SN/A * notice, this list of conditions and the following disclaimer in the 11451SN/A * documentation and/or other materials provided with the distribution; 12451SN/A * neither the name of the copyright holders nor the names of its 13451SN/A * contributors may be used to endorse or promote products derived from 14451SN/A * this software without specific prior written permission. 15451SN/A * 16451SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17451SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18451SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19451SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20451SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21451SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22451SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23451SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24451SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25451SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26451SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 29451SN/A */ 30451SN/A 31451SN/A#ifndef __LINUX_HH__ 32451SN/A#define __LINUX_HH__ 336215Snate@binkert.org 346215Snate@binkert.org#include "base/types.hh" 352093SN/A 365795Ssaidi@eecs.umich.edu#include <string> 372093SN/A 383113Sgblack@eecs.umich.edu#include "kern/operatingsystem.hh" 392423SN/A 405795Ssaidi@eecs.umich.educlass ThreadContext; 415795Ssaidi@eecs.umich.educlass LiveProcess; 425795Ssaidi@eecs.umich.edu 432093SN/A/// 442093SN/A/// This class encapsulates the types, structures, constants, 452093SN/A/// functions, and syscall-number mappings specific to the Alpha Linux 462093SN/A/// syscall interface. 472093SN/A/// 483113Sgblack@eecs.umich.educlass Linux : public OperatingSystem 493113Sgblack@eecs.umich.edu{ 502093SN/A 512093SN/A public: 522093SN/A 532093SN/A //@{ 542093SN/A /// Basic Linux types. 553122Sgblack@eecs.umich.edu typedef uint64_t size_t; 562093SN/A typedef uint64_t off_t; 572093SN/A typedef int64_t time_t; 586684Stjones1@inf.ed.ac.uk typedef int64_t clock_t; 592093SN/A typedef uint32_t uid_t; 603122Sgblack@eecs.umich.edu typedef uint32_t gid_t; 612093SN/A //@} 622093SN/A 632093SN/A /// Stat buffer. Note that we can't call it 'stat' since that 643113Sgblack@eecs.umich.edu /// gets #defined to something else on some systems. This type 653113Sgblack@eecs.umich.edu /// can be specialized by architecture specific "Linux" classes 663113Sgblack@eecs.umich.edu typedef struct { 675543Ssaidi@eecs.umich.edu uint32_t st_dev; //!< device 685543Ssaidi@eecs.umich.edu uint32_t st_ino; //!< inode 695543Ssaidi@eecs.umich.edu uint32_t st_mode; //!< mode 705543Ssaidi@eecs.umich.edu uint32_t st_nlink; //!< link count 715543Ssaidi@eecs.umich.edu uint32_t st_uid; //!< owner's user ID 725543Ssaidi@eecs.umich.edu uint32_t st_gid; //!< owner's group ID 735543Ssaidi@eecs.umich.edu uint32_t st_rdev; //!< device number 745543Ssaidi@eecs.umich.edu int32_t _pad1; //!< for alignment 755543Ssaidi@eecs.umich.edu int64_t st_size; //!< file size in bytes 765543Ssaidi@eecs.umich.edu uint64_t st_atimeX; //!< time of last access 775543Ssaidi@eecs.umich.edu uint64_t st_mtimeX; //!< time of last modification 785543Ssaidi@eecs.umich.edu uint64_t st_ctimeX; //!< time of last status change 795543Ssaidi@eecs.umich.edu uint32_t st_blksize; //!< optimal I/O block size 805543Ssaidi@eecs.umich.edu int32_t st_blocks; //!< number of blocks allocated 815543Ssaidi@eecs.umich.edu uint32_t st_flags; //!< flags 825543Ssaidi@eecs.umich.edu uint32_t st_gen; //!< unknown 833113Sgblack@eecs.umich.edu } tgt_stat; 842093SN/A 852093SN/A // same for stat64 863113Sgblack@eecs.umich.edu typedef struct { 875543Ssaidi@eecs.umich.edu uint64_t st_dev; 885543Ssaidi@eecs.umich.edu uint64_t st_ino; 895543Ssaidi@eecs.umich.edu uint64_t st_rdev; 905543Ssaidi@eecs.umich.edu int64_t st_size; 915543Ssaidi@eecs.umich.edu uint64_t st_blocks; 922093SN/A 935543Ssaidi@eecs.umich.edu uint32_t st_mode; 945543Ssaidi@eecs.umich.edu uint32_t st_uid; 955543Ssaidi@eecs.umich.edu uint32_t st_gid; 965543Ssaidi@eecs.umich.edu uint32_t st_blksize; 975543Ssaidi@eecs.umich.edu uint32_t st_nlink; 985543Ssaidi@eecs.umich.edu uint32_t __pad0; 992093SN/A 1005543Ssaidi@eecs.umich.edu uint64_t st_atimeX; 1015543Ssaidi@eecs.umich.edu uint64_t st_atime_nsec; 1025543Ssaidi@eecs.umich.edu uint64_t st_mtimeX; 1035543Ssaidi@eecs.umich.edu uint64_t st_mtime_nsec; 1045543Ssaidi@eecs.umich.edu uint64_t st_ctimeX; 1055543Ssaidi@eecs.umich.edu uint64_t st_ctime_nsec; 1065543Ssaidi@eecs.umich.edu int64_t ___unused[3]; 1073113Sgblack@eecs.umich.edu } tgt_stat64; 1082093SN/A 1092093SN/A /// Length of strings in struct utsname (plus 1 for null char). 1102093SN/A static const int _SYS_NMLN = 65; 1112093SN/A 1122093SN/A /// Interface struct for uname(). 1132093SN/A struct utsname { 1145543Ssaidi@eecs.umich.edu char sysname[_SYS_NMLN]; //!< System name. 1155543Ssaidi@eecs.umich.edu char nodename[_SYS_NMLN]; //!< Node name. 1165543Ssaidi@eecs.umich.edu char release[_SYS_NMLN]; //!< OS release. 1175543Ssaidi@eecs.umich.edu char version[_SYS_NMLN]; //!< OS version. 1185543Ssaidi@eecs.umich.edu char machine[_SYS_NMLN]; //!< Machine type. 1192093SN/A }; 1202093SN/A 1212093SN/A /// Limit struct for getrlimit/setrlimit. 1222093SN/A struct rlimit { 1235543Ssaidi@eecs.umich.edu uint64_t rlim_cur; //!< soft limit 1245543Ssaidi@eecs.umich.edu uint64_t rlim_max; //!< hard limit 1252093SN/A }; 1262093SN/A 1272093SN/A /// For gettimeofday(). 1282093SN/A struct timeval { 1295543Ssaidi@eecs.umich.edu int64_t tv_sec; //!< seconds 1305543Ssaidi@eecs.umich.edu int64_t tv_usec; //!< microseconds 1312093SN/A }; 1322093SN/A 1336683Stjones1@inf.ed.ac.uk /// Clock ticks per second, for times(). 1346744SAli.Saidi@arm.com static const int M5_SC_CLK_TCK = 100; 1356683Stjones1@inf.ed.ac.uk 1366683Stjones1@inf.ed.ac.uk /// For times(). 1376683Stjones1@inf.ed.ac.uk struct tms { 1386683Stjones1@inf.ed.ac.uk int64_t tms_utime; //!< user time 1396683Stjones1@inf.ed.ac.uk int64_t tms_stime; //!< system time 1406683Stjones1@inf.ed.ac.uk int64_t tms_cutime; //!< user time of children 1416683Stjones1@inf.ed.ac.uk int64_t tms_cstime; //!< system time of children 1426683Stjones1@inf.ed.ac.uk }; 1436683Stjones1@inf.ed.ac.uk 1442093SN/A // For writev/readv 1452093SN/A struct tgt_iovec { 1462093SN/A uint64_t iov_base; // void * 1472093SN/A uint64_t iov_len; 1482093SN/A }; 1492093SN/A 1509141Smarc.orr@gmail.com //@{ 1519141Smarc.orr@gmail.com /// ioctl() command codes. 1529141Smarc.orr@gmail.com static const unsigned TGT_TCGETS = 0x5401; 1539141Smarc.orr@gmail.com static const unsigned TGT_TCGETA = 0x5405; 1549141Smarc.orr@gmail.com static const unsigned TGT_TCSETAW = 0x5407; 1559141Smarc.orr@gmail.com static const unsigned TGT_FIONREAD = 0x541B; 1569141Smarc.orr@gmail.com //@} 1579141Smarc.orr@gmail.com 1589141Smarc.orr@gmail.com /// Return true for the ioctl codes for which we return ENOTTY 1599141Smarc.orr@gmail.com /// *without* printing a warning, since we know that ENOTTY is the 1609141Smarc.orr@gmail.com /// correct thing to return (and not just a sign that we don't 1619141Smarc.orr@gmail.com /// recognize the ioctl code. 1629141Smarc.orr@gmail.com static bool 1639141Smarc.orr@gmail.com isTtyReq(unsigned req) 1649141Smarc.orr@gmail.com { 1659141Smarc.orr@gmail.com switch (req) { 1669141Smarc.orr@gmail.com case TGT_FIONREAD: 1679141Smarc.orr@gmail.com case TGT_TCSETAW: 1689141Smarc.orr@gmail.com case TGT_TCGETS: 1699141Smarc.orr@gmail.com case TGT_TCGETA: 1709141Smarc.orr@gmail.com return true; 1719141Smarc.orr@gmail.com default: 1729141Smarc.orr@gmail.com return false; 1739141Smarc.orr@gmail.com } 1749141Smarc.orr@gmail.com } 1759141Smarc.orr@gmail.com 1762093SN/A 1772093SN/A /// For getrusage(). 1782093SN/A struct rusage { 1795543Ssaidi@eecs.umich.edu struct timeval ru_utime; //!< user time used 1805543Ssaidi@eecs.umich.edu struct timeval ru_stime; //!< system time used 1815543Ssaidi@eecs.umich.edu int64_t ru_maxrss; //!< max rss 1825543Ssaidi@eecs.umich.edu int64_t ru_ixrss; //!< integral shared memory size 1835543Ssaidi@eecs.umich.edu int64_t ru_idrss; //!< integral unshared data " 1845543Ssaidi@eecs.umich.edu int64_t ru_isrss; //!< integral unshared stack " 1855543Ssaidi@eecs.umich.edu int64_t ru_minflt; //!< page reclaims - total vmfaults 1865543Ssaidi@eecs.umich.edu int64_t ru_majflt; //!< page faults 1875543Ssaidi@eecs.umich.edu int64_t ru_nswap; //!< swaps 1885543Ssaidi@eecs.umich.edu int64_t ru_inblock; //!< block input operations 1895543Ssaidi@eecs.umich.edu int64_t ru_oublock; //!< block output operations 1905543Ssaidi@eecs.umich.edu int64_t ru_msgsnd; //!< messages sent 1915543Ssaidi@eecs.umich.edu int64_t ru_msgrcv; //!< messages received 1925543Ssaidi@eecs.umich.edu int64_t ru_nsignals; //!< signals received 1935543Ssaidi@eecs.umich.edu int64_t ru_nvcsw; //!< voluntary context switches 1945543Ssaidi@eecs.umich.edu int64_t ru_nivcsw; //!< involuntary " 1952093SN/A }; 1962093SN/A 1975795Ssaidi@eecs.umich.edu static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc); 1985795Ssaidi@eecs.umich.edu static std::string procMeminfo(LiveProcess *process, ThreadContext *tc); 1995795Ssaidi@eecs.umich.edu 2009112Smarc.orr@gmail.com // For futex system call 2019112Smarc.orr@gmail.com static const unsigned TGT_FUTEX_WAIT = 0; 2029112Smarc.orr@gmail.com static const unsigned TGT_FUTEX_WAKE = 1; 2039112Smarc.orr@gmail.com static const unsigned TGT_EAGAIN = 11; 2049112Smarc.orr@gmail.com static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN; 2059112Smarc.orr@gmail.com 2062093SN/A}; // class Linux 2072093SN/A 208451SN/A#endif // __LINUX_HH__ 209