-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageSegment.cpp
More file actions
43 lines (33 loc) · 1009 Bytes
/
ImageSegment.cpp
File metadata and controls
43 lines (33 loc) · 1009 Bytes
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
/*
* 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
*/
#include "Util.h"
#include "ImageSegment.h"
#include "Memory.h"
ImageSegment*
ImageSegment::alloc(uintptr_t base, size_t size)
{
/*
* TODO: In long run we should either use OMR port library or
* take hmm.h / hmm.c from Smalltalk/X jv-branch runtime.
*/
ASSERT(base == pagealign(base));
auto ptr = AllocateMemory(base, size);
ASSERT(base == ptr);
return reinterpret_cast<ImageSegment*>(ptr);
}
ImageSegment*
ImageSegment::load(std::istream* data)
{
ImageSegmentHeader header;
data->read(reinterpret_cast<char*>(&header), sizeof(header));
ImageSegment* segment = ImageSegment::alloc(header.baseAddress, header.reservedSize);
data->seekg(0, data->beg);
data->read(reinterpret_cast<char*>(segment), header.size);
return segment;
}