operatingsystem.hh (5543:3af77710f397) operatingsystem.hh (5795:72ce7502dc71)
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: Gabe Black
29 */
30
31#ifndef __KERN_OPERATINGSYSTEM_HH__
32#define __KERN_OPERATINGSYSTEM_HH__
33
34#include "config/full_system.hh"
35
36#include <inttypes.h>
37
38#if FULL_SYSTEM
39
40class OperatingSystem {};
41
42#else //!FULL_SYSTEM
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: Gabe Black
29 */
30
31#ifndef __KERN_OPERATINGSYSTEM_HH__
32#define __KERN_OPERATINGSYSTEM_HH__
33
34#include "config/full_system.hh"
35
36#include <inttypes.h>
37
38#if FULL_SYSTEM
39
40class OperatingSystem {};
41
42#else //!FULL_SYSTEM
43#include <string>
43
44
45class LiveProcess;
46class ThreadContext;
47
44/// This struct is used to build an target-OS-dependent table that
45/// maps the target's open() flags to the host open() flags.
46struct OpenFlagTransTable {
47 int tgtFlag; //!< Target system flag value.
48 int hostFlag; //!< Corresponding host system flag value.
49};
50
51
52///
53/// This class encapsulates the types, structures, constants,
54/// functions, and syscall-number mappings specific to an operating system
55/// syscall interface.
56///
57class OperatingSystem {
58
59 public:
60
61 /// Stat buffer. Note that we can't call it 'stat' since that
62 /// gets #defined to something else on some systems. This type
63 /// can be specialized by architecture specific "Linux" classes
64 typedef void tgt_stat;
65
66 // same for stat64
67 typedef void tgt_stat64;
68
69 /// Length of strings in struct utsname (plus 1 for null char).
70 static const int _SYS_NMLN = 65;
71
72 /// Interface struct for uname().
73 typedef struct {
74 char sysname[_SYS_NMLN]; //!< System name.
75 char nodename[_SYS_NMLN]; //!< Node name.
76 char release[_SYS_NMLN]; //!< OS release.
77 char version[_SYS_NMLN]; //!< OS version.
78 char machine[_SYS_NMLN]; //!< Machine type.
79 } utsname;
80
81 /// Limit struct for getrlimit/setrlimit.
82 typedef struct {
83 uint64_t rlim_cur; //!< soft limit
84 uint64_t rlim_max; //!< hard limit
85 } rlimit;
86
87 /// For gettimeofday().
88 typedef struct {
89 int64_t tv_sec; //!< seconds
90 int64_t tv_usec; //!< microseconds
91 } timeval;
92
93 // For writev/readv
94 typedef struct {
95 uint64_t iov_base; // void *
96 uint64_t iov_len;
97 } tgt_iovec;
98
99
100 /// For getrusage().
101 typedef struct {
102 timeval ru_utime; //!< user time used
103 timeval ru_stime; //!< system time used
104 int64_t ru_maxrss; //!< max rss
105 int64_t ru_ixrss; //!< integral shared memory size
106 int64_t ru_idrss; //!< integral unshared data "
107 int64_t ru_isrss; //!< integral unshared stack "
108 int64_t ru_minflt; //!< page reclaims - total vmfaults
109 int64_t ru_majflt; //!< page faults
110 int64_t ru_nswap; //!< swaps
111 int64_t ru_inblock; //!< block input operations
112 int64_t ru_oublock; //!< block output operations
113 int64_t ru_msgsnd; //!< messages sent
114 int64_t ru_msgrcv; //!< messages received
115 int64_t ru_nsignals; //!< signals received
116 int64_t ru_nvcsw; //!< voluntary context switches
117 int64_t ru_nivcsw; //!< involuntary "
118 } rusage;
119
48/// This struct is used to build an target-OS-dependent table that
49/// maps the target's open() flags to the host open() flags.
50struct OpenFlagTransTable {
51 int tgtFlag; //!< Target system flag value.
52 int hostFlag; //!< Corresponding host system flag value.
53};
54
55
56///
57/// This class encapsulates the types, structures, constants,
58/// functions, and syscall-number mappings specific to an operating system
59/// syscall interface.
60///
61class OperatingSystem {
62
63 public:
64
65 /// Stat buffer. Note that we can't call it 'stat' since that
66 /// gets #defined to something else on some systems. This type
67 /// can be specialized by architecture specific "Linux" classes
68 typedef void tgt_stat;
69
70 // same for stat64
71 typedef void tgt_stat64;
72
73 /// Length of strings in struct utsname (plus 1 for null char).
74 static const int _SYS_NMLN = 65;
75
76 /// Interface struct for uname().
77 typedef struct {
78 char sysname[_SYS_NMLN]; //!< System name.
79 char nodename[_SYS_NMLN]; //!< Node name.
80 char release[_SYS_NMLN]; //!< OS release.
81 char version[_SYS_NMLN]; //!< OS version.
82 char machine[_SYS_NMLN]; //!< Machine type.
83 } utsname;
84
85 /// Limit struct for getrlimit/setrlimit.
86 typedef struct {
87 uint64_t rlim_cur; //!< soft limit
88 uint64_t rlim_max; //!< hard limit
89 } rlimit;
90
91 /// For gettimeofday().
92 typedef struct {
93 int64_t tv_sec; //!< seconds
94 int64_t tv_usec; //!< microseconds
95 } timeval;
96
97 // For writev/readv
98 typedef struct {
99 uint64_t iov_base; // void *
100 uint64_t iov_len;
101 } tgt_iovec;
102
103
104 /// For getrusage().
105 typedef struct {
106 timeval ru_utime; //!< user time used
107 timeval ru_stime; //!< system time used
108 int64_t ru_maxrss; //!< max rss
109 int64_t ru_ixrss; //!< integral shared memory size
110 int64_t ru_idrss; //!< integral unshared data "
111 int64_t ru_isrss; //!< integral unshared stack "
112 int64_t ru_minflt; //!< page reclaims - total vmfaults
113 int64_t ru_majflt; //!< page faults
114 int64_t ru_nswap; //!< swaps
115 int64_t ru_inblock; //!< block input operations
116 int64_t ru_oublock; //!< block output operations
117 int64_t ru_msgsnd; //!< messages sent
118 int64_t ru_msgrcv; //!< messages received
119 int64_t ru_nsignals; //!< signals received
120 int64_t ru_nvcsw; //!< voluntary context switches
121 int64_t ru_nivcsw; //!< involuntary "
122 } rusage;
123
124 static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
125
120}; // class OperatingSystem
121
122
123#endif // FULL_SYSTEM
124
125#endif // __OPERATINGSYSTEM_HH__
126}; // class OperatingSystem
127
128
129#endif // FULL_SYSTEM
130
131#endif // __OPERATINGSYSTEM_HH__