-
Notifications
You must be signed in to change notification settings - Fork 11
/
mm.h
88 lines (68 loc) · 2.82 KB
/
mm.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// -*- c++ -*-
//
// PTLsim: Cycle Accurate x86-64 Simulator
// Memory Management
//
// Copyright 2004-2008 Matt T. Yourst <[email protected]>
//
#ifndef _MM_H_
#define _MM_H_
#include <globals.h>
void* ptl_mm_alloc_private_pages(Waddr bytecount, int prot = PROT_READ|PROT_WRITE|PROT_EXEC, Waddr base = 0);
void* ptl_mm_try_alloc_private_pages(Waddr bytecount, int prot = PROT_READ|PROT_WRITE|PROT_EXEC, Waddr base = 0, void* caller = 0);
void* ptl_mm_alloc_private_32bit_pages(Waddr bytecount, int prot = PROT_READ|PROT_WRITE|PROT_EXEC, Waddr base = 0);
void ptl_mm_free_private_pages(void* addr, Waddr bytecount);
void ptl_mm_zero_private_pages(void* base, Waddr bytecount);
void* ptl_mm_alloc_private_page();
void* ptl_mm_try_alloc_private_page();
void* ptl_mm_alloc_private_32bit_page();
void ptl_mm_free_private_page(void* addr);
void ptl_mm_zero_private_page(void* addr);
void* ptl_mm_alloc(size_t bytes);
void* ptl_mm_alloc_aligned(int alignbits);
void* ptl_mm_try_alloc(size_t bytes);
void ptl_mm_free(void* p);
template <typename T>
static inline T* ptl_mm_alloc_private_pages_for_objects(int count) {
T* p = (T*)ptl_mm_alloc_private_pages(count * sizeof(T));
return p;
}
template <typename T>
static inline T* ptl_mm_alloc_and_zero_private_pages_for_objects(int count) {
T* p = ptl_mm_alloc_private_pages_for_objects<T>(count);
ptl_mm_zero_private_pages(p, count * sizeof(T));
return p;
}
static const int MAX_URGENCY = 65535;
typedef void (*mm_reclaim_handler_t)(size_t bytes, int urgency);
bool ptl_mm_register_reclaim_handler(mm_reclaim_handler_t handler);
void ptl_mm_reclaim(size_t bytes = 0, int urgency = 0);
void ptl_mm_cleanup();
class DataStoreNode;
DataStoreNode& ptl_mm_capture_stats(DataStoreNode& root);
void ptl_mm_init(byte* heap_start = null, byte* heap_end = null);
size_t ptl_mm_getsize(void* p);
void ptl_mm_dump(ostream& os);
void ptl_mm_validate();
void ptl_mm_set_logging(const char* mm_log_filename, int mm_log_buffer_size, bool enable_inline_mm_logging);
void ptl_mm_set_validate(bool enable_mm_validate);
void ptl_mm_flush_logging();
#ifdef __x86_64__
#define mmap_invalid(addr) (((W64)(addr) & 0xfffffffffffff000) == 0xfffffffffffff000)
#define mmap_valid(addr) (!mmap_invalid(addr))
#else // ! __x86_64__
#define mmap_invalid(addr) (((W32)(addr) & 0xfffff000) == 0xfffff000)
#define mmap_valid(addr) (!mmap_invalid(addr))
#endif
#ifdef PTLSIM_HYPERVISOR
#define PTL_PAGE_POOL_BASE PTLSIM_VIRT_BASE
#define PTL_PAGE_POOL_BYTES (2ULL*1024*1024*1024) // up to 2 GB (64KB bitmap)
#define PTL_PAGE_POOL_SIZE (PTL_PAGE_POOL_BYTES / 4096)
#else
#define PTL_PAGE_POOL_BASE 0
#define PTL_PAGE_POOL_BYTES (4ULL*1024*1024*1024) // lower 4 GB
#define PTL_PAGE_POOL_SIZE (PTL_PAGE_POOL_BYTES / 4096)
#define PTL_IMAGE_BASE 0x70000000ULL
#define PTL_IMAGE_SIZE (256*1024*1024) // 256 MB (up to 0x80000000)
#endif
#endif // _MM_H_