-
Notifications
You must be signed in to change notification settings - Fork 242
/
sysv-shm.c
66 lines (54 loc) · 1.34 KB
/
sysv-shm.c
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
/*
* SYSV Shared mapping creation.
*/
#include <sys/shm.h>
#include <limits.h>
#include "arch.h"
#include "compat.h"
#include "random.h"
#include "sysv-shm.h"
#include "objects.h"
#include "utils.h"
static void dump_sysv_shm(struct object *obj, bool global)
{
output(0, "sysv_shm: id:%u size:%ld flags:%x ptr:%p global:%d\n",
obj->sysv_shm.id, obj->sysv_shm.size,
obj->sysv_shm.flags, obj->sysv_shm.ptr, global);
}
void create_sysv_shms(void)
{
struct objhead *head;
unsigned int i;
int shmget_flags[] = {
0, // Just CREAT|EXCL
SHM_HUGETLB|SHM_HUGE_2MB,
SHM_HUGETLB|SHM_HUGE_1GB,
SHM_NORESERVE,
SHM_HUGETLB|SHM_HUGE_2MB|SHM_NORESERVE,
SHM_HUGETLB|SHM_HUGE_1GB|SHM_NORESERVE,
};
head = get_objhead(OBJ_GLOBAL, OBJ_SYSV_SHM);
head->dump = dump_sysv_shm;
for (i = 0; i < ARRAY_SIZE(shmget_flags); i++) {
void *p;
struct object *obj;
size_t size = 0;
int flags;
int id;
obj = alloc_object();
flags = 0660 | IPC_CREAT | IPC_EXCL | shmget_flags[i];
size = page_size * (1 + rnd() % 10);
id = shmget(IPC_PRIVATE, page_size, flags);
if (id == -1) {
free(obj);
continue;
}
obj->sysv_shm.id = id;
obj->sysv_shm.flags = flags;
obj->sysv_shm.size = size;
add_object(obj, OBJ_GLOBAL, OBJ_SYSV_SHM);
p = shmat(id, NULL, 0); // TODO: Try alternative flags.
if (p != (void *) -1)
obj->sysv_shm.ptr = p;
}
}