2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
29 #ifndef __SIM_SYSCALLRETURN_HH__
30 #define __SIM_SYSCALLRETURN_HH__
35 * This class represents the return value from an emulated system call,
36 * including any errno setting.
38 * On some platforms, the return value and errno are encoded in a
39 * single signed integer. A value less than zero but greater than
40 * -4096 indicates an error, and the value is the negation of the
41 * errno value. Otherwise, the call was successful and the integer is
42 * the return value. (Large negative numbers are considered
43 * successful to allow syscalls to return pointers to high memory,
44 * e.g., stack addresses.) See, for example, Appendix A of the AMD64
45 * ABI spec at http://www.x86-64.org/documentation/abi.pdf.
47 * Other platforms use a more complex interface, returning a value and
48 * an error code in separate registers.
50 * This class is designed to support both types of interfaces.
56 /// For simplicity, allow the object to be initialized with a
57 /// single signed integer using the same positive=success,
58 /// negative=-errno convention described above.
60 /// Typically this constructor is used as a default type
61 /// conversion, so a bare integer is used where a SyscallReturn
62 /// value is expected, e.g., as the return value from a system
63 /// call emulation function ('return 0;' or 'return -EFAULT;').
64 SyscallReturn(int64_t v) : _value(v), _count(1) {}
66 /// A SyscallReturn constructed with no value means don't return anything.
67 SyscallReturn() : _count(0) {}
69 /// A SyscallReturn constructed with two values means put the second value
70 /// in additional return registers as defined by the ABI, if they exist.
71 SyscallReturn(int64_t v1, int64_t v2) :
72 _value(v1), _value2(v2), _count(2)
75 /// Pseudo-constructor to create an instance with the retry flag set.
86 /// Was the system call successful?
90 return (_value >= 0 || _value <= -4096);
93 /// Does the syscall need to be retried?
94 bool needsRetry() const { return retryFlag; }
96 /// Should returning this value be suppressed?
97 bool suppressed() const { return _count == 0; }
99 /// How many values did the syscall attempt to return?
100 int count() const { return _count; }
106 assert(successful());
114 assert(!successful());
118 /// The encoded value (as described above)
119 int64_t encodedValue() const { return _value; }
120 int64_t value2() const { return _value2; }
123 int64_t _value, _value2;
126 bool retryFlag = false;