-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileImageSegment.h
More file actions
56 lines (44 loc) · 1.52 KB
/
FileImageSegment.h
File metadata and controls
56 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright (c) 2019-2026 Javier Pimás, Jan Vrany, Labware.
See (MIT) license in root directory.
*/
#ifndef _FILE_IMAGE_SEGMENT_H_
#define _FILE_IMAGE_SEGMENT_H_
#include <iostream>
#include <vector>
#include "ImageSegment.h"
namespace Egg
{
/**
* An ImageSegment loaded from an .ems file on disk.
* Handles reading, pointer relocation, and import resolution.
*/
class FileImageSegment : public ImageSegment
{
public:
std::vector<std::string> _importStrings;
std::vector<std::vector<uint32_t>> _importDescriptors;
FileImageSegment(std::istream* data);
/**
* Allocate a new segment of given `size` at given `base` address.
* Contents of the segment is zeroed.
* Return value is address allocated when passed null as base.
*/
uintptr_t alloc(uintptr_t base, size_t size);
/**
* Traverses the image segment space looking for pointers.
* - References to other objects in same space need to be relocated.
* - References to imports (last two bits are 10b) are indices in import table,
* and need to be changed to actual object addresses.
*/
void fixPointerSlots(const std::vector<Object*> &imports);
std::string& importStringAt_(uint32_t index);
HeapObject* relocatedAddress_(const HeapObject* object);
private:
void load(std::istream* data);
void readImportStrings(std::istream *data);
void readImportDescriptors(std::istream *data);
void readExports(std::istream *data);
};
} // namespace Egg
#endif // _FILE_IMAGE_SEGMENT_H_