1/* Copyright (C) 2021 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 _HEAPMAP_H
22#define _HEAPMAP_H
23
24#include "dbe_types.h"
25#include "vec.h"
26
27struct HeapObj;
28struct HeapChunk;
29
30typedef struct UnmapChunk
31{
32  long val;
33  int64_t size;
34  UnmapChunk *next;
35} UnmapChunk;
36
37class HeapMap
38{
39public:
40  HeapMap ();
41  ~HeapMap ();
42  void allocate (uint64_t addr, long val);
43  long deallocate (uint64_t addr);
44  UnmapChunk *mmap (uint64_t addr, int64_t size, long val);
45  UnmapChunk *munmap (uint64_t addr, int64_t size);
46
47private:
48  void allocateChunk ();
49  HeapObj *getHeapObj ();
50  void releaseHeapObj (HeapObj*);
51  UnmapChunk *process (HeapObj *obj, uint64_t addr, int64_t size);
52
53  HeapChunk *chunks;
54  HeapObj *empty;
55  HeapObj **chain;
56  HeapObj *mmaps;
57};
58
59#endif /* _HEAPMAP_H */
60