summaryrefslogtreecommitdiffstats
path: root/mem/memory.h
blob: 395685266354516a34ab72349a9346d40dd89312 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef JOVE_MEM_H
#define JOVE_MEM_H 1

#define PAGESIZE 4096ULL
#define KiB 1024ULL
#define MiB (KiB * KiB)
#define GiB (MiB * KiB)
#define TiB (GiB * KiB)

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
typedef uintptr_t physptr_t;

#include "slab.h"

/*Linear*/
void mem_paging_setup(void);

physptr_t mem_linear_tophys(uintptr_t virt);

/**Check if pointer is within valid memory.
 * @param ptr pointer to check.
 * @return if the pointer is invalid.*/
bool mem_check_ptr(const void *ptr);

/**Make sure the range indicated is available in memory.
 * If necessary, allocate new pages using the passed flags
 * @param from start of the range.
 * @param to end of the range.
 * @param rw flag to mark page is writeable.
 * @param user flag to mark page as user accessable*/
void mem_ensure_range(uintptr_t from, uintptr_t to, bool rw, bool user);

/**Make sure the range indicated is available in memory for specified pd
 * If necessary, allocate new pages using the passed flags
 * @param pd pointer to page directory to edit
 * @param from start of the range.
 * @param to end of the range.
 * @param rw flag to mark page is writeable.
 * @param user flag to mark page as user accessable*/
void mem_ensure_range_for(void *pd, uintptr_t from, uintptr_t to, bool rw, bool user);

void mem_slab_setup(void);
void mem_slabcache_new(struct SlabCache *cache, char *name, size_t objsize);

void* mem_slab_alloc(struct SlabCache *cache);
void mem_slab_free(struct SlabCache *cache, void *ptr);

void* mem_alloc(size_t width);
void mem_free(void *ptr);

/*Physical*/

physptr_t mem_phys_take4k(void);
void mem_phys_reserve(physptr_t start, size_t len);

#endif