Deleted Added
sdiff udiff text old ( 11800:54436a1784dc ) new ( 11856:103e2f92c965 )
full compact
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/serialize.hh"
39
40class EmulatedDriver;
41
42/**
43 * FDEntry is used to manage a single file descriptor mapping and metadata
44 * for processes.
45 * Note that the fields are all declared publicly since system calls have a
46 * habit of only needing to access a single field at a time and accessor
47 * methods seem like overkill.
48 */
49class FDEntry : public Serializable
50{
51 public:
52 /**
53 * Constructor contains default values
54 * The file descriptor is free.
55 */
56 FDEntry()
57 : fd(-1), mode(0), flags(0), isPipe(false), readPipeSource(0),
58 fileOffset(0), filename(""), driver(NULL)
59 { }
60
61 void serialize(CheckpointOut &cp) const override;
62 void unserialize(CheckpointIn &cp) override;
63
64 /**
65 * Check if the target file descriptor is in use.
66 * @return value denoting if target file descriptor already used
67 */
68 bool isFree();
69
70 /**
71 * Fill in members for this file descriptor entry.
72 * @param sim_fd host file descriptor
73 * @param name filename string
74 * @param flags current flags of the file descriptor
75 * @param mode current mode of the file descriptor
76 * @param pipe denotes whether the file descriptor belongs to a pipe
77 */
78 void set(int sim_fd, const std::string name, int flags, int mode,
79 bool pipe);
80
81 /** Reset members to their default values. */
82 void reset();
83
84 int fd;
85 int mode;
86 int flags;
87 bool isPipe;
88 int readPipeSource;
89 uint64_t fileOffset;
90 std::string filename;
91 EmulatedDriver *driver;
92};
93
94#endif // __FD_ENTRY_HH__