fd_entry.hh revision 10930
1/* 2 * Copyright (c) 2015 Advanced Micro Devices, Inc. 3 * Copyright (c) 2001-2005 The Regents of The University of Michigan 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 */ 31 32#ifndef __FD_ENTRY_HH__ 33#define __FD_ENTRY_HH__ 34 35#include <ostream> 36#include <string> 37 38#include "sim/emul_driver.hh" 39 40/** 41 * FDEntry is used to manage a single file descriptor mapping and metadata 42 * for processes. 43 * Note that the fields are all declared publicly since system calls have a 44 * habit of only needing to access a single field at a time and accessor 45 * methods seem like overkill. 46 */ 47class FDEntry : public Serializable 48{ 49 public: 50 /** 51 * Constructor contains default values 52 * The file descriptor is free. 53 */ 54 FDEntry() 55 : fd(-1), mode(0), flags(0), isPipe(false), readPipeSource(0), 56 fileOffset(0), filename(""), driver(NULL) 57 { } 58 59 void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 60 void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 61 62 /** 63 * Check if the target file descriptor is in use. 64 * @return value denoting if target file descriptor already used 65 */ 66 bool isFree(); 67 68 /** 69 * Fill in members for this file descriptor entry. 70 * @param sim_fd host file descriptor 71 * @param name filename string 72 * @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