syscall_desc.hh revision 11877
15643Sgblack@eecs.umich.edu/*
25643Sgblack@eecs.umich.edu * Copyright (c) 2012-2013, 2015 ARM Limited
35643Sgblack@eecs.umich.edu * Copyright (c) 2015-2016 Advanced Micro Devices, Inc.
45643Sgblack@eecs.umich.edu * All rights reserved
55643Sgblack@eecs.umich.edu *
65643Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
75643Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
85643Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
95643Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
105643Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
115643Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
125643Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
135643Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
145643Sgblack@eecs.umich.edu *
155643Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
165643Sgblack@eecs.umich.edu * All rights reserved.
175643Sgblack@eecs.umich.edu *
185643Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
195643Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
205643Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
215643Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
225643Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
235643Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
245643Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
255643Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
265643Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
275643Sgblack@eecs.umich.edu * this software without specific prior written permission.
285643Sgblack@eecs.umich.edu *
295643Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
305643Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
315643Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
325643Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
335643Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
345643Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
355643Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
365643Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
375643Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
385643Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
395643Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
405643Sgblack@eecs.umich.edu *
415643Sgblack@eecs.umich.edu * Authors: Steve Reinhardt
425643Sgblack@eecs.umich.edu *          Kevin Lim
435643Sgblack@eecs.umich.edu *          Brandon Potter
445643Sgblack@eecs.umich.edu */
455643Sgblack@eecs.umich.edu
465643Sgblack@eecs.umich.edu#ifndef __SIM_SYSCALL_DESC_HH__
475643Sgblack@eecs.umich.edu#define __SIM_SYSCALL_DESC_HH__
485643Sgblack@eecs.umich.edu
495643Sgblack@eecs.umich.edu#include <string>
505643Sgblack@eecs.umich.edu
515643Sgblack@eecs.umich.edu#include "base/types.hh"
525643Sgblack@eecs.umich.edu
535643Sgblack@eecs.umich.educlass Process;
545643Sgblack@eecs.umich.educlass SyscallReturn;
555643Sgblack@eecs.umich.educlass ThreadContext;
565643Sgblack@eecs.umich.edu
575643Sgblack@eecs.umich.edu/**
585643Sgblack@eecs.umich.edu * This class provides the wrapper interface for the system call
595643Sgblack@eecs.umich.edu * implementations which are defined in the sim/syscall_emul files and
605643Sgblack@eecs.umich.edu * bound to the ISAs in the architecture specific code
615643Sgblack@eecs.umich.edu * (i.e. arch/X86/linux/process.cc).
625643Sgblack@eecs.umich.edu */
635643Sgblack@eecs.umich.educlass SyscallDesc {
645643Sgblack@eecs.umich.edu  public:
655643Sgblack@eecs.umich.edu    /** Typedef the function pointer here to clean up code below */
665643Sgblack@eecs.umich.edu    typedef SyscallReturn (*SyscallExecutor)(SyscallDesc*, int num,
675643Sgblack@eecs.umich.edu                                             Process*, ThreadContext*);
685643Sgblack@eecs.umich.edu
695643Sgblack@eecs.umich.edu    SyscallDesc(const char *name, SyscallExecutor sys_exec, int flags = 0)
705643Sgblack@eecs.umich.edu        : _name(name), executor(sys_exec), _flags(flags), _warned(false)
715643Sgblack@eecs.umich.edu    {
725643Sgblack@eecs.umich.edu    }
735643Sgblack@eecs.umich.edu
745643Sgblack@eecs.umich.edu    /** Provide a mechanism to specify behavior for abnormal system calls */
755643Sgblack@eecs.umich.edu    enum Flags {
765643Sgblack@eecs.umich.edu        /**
775643Sgblack@eecs.umich.edu         * Do not set return registers according to executor return value.
785643Sgblack@eecs.umich.edu         * Used for system calls with non-standard return conventions that
795643Sgblack@eecs.umich.edu         * explicitly set the thread context regs (e.g., sigreturn, clone)
805643Sgblack@eecs.umich.edu         */
815643Sgblack@eecs.umich.edu        SuppressReturnValue = 1,
825643Sgblack@eecs.umich.edu        /** Warn only once for unimplemented system calls */
835643Sgblack@eecs.umich.edu        WarnOnce = 2
845643Sgblack@eecs.umich.edu        /* X2 = 4, // Remove these comments when the next field is added; */
855643Sgblack@eecs.umich.edu        /* X3 = 8, // point is to make it obvious that this defines vector */
865643Sgblack@eecs.umich.edu    };
875643Sgblack@eecs.umich.edu
885643Sgblack@eecs.umich.edu    /**
895643Sgblack@eecs.umich.edu     * Interface for invoking the system call funcion pointer. Note that
905643Sgblack@eecs.umich.edu     * this acts as a gateway for all system calls and serves a good point
915643Sgblack@eecs.umich.edu     * to add filters for behaviors or apply checks for all system calls.
925643Sgblack@eecs.umich.edu     * @param callnum Number associated with call (by operating system)
935643Sgblack@eecs.umich.edu     * @param proc Handle for the owning Process to pass information
945643Sgblack@eecs.umich.edu     * @param tc Handle for owning ThreadContext to pass information
955643Sgblack@eecs.umich.edu     */
965643Sgblack@eecs.umich.edu    void doSyscall(int callnum, Process *proc, ThreadContext *tc,
975643Sgblack@eecs.umich.edu                   Fault *fault);
985643Sgblack@eecs.umich.edu
995643Sgblack@eecs.umich.edu    /**
1005643Sgblack@eecs.umich.edu     * Return false if WarnOnce is set and a warning has already been issued.
1015643Sgblack@eecs.umich.edu     * Otherwise, return true. Updates state as a side effect to help
1025643Sgblack@eecs.umich.edu     * keep track of issued warnings.
1035643Sgblack@eecs.umich.edu     */
1045643Sgblack@eecs.umich.edu    bool needWarning();
1055643Sgblack@eecs.umich.edu
1065643Sgblack@eecs.umich.edu    bool warnOnce() const { return (_flags & WarnOnce); }
107
108    std::string name() { return _name; }
109
110  private:
111    /** System call name (e.g., open, mmap, clone, socket, etc.) */
112    std::string _name;
113
114    /** Mechanism for ISAs to connect to the emul function definitions */
115    SyscallExecutor executor;
116
117    /**
118     * Holds values set with the preceding enum; note that this has been
119     * used primarily for features that are mutually exclusive, but there's
120     * no reason that this needs to be true going forward.
121     */
122    int _flags;
123
124    /** Set if WarnOnce is specified in flags AFTER first call */
125    bool _warned;
126};
127
128#endif // __SIM_SYSCALL_DESC_HH__
129