1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc. 2 Contributed by Oracle. 3 4 This file is part of GNU Binutils. 5 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) 9 any later version. 10 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. 15 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. */ 20 21 #ifndef _DATA_WINDOW_H 22 #define _DATA_WINDOW_H 23 24 // The Data_window class hiearchy is used to access raw data in the 25 // experiment record. 26 // 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. 30 31 #include "util.h" 32 33 class Data_window 34 { 35 public: 36 37 // Span in data file 38 typedef struct 39 { 40 int64_t offset; // file offset 41 int64_t length; // span length 42 } Span; 43 44 Data_window (char *filename); 45 ~Data_window (); 46 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); 54 not_opened()55 bool not_opened () { return !opened; } get_fsize()56 off64_t get_fsize () { return fsize; } 57 58 template <typename Key_t> inline Key_t get_align_val(Key_t * vp)59 get_align_val (Key_t *vp) 60 { 61 if (sizeof (Key_t) <= sizeof (int)) 62 return *vp; 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); 67 p2[0] = p1[0]; 68 p2[1] = p1[1]; 69 return val; 70 } 71 72 template <typename Key_t> inline Key_t decode(Key_t & v)73 decode (Key_t &v) 74 { 75 Key_t val = get_align_val (&v); 76 if (need_swap_endian) 77 swapByteOrder (&val, sizeof (val)); 78 return val; 79 } 80 81 bool need_swap_endian; 82 char *fname; // file name 83 84 protected: 85 int fd; // file descriptor 86 bool mmap_on_file; 87 88 private: 89 long page_size; // used in mmap() 90 bool use_mmap; 91 bool opened; 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 97 }; 98 99 #endif /* _DATA_WINDOW_H */ 100