fd_entry.hh revision 10930:ddc3d96d6313
111723Sar4jc@virginia.edu/* 211723Sar4jc@virginia.edu * Copyright (c) 2015 Advanced Micro Devices, Inc. 311970Sar4jc@virginia.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan 411723Sar4jc@virginia.edu * 511723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without 611723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are 711723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright 811723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer; 911723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright 1011723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the 1111723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution; 1211723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its 1311723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from 1411723Sar4jc@virginia.edu * this software without specific prior written permission. 1511723Sar4jc@virginia.edu * 1611723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711723Sar4jc@virginia.edu * 2811723Sar4jc@virginia.edu * Authors: Nathan Binkert 2911723Sar4jc@virginia.edu * Steve Reinhardt 3011723Sar4jc@virginia.edu */ 3111970Sar4jc@virginia.edu 3211723Sar4jc@virginia.edu#ifndef __FD_ENTRY_HH__ 3311723Sar4jc@virginia.edu#define __FD_ENTRY_HH__ 3411723Sar4jc@virginia.edu 3511723Sar4jc@virginia.edu#include <ostream> 3611723Sar4jc@virginia.edu#include <string> 3711723Sar4jc@virginia.edu 3811723Sar4jc@virginia.edu#include "sim/emul_driver.hh" 3911723Sar4jc@virginia.edu 4011800Sbrandon.potter@amd.com/** 4111723Sar4jc@virginia.edu * FDEntry is used to manage a single file descriptor mapping and metadata 4211723Sar4jc@virginia.edu * for processes. 4311723Sar4jc@virginia.edu * Note that the fields are all declared publicly since system calls have a 4411723Sar4jc@virginia.edu * habit of only needing to access a single field at a time and accessor 4511723Sar4jc@virginia.edu * methods seem like overkill. 4611851Sbrandon.potter@amd.com */ 4711723Sar4jc@virginia.educlass FDEntry : public Serializable 4811723Sar4jc@virginia.edu{ 4911851Sbrandon.potter@amd.com public: 5011723Sar4jc@virginia.edu /** 5112030Sbrandon.potter@amd.com * Constructor contains default values 5211723Sar4jc@virginia.edu * The file descriptor is free. 5311723Sar4jc@virginia.edu */ 5411723Sar4jc@virginia.edu FDEntry() 5511723Sar4jc@virginia.edu : fd(-1), mode(0), flags(0), isPipe(false), readPipeSource(0), 5611723Sar4jc@virginia.edu fileOffset(0), filename(""), driver(NULL) 5712030Sbrandon.potter@amd.com { } 5811723Sar4jc@virginia.edu 5911851Sbrandon.potter@amd.com void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 6012030Sbrandon.potter@amd.com void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 6112030Sbrandon.potter@amd.com 6212030Sbrandon.potter@amd.com /** 6312030Sbrandon.potter@amd.com * Check if the target file descriptor is in use. 6411970Sar4jc@virginia.edu * @return value denoting if target file descriptor already used 6511970Sar4jc@virginia.edu */ 6611723Sar4jc@virginia.edu bool isFree(); 6711723Sar4jc@virginia.edu 6811723Sar4jc@virginia.edu /** 6911723Sar4jc@virginia.edu * Fill in members for this file descriptor entry. 7011723Sar4jc@virginia.edu * @param sim_fd host file descriptor 7111723Sar4jc@virginia.edu * @param name filename string 7211723Sar4jc@virginia.edu * @param flags current flags of the file descriptor 73 * @param mode current mode of the file descriptor 74 * @param pipe denotes whether the file descriptor belongs to a pipe 75 */ 76 void set(int sim_fd, const std::string name, int flags, int mode, 77 bool pipe); 78 79 /** Reset members to their default values. */ 80 void reset(); 81 82 int fd; 83 int mode; 84 int flags; 85 bool isPipe; 86 int readPipeSource; 87 uint64_t fileOffset; 88 std::string filename; 89 EmulatedDriver *driver; 90}; 91 92#endif // __FD_ENTRY_HH__ 93