-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmmap.cpp
60 lines (48 loc) · 1.46 KB
/
mmap.cpp
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
#include "faasm/faasm.h"
#include <array>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sys/mman.h>
int main(int argc, char* argv[])
{
// Make this multiple pages not on a page boundary
size_t nPages = 3;
size_t memLen = (nPages * 64 * 1024) + 1234;
std::string output;
char* memPtrs[10];
std::array<std::string, 10> expected;
for (int i = 0; i < 10; i++) {
// Map some memory
void* p = mmap(nullptr,
memLen,
PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE,
-1,
0);
if (p == MAP_FAILED) {
printf("ERROR - mmap failed: %s\n", strerror(errno));
return 1;
}
memPtrs[i] = (char*)p;
// Write something to it
std::string output = std::string("Output ") + std::to_string(i);
strcpy(memPtrs[i], output.c_str());
expected[i] = output;
}
// Check the outputs are still in place
for (int i = 0; i < 10; i++) {
std::string thisExpected = expected.at(i);
std::string thisActual(memPtrs[i]);
if (thisExpected != thisActual) {
printf("Expected %s but got %s\n",
thisExpected.c_str(),
thisActual.c_str());
return 1;
}
}
output = "success";
faasmSetOutput(output.c_str(), output.size());
return 0;
}