aboutsummaryrefslogtreecommitdiff
path: root/src/rt/memory_region.h
blob: 3411d867ebfb723416a40b7092c75aa8d7242963 (plain) (blame)
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
/*
 * The Rust runtime uses memory regions to provide a primitive level of
 * memory management and isolation between tasks, and domains.
 *
 * TODO: Implement a custom lock-free malloc / free instead of relying solely
 *       on the standard malloc / free.
 */

#ifndef MEMORY_REGION_H
#define MEMORY_REGION_H

#include "sync/spin_lock.h"

class rust_srv;

class memory_region {
private:
    rust_srv *_srv;
    memory_region *_parent;
    size_t _live_allocations;
    array_list<void *> _allocation_list;
    const bool _synchronized;
    spin_lock _lock;
public:
    enum memory_region_type {
        LOCAL = 0x1, SYNCHRONIZED = 0x2
    };
    memory_region(rust_srv *srv, bool synchronized);
    memory_region(memory_region *parent);
    void *malloc(size_t size);
    void *calloc(size_t size);
    void *realloc(void *mem, size_t size);
    void free(void *mem);
    virtual ~memory_region();
};

#endif /* MEMORY_REGION_H */