-
Notifications
You must be signed in to change notification settings - Fork 0
/
eastlake.h
121 lines (96 loc) · 2.71 KB
/
eastlake.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef EASTLAKE_H_
#define EASTLAKE_H_
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h> /* For SYS_xxx definitions */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include "slab.h"
#define PAGE_SIZE 4096
// #define USE_SLAB
/*
* struct po_stat
*/
struct po_stat {
mode_t st_mode;
uid_t st_uid;
gid_t st_gid;
off_t st_size;
};
/*
* system calls in lullaby.
* attention: we will not use these functions directly,
* instead we will use syscall by passing syscall number to it.
*/
static inline long po_creat(const char *poname, mode_t mode) {
return syscall(400, poname, mode);
}
static inline long po_unlink(const char *poname) {
return syscall(401, poname);
}
static inline long po_open(const char *poname, int flags, mode_t mode) {
return syscall(402, poname, flags, mode);
}
static inline long po_close(unsigned int pod) {
return syscall(403, pod);
}
static inline long po_chunk_mmap(unsigned int pod, unsigned long addr, \
unsigned long prot, unsigned long flags) {
return syscall(404, pod, addr, prot, flags);
}
static inline long po_chunk_munmap(unsigned long addr) {
return syscall(405, addr);
}
static inline long po_extend(unsigned int pod, size_t len, \
unsigned long prot, unsigned long flags) {
return syscall(406, pod, len, prot, flags);
}
static inline long po_shrink(unsigned int pod, unsigned long addr, size_t len) {
return syscall(407, pod, addr, len);
}
static inline long po_stat(const char *poname, struct po_stat *statbuf) {
return syscall(408, poname, statbuf);
}
static inline long po_fstat(unsigned int pod, struct po_stat *statbuf) {
return syscall(409, pod, statbuf);
}
static inline long po_chunk_next(unsigned int pod, unsigned long last, \
size_t size, unsigned long *addrbuf) {
return syscall(410, pod, last, size, addrbuf);
}
/*
* user library functions in lullaby
*/
#ifndef USE_SLAB
static void *po_malloc(int pod, size_t size) {
long int retval = po_extend(pod, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE);
if (retval == -1)
return nullptr;
return (void*)retval;
}
static void po_free(int pod, void *ptr) {
int retval;
retval = po_shrink(pod, (unsigned long)ptr, 4096);
if (retval == -1)
printf("po_shring failed, errno: %d\n", errno);
}
#else
static void po_memory_alloc_init(struct slab_chain *const sch, const size_t itemsize) {
slab_init(sch, itemsize);
}
static void *po_malloc(struct slab_chain *const sch) {
return slab_alloc(sch);
}
static void po_free(struct slab_chain *const sch, const void *const addr) {
return slab_free(sch, addr);
}
#endif
#endif