-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsm_mem.c
More file actions
37 lines (28 loc) · 899 Bytes
/
sm_mem.c
File metadata and controls
37 lines (28 loc) · 899 Bytes
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
#include "sm_mem.h"
void* create_mmap(int pid){
int i;
void *address, *alloc;
long bytes;
int prot;
unsigned char arr[20];
// address = (char*)malloc(sizeof(char));
address = (void *)ADDR_BASE;
bytes = getpagesize()*PAGE_NUM;
int flags;
if(pid == -1){ // allow full access in allocator
prot = PROT_READ | PROT_WRITE;
flags = MAP_FIXED | MAP_ANONYMOUS| MAP_SHARED;
}else{ // no w/r access in client
prot = PROT_NONE;
flags = MAP_ANONYMOUS|MAP_PRIVATE | MAP_FIXED;
}
// change to use 'prot' later
alloc = mmap(address, bytes, prot , flags, 0, 0);
if (alloc == MAP_FAILED) {
perror("mmap failed.....................................");
exit(0);
}
// debug_printf("node %d: ..................addr after mmap: %p\n",pid, address);
// debug_printf("node %d: ............................alloc: %p\n",pid, alloc);
return alloc;
}