-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
65 lines (49 loc) · 1.17 KB
/
Copy pathexample.c
File metadata and controls
65 lines (49 loc) · 1.17 KB
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
/* vim: set noet ts=8 sw=8 : */
/* cc -static -O0 ralloc-example.c -o ralloc-example */
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define __NR_ralloc 321
#define __NR_rfree 322
void *ralloc(unsigned long size)
{
return (void *) syscall(__NR_ralloc, size, "10.0.2.2", 8700);
}
int rfree(void *addr)
{
return syscall(__NR_rfree, (unsigned long) addr);
}
int main(int argc, char **argv)
{
char *p, *addr;
addr = ralloc(0x10000);
if (!addr) {
printf("could not allocate memory\n");
return 1;
}
memset(addr, 1, 0x10000);
memset(addr+0x1000, 2, 0x1000);
memset(addr+0x2000, 3, 0x1000);
memset(addr+0x5000, 6, 0x1000);
addr[0] = 12;
addr[0x2fff] = 21;
for (p = addr+1; p < addr+0x1000; ++p)
assert(*p == 1);
for (p = addr+0x1000; p < addr+0x2000; ++p)
assert(*p == 2);
assert(addr[0x2fff] = 21);
addr[0x2fff] = 3;
for (p = addr+0x2000; p < addr+0x3000; ++p)
assert(*p == 3);
for (p = addr+0x8888; p < addr+0x8888+0x6666; ++p)
assert(*p == 1);
for (p = addr+0x5000; p < addr+0x6000; ++p)
assert(*p == 6);
assert(addr[0] == 12);
rfree(addr);
printf("OK\n");
return 0;
}