1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #ifndef _DATA_WINDOW_H
22 #define _DATA_WINDOW_H
24 // The Data_window class hiearchy is used to access raw data in the
27 // The Data_window base class implements a set of windows into a raw data file.
28 // It is responsible for mapping and unmapping regions of the file as
29 // requested by other levels inside of the DBE.
40 int64_t offset; // file offset
41 int64_t length; // span length
44 Data_window (char *filename);
47 // Return address of "offset" byte of window for "length" bytes.
48 // Return 0 on error or locked.
49 void *bind (Span *span, int64_t minSize);
50 void *bind (int64_t file_offset, int64_t minSize);
51 void *get_data (int64_t offset, int64_t size, void *datap);
52 int64_t get_buf_size ();
53 int64_t copy_to_file (int f, int64_t offset, int64_t size);
55 bool not_opened () { return !opened; }
56 off64_t get_fsize () { return fsize; }
58 template <typename Key_t> inline Key_t
59 get_align_val (Key_t *vp)
61 if (sizeof (Key_t) <= sizeof (int))
63 // 64-bit value can have a wrong alignment
64 Key_t val = (Key_t) 0;
65 uint32_t *p1 = (uint32_t *) vp;
66 uint32_t *p2 = (uint32_t*) (&val);
72 template <typename Key_t> inline Key_t
75 Key_t val = get_align_val (&v);
77 swapByteOrder (&val, sizeof (val));
81 bool need_swap_endian;
82 char *fname; // file name
85 int fd; // file descriptor
89 long page_size; // used in mmap()
92 int64_t fsize; // file size
93 void *base; // current window
94 int64_t woffset; // offset of current window
95 int64_t wsize; // size of current window
96 int64_t basesize; // size of allocated window
99 #endif /* _DATA_WINDOW_H */