syscall_desc.hh revision 11877
12623SN/A/*
22623SN/A * Copyright (c) 2012-2013, 2015 ARM Limited
32623SN/A * Copyright (c) 2015-2016 Advanced Micro Devices, Inc.
42623SN/A * All rights reserved
52623SN/A *
62623SN/A * The license below extends only to copyright in the software and shall
72623SN/A * not be construed as granting a license to any other intellectual
82623SN/A * property including but not limited to intellectual property relating
92623SN/A * to a hardware implementation of the functionality of the software
102623SN/A * licensed hereunder.  You may use the software subject to the license
112623SN/A * terms below provided that you ensure that this notice is replicated
122623SN/A * unmodified and in its entirety in all distributions of the software,
132623SN/A * modified or unmodified, in source code or in binary form.
142623SN/A *
152623SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
162623SN/A * All rights reserved.
172623SN/A *
182623SN/A * Redistribution and use in source and binary forms, with or without
192623SN/A * modification, are permitted provided that the following conditions are
202623SN/A * met: redistributions of source code must retain the above copyright
212623SN/A * notice, this list of conditions and the following disclaimer;
222623SN/A * redistributions in binary form must reproduce the above copyright
232623SN/A * notice, this list of conditions and the following disclaimer in the
242623SN/A * documentation and/or other materials provided with the distribution;
252623SN/A * neither the name of the copyright holders nor the names of its
262623SN/A * contributors may be used to endorse or promote products derived from
272665Ssaidi@eecs.umich.edu * this software without specific prior written permission.
282665Ssaidi@eecs.umich.edu *
292623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402623SN/A *
412623SN/A * Authors: Steve Reinhardt
422623SN/A *          Kevin Lim
432623SN/A *          Brandon Potter
442623SN/A */
452623SN/A
462623SN/A#ifndef __SIM_SYSCALL_DESC_HH__
472623SN/A#define __SIM_SYSCALL_DESC_HH__
482623SN/A
492623SN/A#include <string>
502623SN/A
512623SN/A#include "base/types.hh"
522623SN/A
532623SN/Aclass Process;
542623SN/Aclass SyscallReturn;
552623SN/Aclass ThreadContext;
562623SN/A
572623SN/A/**
582623SN/A * This class provides the wrapper interface for the system call
592623SN/A * implementations which are defined in the sim/syscall_emul files and
602623SN/A * bound to the ISAs in the architecture specific code
612623SN/A * (i.e. arch/X86/linux/process.cc).
622623SN/A */
632623SN/Aclass SyscallDesc {
642623SN/A  public:
652630SN/A    /** Typedef the function pointer here to clean up code below */
662623SN/A    typedef SyscallReturn (*SyscallExecutor)(SyscallDesc*, int num,
672623SN/A                                             Process*, ThreadContext*);
682623SN/A
692623SN/A    SyscallDesc(const char *name, SyscallExecutor sys_exec, int flags = 0)
702623SN/A        : _name(name), executor(sys_exec), _flags(flags), _warned(false)
712623SN/A    {
722630SN/A    }
732623SN/A
742623SN/A    /** Provide a mechanism to specify behavior for abnormal system calls */
752623SN/A    enum Flags {
762623SN/A        /**
772623SN/A         * Do not set return registers according to executor return value.
782623SN/A         * Used for system calls with non-standard return conventions that
792623SN/A         * explicitly set the thread context regs (e.g., sigreturn, clone)
802631SN/A         */
812631SN/A        SuppressReturnValue = 1,
822631SN/A        /** Warn only once for unimplemented system calls */
832623SN/A        WarnOnce = 2
842623SN/A        /* X2 = 4, // Remove these comments when the next field is added; */
852623SN/A        /* X3 = 8, // point is to make it obvious that this defines vector */
862623SN/A    };
872623SN/A
882623SN/A    /**
892623SN/A     * Interface for invoking the system call funcion pointer. Note that
902623SN/A     * this acts as a gateway for all system calls and serves a good point
912623SN/A     * to add filters for behaviors or apply checks for all system calls.
922623SN/A     * @param callnum Number associated with call (by operating system)
932623SN/A     * @param proc Handle for the owning Process to pass information
942623SN/A     * @param tc Handle for owning ThreadContext to pass information
952623SN/A     */
962623SN/A    void doSyscall(int callnum, Process *proc, ThreadContext *tc,
972623SN/A                   Fault *fault);
982623SN/A
992623SN/A    /**
1002623SN/A     * Return false if WarnOnce is set and a warning has already been issued.
1012623SN/A     * Otherwise, return true. Updates state as a side effect to help
1022623SN/A     * keep track of issued warnings.
1032623SN/A     */
1042623SN/A    bool needWarning();
1052623SN/A
1062623SN/A    bool warnOnce() const { return (_flags & WarnOnce); }
1072623SN/A
1082623SN/A    std::string name() { return _name; }
1092623SN/A
1102623SN/A  private:
1112623SN/A    /** System call name (e.g., open, mmap, clone, socket, etc.) */
1122623SN/A    std::string _name;
1132623SN/A
1142623SN/A    /** Mechanism for ISAs to connect to the emul function definitions */
1152623SN/A    SyscallExecutor executor;
1162623SN/A
1172623SN/A    /**
1182623SN/A     * Holds values set with the preceding enum; note that this has been
1192623SN/A     * used primarily for features that are mutually exclusive, but there's
1202623SN/A     * no reason that this needs to be true going forward.
1212623SN/A     */
1222623SN/A    int _flags;
1232623SN/A
1242623SN/A    /** Set if WarnOnce is specified in flags AFTER first call */
1252623SN/A    bool _warned;
1262623SN/A};
1272623SN/A
1282623SN/A#endif // __SIM_SYSCALL_DESC_HH__
1292623SN/A