fd_entry.cc revision 10930
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#include "base/misc.hh"
3310930Sbrandon.potter@amd.com#include "fd_entry.hh"
3410930Sbrandon.potter@amd.com
3510930Sbrandon.potter@amd.comusing namespace std;
3610930Sbrandon.potter@amd.com
3710930Sbrandon.potter@amd.comvoid
3810930Sbrandon.potter@amd.comFDEntry::serialize(CheckpointOut &cp) const
3910930Sbrandon.potter@amd.com{
4010930Sbrandon.potter@amd.com    SERIALIZE_SCALAR(fd);
4110930Sbrandon.potter@amd.com    if (fd != -1) {
4210930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(mode);
4310930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(flags);
4410930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(isPipe);
4510930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(readPipeSource);
4610930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(fileOffset);
4710930Sbrandon.potter@amd.com        SERIALIZE_SCALAR(filename);
4810930Sbrandon.potter@amd.com    }
4910930Sbrandon.potter@amd.com    if (driver)
5010930Sbrandon.potter@amd.com        warn("EmulatedDriver objects do not currently support checkpoints");
5110930Sbrandon.potter@amd.com}
5210930Sbrandon.potter@amd.com
5310930Sbrandon.potter@amd.comvoid
5410930Sbrandon.potter@amd.comFDEntry::unserialize(CheckpointIn &cp)
5510930Sbrandon.potter@amd.com{
5610930Sbrandon.potter@amd.com    UNSERIALIZE_SCALAR(fd);
5710930Sbrandon.potter@amd.com    if (fd != -1) {
5810930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(mode);
5910930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(flags);
6010930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(isPipe);
6110930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(readPipeSource);
6210930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(fileOffset);
6310930Sbrandon.potter@amd.com        UNSERIALIZE_SCALAR(filename);
6410930Sbrandon.potter@amd.com    }
6510930Sbrandon.potter@amd.com    driver = NULL;
6610930Sbrandon.potter@amd.com}
6710930Sbrandon.potter@amd.com
6810930Sbrandon.potter@amd.combool
6910930Sbrandon.potter@amd.comFDEntry::isFree()
7010930Sbrandon.potter@amd.com{
7110930Sbrandon.potter@amd.com    return (fd == -1 && driver == NULL);
7210930Sbrandon.potter@amd.com}
7310930Sbrandon.potter@amd.com
7410930Sbrandon.potter@amd.comvoid
7510930Sbrandon.potter@amd.comFDEntry::set(int sim_fd, const string name, int flags, int mode, bool pipe)
7610930Sbrandon.potter@amd.com{
7710930Sbrandon.potter@amd.com    fd = sim_fd;
7810930Sbrandon.potter@amd.com    filename = name;
7910930Sbrandon.potter@amd.com    this->flags = flags;
8010930Sbrandon.potter@amd.com    this->mode = mode;
8110930Sbrandon.potter@amd.com    isPipe = pipe;
8210930Sbrandon.potter@amd.com    fileOffset = 0;
8310930Sbrandon.potter@amd.com    readPipeSource = 0;
8410930Sbrandon.potter@amd.com    driver = NULL;
8510930Sbrandon.potter@amd.com}
8610930Sbrandon.potter@amd.com
8710930Sbrandon.potter@amd.comvoid
8810930Sbrandon.potter@amd.comFDEntry::reset()
8910930Sbrandon.potter@amd.com{
9010930Sbrandon.potter@amd.com    set(-1, "", 0, 0, false);
9110930Sbrandon.potter@amd.com}
92