-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageSegment.h
More file actions
69 lines (59 loc) · 1.75 KB
/
ImageSegment.h
File metadata and controls
69 lines (59 loc) · 1.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2020 Javier Pimas & LabWare
*
* This program and the accompanying materials are made available under
* the terms of the MIT license, see LICENSE file.
*
* SPDX-License-Identifier: MIT
*/
#ifndef IMAGESEGMENT_H_
#define IMAGESEGMENT_H_
#include <cstdint>
#include <iostream>
#include <iterator>
#include <HeapObject.h>
typedef struct _ImageSegmentHeader
{
/**
* Signature of a PST segment, must be following sequence:
* { 'P' , '_', 'I', 'M' , '_', 'S', '\n', '\0' }
*/
uint8_t signature[8];
/**
* Assumed base address at which segment is loaded, including
* its segment header. Implementations are free to load segment at
* any other address in which case object references (including the
* `entry_point_method` reference!) must be relocated prior use.
*/
uint64_t baseAddress;
/**
* Size of a segment including its header
*/
uint64_t size;
/**
* Amount of memory to be reserved when loading the segment
*/
uint64_t reservedSize;
/**
* A reference to Module instance describing this image segment
*/
HeapObject* module;
} ImageSegmentHeader;
static_assert(sizeof(ImageSegmentHeader) == 40 /*bytes*/,
"segment_header size not 40 bytes");
class ImageSegment
{
public:
ImageSegmentHeader header;
/**
* Allocate a new segment of given `size` at given `base` address.
* Contents of the segment is zeroed.
*/
static ImageSegment* alloc(uintptr_t base, size_t size);
/**
* Load a segment from given stream and return it. The stream should
* be positioned to the beginning of segment prior calling load()
*/
static ImageSegment* load(std::istream* data);
};
#endif // IMAGESEGMENT_H_