syscall_desc.hh revision 12296:e127a1bae7bd
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 2012-2013, 2015 ARM Limited
312855Sgabeblack@google.com * Copyright (c) 2015-2016 Advanced Micro Devices, Inc.
412855Sgabeblack@google.com * All rights reserved
512855Sgabeblack@google.com *
612855Sgabeblack@google.com * The license below extends only to copyright in the software and shall
712855Sgabeblack@google.com * not be construed as granting a license to any other intellectual
812855Sgabeblack@google.com * property including but not limited to intellectual property relating
912855Sgabeblack@google.com * to a hardware implementation of the functionality of the software
1012855Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1112855Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1212855Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1312855Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1412855Sgabeblack@google.com *
1512855Sgabeblack@google.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
1612855Sgabeblack@google.com * All rights reserved.
1712855Sgabeblack@google.com *
1812855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1912855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
2012855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2212855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2312855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2412855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2512855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2612855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2712855Sgabeblack@google.com * this software without specific prior written permission.
2812855Sgabeblack@google.com *
2912855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3012855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3112855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3212855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3312855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3412855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3612855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3712855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3812855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3912855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4012855Sgabeblack@google.com *
4112855Sgabeblack@google.com * Authors: Steve Reinhardt
4212855Sgabeblack@google.com *          Kevin Lim
4312855Sgabeblack@google.com *          Brandon Potter
4412855Sgabeblack@google.com */
4512855Sgabeblack@google.com
4612855Sgabeblack@google.com#ifndef __SIM_SYSCALL_DESC_HH__
4712855Sgabeblack@google.com#define __SIM_SYSCALL_DESC_HH__
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com#include <string>
5012855Sgabeblack@google.com
5112855Sgabeblack@google.com#include "base/types.hh"
5212855Sgabeblack@google.com
5312855Sgabeblack@google.comclass Process;
5412855Sgabeblack@google.comclass SyscallDesc;
5512855Sgabeblack@google.comclass SyscallReturn;
5612855Sgabeblack@google.comclass ThreadContext;
5712855Sgabeblack@google.com
5812855Sgabeblack@google.comSyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
5912855Sgabeblack@google.com    Process *p, ThreadContext *tc);
6012855Sgabeblack@google.com
6112855Sgabeblack@google.com/**
6212855Sgabeblack@google.com * This class provides the wrapper interface for the system call
6312855Sgabeblack@google.com * implementations which are defined in the sim/syscall_emul files and
6412855Sgabeblack@google.com * bound to the ISAs in the architecture specific code
6512855Sgabeblack@google.com * (i.e. arch/X86/linux/process.cc).
6612855Sgabeblack@google.com */
6712855Sgabeblack@google.comclass SyscallDesc {
6812855Sgabeblack@google.com  public:
6912855Sgabeblack@google.com    /** Typedef the function pointer here to clean up code below */
7012855Sgabeblack@google.com    typedef SyscallReturn (*SyscallExecutor)(SyscallDesc*, int num,
7112855Sgabeblack@google.com                                             Process*, ThreadContext*);
7212855Sgabeblack@google.com
7312855Sgabeblack@google.com    SyscallDesc(const char *name,
7412855Sgabeblack@google.com                SyscallExecutor sys_exec=unimplementedFunc, int flags=0)
7512855Sgabeblack@google.com        : _name(name), executor(sys_exec), _flags(flags), _warned(false)
7612855Sgabeblack@google.com    {
7712855Sgabeblack@google.com    }
7812855Sgabeblack@google.com
7912855Sgabeblack@google.com    /** Provide a mechanism to specify behavior for abnormal system calls */
8012855Sgabeblack@google.com    enum Flags {
8112855Sgabeblack@google.com        /**
8212855Sgabeblack@google.com         * Do not set return registers according to executor return value.
8312855Sgabeblack@google.com         * Used for system calls with non-standard return conventions that
8412855Sgabeblack@google.com         * explicitly set the thread context regs (e.g., sigreturn, clone)
8512855Sgabeblack@google.com         */
8612855Sgabeblack@google.com        SuppressReturnValue = 1,
8712855Sgabeblack@google.com        /** Warn only once for unimplemented system calls */
8812855Sgabeblack@google.com        WarnOnce = 2
8912855Sgabeblack@google.com        /* X2 = 4, // Remove these comments when the next field is added; */
9012855Sgabeblack@google.com        /* X3 = 8, // point is to make it obvious that this defines vector */
9112855Sgabeblack@google.com    };
9212855Sgabeblack@google.com
9312855Sgabeblack@google.com    /**
9412855Sgabeblack@google.com     * Interface for invoking the system call funcion pointer. Note that
9512855Sgabeblack@google.com     * this acts as a gateway for all system calls and serves a good point
9612855Sgabeblack@google.com     * to add filters for behaviors or apply checks for all system calls.
9712855Sgabeblack@google.com     * @param callnum Number associated with call (by operating system)
9812855Sgabeblack@google.com     * @param proc Handle for the owning Process to pass information
9912855Sgabeblack@google.com     * @param tc Handle for owning ThreadContext to pass information
10012855Sgabeblack@google.com     */
10112855Sgabeblack@google.com    void doSyscall(int callnum, Process *proc, ThreadContext *tc,
10212855Sgabeblack@google.com                   Fault *fault);
10312855Sgabeblack@google.com
10412855Sgabeblack@google.com    /**
10512855Sgabeblack@google.com     * Return false if WarnOnce is set and a warning has already been issued.
10612855Sgabeblack@google.com     * Otherwise, return true. Updates state as a side effect to help
10712855Sgabeblack@google.com     * keep track of issued warnings.
10812855Sgabeblack@google.com     */
10912855Sgabeblack@google.com    bool needWarning();
11012855Sgabeblack@google.com
11112855Sgabeblack@google.com    bool warnOnce() const { return (_flags & WarnOnce); }
11212855Sgabeblack@google.com
11312855Sgabeblack@google.com    std::string name() { return _name; }
114
115    int getFlags() const { return _flags; }
116
117    void setFlags(int flags) { _flags = flags; }
118
119  private:
120    /** System call name (e.g., open, mmap, clone, socket, etc.) */
121    std::string _name;
122
123    /** Mechanism for ISAs to connect to the emul function definitions */
124    SyscallExecutor executor;
125
126    /**
127     * Holds values set with the preceding enum; note that this has been
128     * used primarily for features that are mutually exclusive, but there's
129     * no reason that this needs to be true going forward.
130     */
131    int _flags;
132
133    /** Set if WarnOnce is specified in flags AFTER first call */
134    bool _warned;
135};
136
137#endif // __SIM_SYSCALL_DESC_HH__
138