syscall_desc.hh revision 11886
111794Sbrandon.potter@amd.com/*
211794Sbrandon.potter@amd.com * Copyright (c) 2012-2013, 2015 ARM Limited
311794Sbrandon.potter@amd.com * Copyright (c) 2015-2016 Advanced Micro Devices, Inc.
411794Sbrandon.potter@amd.com * All rights reserved
511794Sbrandon.potter@amd.com *
611794Sbrandon.potter@amd.com * The license below extends only to copyright in the software and shall
711794Sbrandon.potter@amd.com * not be construed as granting a license to any other intellectual
811794Sbrandon.potter@amd.com * property including but not limited to intellectual property relating
911794Sbrandon.potter@amd.com * to a hardware implementation of the functionality of the software
1011794Sbrandon.potter@amd.com * licensed hereunder.  You may use the software subject to the license
1111794Sbrandon.potter@amd.com * terms below provided that you ensure that this notice is replicated
1211794Sbrandon.potter@amd.com * unmodified and in its entirety in all distributions of the software,
1311794Sbrandon.potter@amd.com * modified or unmodified, in source code or in binary form.
1411794Sbrandon.potter@amd.com *
1511794Sbrandon.potter@amd.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
1611794Sbrandon.potter@amd.com * All rights reserved.
1711794Sbrandon.potter@amd.com *
1811794Sbrandon.potter@amd.com * Redistribution and use in source and binary forms, with or without
1911794Sbrandon.potter@amd.com * modification, are permitted provided that the following conditions are
2011794Sbrandon.potter@amd.com * met: redistributions of source code must retain the above copyright
2111794Sbrandon.potter@amd.com * notice, this list of conditions and the following disclaimer;
2211794Sbrandon.potter@amd.com * redistributions in binary form must reproduce the above copyright
2311794Sbrandon.potter@amd.com * notice, this list of conditions and the following disclaimer in the
2411794Sbrandon.potter@amd.com * documentation and/or other materials provided with the distribution;
2511794Sbrandon.potter@amd.com * neither the name of the copyright holders nor the names of its
2611794Sbrandon.potter@amd.com * contributors may be used to endorse or promote products derived from
2711794Sbrandon.potter@amd.com * this software without specific prior written permission.
2811794Sbrandon.potter@amd.com *
2911794Sbrandon.potter@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3011794Sbrandon.potter@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3111794Sbrandon.potter@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3211794Sbrandon.potter@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3311794Sbrandon.potter@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3411794Sbrandon.potter@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3511794Sbrandon.potter@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3611794Sbrandon.potter@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3711794Sbrandon.potter@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3811794Sbrandon.potter@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3911794Sbrandon.potter@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4011794Sbrandon.potter@amd.com *
4111794Sbrandon.potter@amd.com * Authors: Steve Reinhardt
4211794Sbrandon.potter@amd.com *          Kevin Lim
4311794Sbrandon.potter@amd.com *          Brandon Potter
4411794Sbrandon.potter@amd.com */
4511794Sbrandon.potter@amd.com
4611794Sbrandon.potter@amd.com#ifndef __SIM_SYSCALL_DESC_HH__
4711794Sbrandon.potter@amd.com#define __SIM_SYSCALL_DESC_HH__
4811794Sbrandon.potter@amd.com
4911794Sbrandon.potter@amd.com#include <string>
5011794Sbrandon.potter@amd.com
5111877Sbrandon.potter@amd.com#include "base/types.hh"
5211877Sbrandon.potter@amd.com
5311851Sbrandon.potter@amd.comclass Process;
5411794Sbrandon.potter@amd.comclass SyscallReturn;
5511794Sbrandon.potter@amd.comclass ThreadContext;
5611794Sbrandon.potter@amd.com
5711794Sbrandon.potter@amd.com/**
5811794Sbrandon.potter@amd.com * This class provides the wrapper interface for the system call
5911794Sbrandon.potter@amd.com * implementations which are defined in the sim/syscall_emul files and
6011794Sbrandon.potter@amd.com * bound to the ISAs in the architecture specific code
6111794Sbrandon.potter@amd.com * (i.e. arch/X86/linux/process.cc).
6211794Sbrandon.potter@amd.com */
6311794Sbrandon.potter@amd.comclass SyscallDesc {
6411794Sbrandon.potter@amd.com  public:
6511794Sbrandon.potter@amd.com    /** Typedef the function pointer here to clean up code below */
6611794Sbrandon.potter@amd.com    typedef SyscallReturn (*SyscallExecutor)(SyscallDesc*, int num,
6711851Sbrandon.potter@amd.com                                             Process*, ThreadContext*);
6811794Sbrandon.potter@amd.com
6911794Sbrandon.potter@amd.com    SyscallDesc(const char *name, SyscallExecutor sys_exec, int flags = 0)
7011794Sbrandon.potter@amd.com        : _name(name), executor(sys_exec), _flags(flags), _warned(false)
7111794Sbrandon.potter@amd.com    {
7211794Sbrandon.potter@amd.com    }
7311794Sbrandon.potter@amd.com
7411794Sbrandon.potter@amd.com    /** Provide a mechanism to specify behavior for abnormal system calls */
7511794Sbrandon.potter@amd.com    enum Flags {
7611794Sbrandon.potter@amd.com        /**
7711794Sbrandon.potter@amd.com         * Do not set return registers according to executor return value.
7811794Sbrandon.potter@amd.com         * Used for system calls with non-standard return conventions that
7911794Sbrandon.potter@amd.com         * explicitly set the thread context regs (e.g., sigreturn, clone)
8011794Sbrandon.potter@amd.com         */
8111794Sbrandon.potter@amd.com        SuppressReturnValue = 1,
8211794Sbrandon.potter@amd.com        /** Warn only once for unimplemented system calls */
8311794Sbrandon.potter@amd.com        WarnOnce = 2
8411794Sbrandon.potter@amd.com        /* X2 = 4, // Remove these comments when the next field is added; */
8511794Sbrandon.potter@amd.com        /* X3 = 8, // point is to make it obvious that this defines vector */
8611794Sbrandon.potter@amd.com    };
8711794Sbrandon.potter@amd.com
8811794Sbrandon.potter@amd.com    /**
8911794Sbrandon.potter@amd.com     * Interface for invoking the system call funcion pointer. Note that
9011794Sbrandon.potter@amd.com     * this acts as a gateway for all system calls and serves a good point
9111794Sbrandon.potter@amd.com     * to add filters for behaviors or apply checks for all system calls.
9211794Sbrandon.potter@amd.com     * @param callnum Number associated with call (by operating system)
9311794Sbrandon.potter@amd.com     * @param proc Handle for the owning Process to pass information
9411794Sbrandon.potter@amd.com     * @param tc Handle for owning ThreadContext to pass information
9511794Sbrandon.potter@amd.com     */
9611877Sbrandon.potter@amd.com    void doSyscall(int callnum, Process *proc, ThreadContext *tc,
9711877Sbrandon.potter@amd.com                   Fault *fault);
9811794Sbrandon.potter@amd.com
9911794Sbrandon.potter@amd.com    /**
10011794Sbrandon.potter@amd.com     * Return false if WarnOnce is set and a warning has already been issued.
10111794Sbrandon.potter@amd.com     * Otherwise, return true. Updates state as a side effect to help
10211794Sbrandon.potter@amd.com     * keep track of issued warnings.
10311794Sbrandon.potter@amd.com     */
10411794Sbrandon.potter@amd.com    bool needWarning();
10511794Sbrandon.potter@amd.com
10611794Sbrandon.potter@amd.com    bool warnOnce() const { return (_flags & WarnOnce); }
10711794Sbrandon.potter@amd.com
10811794Sbrandon.potter@amd.com    std::string name() { return _name; }
10911794Sbrandon.potter@amd.com
11011886Sbrandon.potter@amd.com    int getFlags() const { return _flags; }
11111886Sbrandon.potter@amd.com
11211886Sbrandon.potter@amd.com    void setFlags(int flags) { _flags = flags; }
11311886Sbrandon.potter@amd.com
11411794Sbrandon.potter@amd.com  private:
11511794Sbrandon.potter@amd.com    /** System call name (e.g., open, mmap, clone, socket, etc.) */
11611794Sbrandon.potter@amd.com    std::string _name;
11711794Sbrandon.potter@amd.com
11811794Sbrandon.potter@amd.com    /** Mechanism for ISAs to connect to the emul function definitions */
11911794Sbrandon.potter@amd.com    SyscallExecutor executor;
12011794Sbrandon.potter@amd.com
12111794Sbrandon.potter@amd.com    /**
12211794Sbrandon.potter@amd.com     * Holds values set with the preceding enum; note that this has been
12311794Sbrandon.potter@amd.com     * used primarily for features that are mutually exclusive, but there's
12411794Sbrandon.potter@amd.com     * no reason that this needs to be true going forward.
12511794Sbrandon.potter@amd.com     */
12611794Sbrandon.potter@amd.com    int _flags;
12711794Sbrandon.potter@amd.com
12811794Sbrandon.potter@amd.com    /** Set if WarnOnce is specified in flags AFTER first call */
12911794Sbrandon.potter@amd.com    bool _warned;
13011794Sbrandon.potter@amd.com};
13111794Sbrandon.potter@amd.com
13211794Sbrandon.potter@amd.com#endif // __SIM_SYSCALL_DESC_HH__
133