this repo has no description
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */
2#pragma once
3
4#include "globals.h"
5#include "utils.h"
6
7namespace py {
8
9class Space {
10 public:
11 explicit Space(word size);
12 ~Space();
13
14 bool allocate(word size, uword* result);
15
16 void protect();
17
18 void unprotect();
19
20 bool contains(uword address) { return address >= start() && address < end(); }
21
22 bool isAllocated(uword address) {
23 return address >= start() && address < fill();
24 }
25
26 uword start() { return start_; }
27
28 uword end() { return end_; }
29
30 uword fill() { return fill_; }
31
32 void reset();
33
34 word size() { return end_ - start_; }
35
36 static int endOffset() { return offsetof(Space, end_); }
37
38 static int fillOffset() { return offsetof(Space, fill_); }
39
40 private:
41 uword start_;
42 uword end_;
43 uword fill_;
44
45 byte* raw_;
46
47 DISALLOW_COPY_AND_ASSIGN(Space);
48};
49
50inline bool Space::allocate(word size, uword* result) {
51 word fill = fill_;
52 word free = end_ - fill;
53 if (size > free) {
54 return false;
55 }
56 *result = fill;
57 fill_ = fill + size;
58 return true;
59}
60
61} // namespace py