Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/vmalloc/tmmopen.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "vmtest.h"
21
22
#define MAPSIZE (128*1024*1024)
23
24
char *shmfile;
25
char *mapfile;
26
27
tmain()
28
{
29
int k, code = 0;
30
Vmalloc_t *shm, *map;
31
char *arg[5];
32
pid_t ppid, cpid;
33
34
if(k = tchild())
35
{ cpid = getpid();
36
shmfile = argv[k];
37
mapfile = argv[k+1];
38
39
tinfo("Child[pid=%d]: allocating heap memory before opening shm region", cpid);
40
for(k = 0; k < 1024; ++k)
41
if(!malloc(32*1024) )
42
terror("Child[pid=%d]: Can't allocate segment %d", cpid, k);
43
44
if(*shmfile)
45
{ tinfo("Child[pid=%d]: opening shm region", cpid);
46
if(!(shm = vmmopen(shmfile, 1, MAPSIZE)) )
47
terror("Child[pid=%d]: Can't open shm region in child process", cpid);
48
tinfo("Child[pid=%d]: shm region opened", cpid);
49
}
50
51
tinfo("Child[pid=%d]: allocating heap memory before opening map region", cpid);
52
for(k = 0; k < 1024; ++k)
53
if(!malloc(32*1024) )
54
terror("Child[pid=%d]: Can't allocate segment %d", cpid, k);
55
56
if(*mapfile)
57
{ tinfo("Child[pid=%d]: opening map region", cpid);
58
if(!(map = vmmopen(mapfile, -1, MAPSIZE)) )
59
terror("Child[pid=%d]: Can't open map region in child process", cpid);
60
tinfo("Child[pid=%d]: map region opened", cpid);
61
}
62
}
63
else
64
{ ppid = getpid();
65
shmfile = tstfile("shm", -1);
66
mapfile = tstfile("map", -1);
67
(void)unlink(shmfile);
68
(void)unlink(mapfile);
69
70
tinfo("Parent[pid=%d]: %s: opening shm region", ppid, shmfile);
71
if(shm = vmmopen(shmfile, 1, MAPSIZE) )
72
tinfo("Parent[pid=%d]: %s: shm region opened", ppid, shmfile);
73
else
74
{ tnote("shm not supported");
75
shmfile = "";
76
}
77
78
tinfo("Parent[pid=%d]: %s: opening map region", ppid, mapfile);
79
if(map = vmmopen(mapfile, -1, MAPSIZE) )
80
tinfo("Parent[pid=%d]: %s: map region opened", ppid, mapfile);
81
else
82
{ tnote("map not supported");
83
mapfile = "";
84
}
85
86
switch((cpid = fork()) ) /* make a child process */
87
{ default :
88
code = twait(&cpid, 1);
89
break;
90
case 0 :
91
arg[0] = argv[0];
92
arg[1] = "--child";
93
arg[2] = shmfile;
94
arg[3] = mapfile;
95
arg[4] = 0;
96
if(execv(argv[0], arg) < 0 )
97
terror("Could not exec child process");
98
case -1:
99
terror("Could not fork a child process");
100
}
101
}
102
103
vmmrelease(shm, 1); vmclose(shm);
104
vmmrelease(map, 1); vmclose(map);
105
106
texit(code);
107
}
108
109