fd_entry.hh revision 11800
110930Sbrandon.potter@amd.com/*
210930Sbrandon.potter@amd.com * Copyright (c) 2015 Advanced Micro Devices, Inc.
310930Sbrandon.potter@amd.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
410930Sbrandon.potter@amd.com *
510930Sbrandon.potter@amd.com * Redistribution and use in source and binary forms, with or without
610930Sbrandon.potter@amd.com * modification, are permitted provided that the following conditions are
710930Sbrandon.potter@amd.com * met: redistributions of source code must retain the above copyright
810930Sbrandon.potter@amd.com * notice, this list of conditions and the following disclaimer;
910930Sbrandon.potter@amd.com * redistributions in binary form must reproduce the above copyright
1010930Sbrandon.potter@amd.com * notice, this list of conditions and the following disclaimer in the
1110930Sbrandon.potter@amd.com * documentation and/or other materials provided with the distribution;
1210930Sbrandon.potter@amd.com * neither the name of the copyright holders nor the names of its
1310930Sbrandon.potter@amd.com * contributors may be used to endorse or promote products derived from
1410930Sbrandon.potter@amd.com * this software without specific prior written permission.
1510930Sbrandon.potter@amd.com *
1610930Sbrandon.potter@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710930Sbrandon.potter@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810930Sbrandon.potter@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910930Sbrandon.potter@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010930Sbrandon.potter@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110930Sbrandon.potter@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210930Sbrandon.potter@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310930Sbrandon.potter@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410930Sbrandon.potter@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510930Sbrandon.potter@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610930Sbrandon.potter@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710930Sbrandon.potter@amd.com *
2810930Sbrandon.potter@amd.com * Authors: Nathan Binkert
2910930Sbrandon.potter@amd.com *          Steve Reinhardt
3010930Sbrandon.potter@amd.com */
3110930Sbrandon.potter@amd.com
3210930Sbrandon.potter@amd.com#ifndef __FD_ENTRY_HH__
3310930Sbrandon.potter@amd.com#define __FD_ENTRY_HH__
3410930Sbrandon.potter@amd.com
3510930Sbrandon.potter@amd.com#include <ostream>
3610930Sbrandon.potter@amd.com#include <string>
3710930Sbrandon.potter@amd.com
3811800Sbrandon.potter@amd.com#include "sim/serialize.hh"
3911800Sbrandon.potter@amd.com
4011800Sbrandon.potter@amd.comclass EmulatedDriver;
4110930Sbrandon.potter@amd.com
4210930Sbrandon.potter@amd.com/**
4310930Sbrandon.potter@amd.com * FDEntry is used to manage a single file descriptor mapping and metadata
4410930Sbrandon.potter@amd.com * for processes.
4510930Sbrandon.potter@amd.com * Note that the fields are all declared publicly since system calls have a
4610930Sbrandon.potter@amd.com * habit of only needing to access a single field at a time and accessor
4710930Sbrandon.potter@amd.com * methods seem like overkill.
4810930Sbrandon.potter@amd.com */
4910930Sbrandon.potter@amd.comclass FDEntry : public Serializable
5010930Sbrandon.potter@amd.com{
5110930Sbrandon.potter@amd.com  public:
5210930Sbrandon.potter@amd.com    /**
5310930Sbrandon.potter@amd.com     * Constructor contains default values
5410930Sbrandon.potter@amd.com     * The file descriptor is free.
5510930Sbrandon.potter@amd.com     */
5610930Sbrandon.potter@amd.com    FDEntry()
5710930Sbrandon.potter@amd.com        : fd(-1), mode(0), flags(0), isPipe(false), readPipeSource(0),
5810930Sbrandon.potter@amd.com          fileOffset(0), filename(""), driver(NULL)
5910930Sbrandon.potter@amd.com    { }
6010930Sbrandon.potter@amd.com
6111168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
6211168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
6310930Sbrandon.potter@amd.com
6410930Sbrandon.potter@amd.com    /**
6510930Sbrandon.potter@amd.com     * Check if the target file descriptor is in use.
6610930Sbrandon.potter@amd.com     * @return value denoting if target file descriptor already used
6710930Sbrandon.potter@amd.com     */
6810930Sbrandon.potter@amd.com    bool isFree();
6910930Sbrandon.potter@amd.com
7010930Sbrandon.potter@amd.com    /**
7110930Sbrandon.potter@amd.com     * Fill in members for this file descriptor entry.
7210930Sbrandon.potter@amd.com     * @param sim_fd host file descriptor
7310930Sbrandon.potter@amd.com     * @param name filename string
7410930Sbrandon.potter@amd.com     * @param flags current flags of the file descriptor
7510930Sbrandon.potter@amd.com     * @param mode current mode of the file descriptor
7610930Sbrandon.potter@amd.com     * @param pipe denotes whether the file descriptor belongs to a pipe
7710930Sbrandon.potter@amd.com     */
7810930Sbrandon.potter@amd.com    void set(int sim_fd, const std::string name, int flags, int mode,
7910930Sbrandon.potter@amd.com             bool pipe);
8010930Sbrandon.potter@amd.com
8110930Sbrandon.potter@amd.com    /** Reset members to their default values. */
8210930Sbrandon.potter@amd.com    void reset();
8310930Sbrandon.potter@amd.com
8410930Sbrandon.potter@amd.com    int fd;
8510930Sbrandon.potter@amd.com    int mode;
8610930Sbrandon.potter@amd.com    int flags;
8710930Sbrandon.potter@amd.com    bool isPipe;
8810930Sbrandon.potter@amd.com    int readPipeSource;
8910930Sbrandon.potter@amd.com    uint64_t fileOffset;
9010930Sbrandon.potter@amd.com    std::string filename;
9110930Sbrandon.potter@amd.com    EmulatedDriver *driver;
9210930Sbrandon.potter@amd.com};
9310930Sbrandon.potter@amd.com
9410930Sbrandon.potter@amd.com#endif // __FD_ENTRY_HH__
95