Debian Codegraph @

testsuite/systemtap.syscall/shmget.c

raw
1 /* COVERAGE: shmget shmctl */
2 #include <sys/types.h>
3 #include <sys/ipc.h>
4 #include <sys/shm.h>
5 #include <unistd.h>
6 #include <time.h>
7 #include <sys/time.h>
8
9 int main()
10 {
11 char *curdir;
12 struct timeval tv;
13 key_t ipc_key;
14 int shmid;
15
16 // Generate a System V IPC key (based on the current directory and time)
17 curdir = getcwd(NULL, 0);
18 gettimeofday(&tv, NULL);
19 ipc_key = ftok(curdir, tv.tv_usec);
20
21 // Why 64k? ppc64 has 64K pages. ia64 has 16k pages. x86_64/i686
22 // has 4k pages. When we specify a size to shmget(), it must be a
23 // multiple of the page size, so we use the biggest.
24 //
25 // The least significant 9 bites of the flags argument are the
26 // permissions. 0600 is read/write permissions.
27 shmid = shmget(ipc_key, 65535, (IPC_CREAT | IPC_EXCL | 0600));
28 //staptest// shmget (NNNN, 65535, IPC_CREAT|IPC_EXCL|0600) = NNNN
29
30 shmget(ipc_key, -1, (IPC_CREAT | IPC_EXCL | 0600));
31 #if __WORDSIZE == 64
32 //staptest// shmget (NNNN, 18446744073709551615, IPC_CREAT|IPC_EXCL|0600) = -NNNN
33 #else
34 //staptest// shmget (NNNN, 4294967295, IPC_CREAT|IPC_EXCL|0600) = -NNNN
35 #endif
36
37 shmget(ipc_key, 65535, -1);
38 //staptest// shmget (NNNN, 65535, IPC_[^ ]+|XXXX|0777) = -NNNN
39
40 shmctl(shmid, IPC_RMID, NULL);
41 //staptest// shmctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = NNNN
42
43 shmid = shmget(-1, 65535, (IPC_CREAT | IPC_EXCL | 0600));
44 //staptest// shmget (-1, 65535, IPC_CREAT|IPC_EXCL|0600) = NNNN
45
46 shmctl(-1, IPC_RMID, NULL);
47 //staptest// shmctl (-1, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = -NNNN
48
49 shmctl(shmid, -1, NULL);
50 //staptest// shmctl (NNNN, [[[[IPC_64|XXXX!!!!0x[f]+]]]], 0x0) = -NNNN
51
52 // The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 in shmid_to_shmid64()
53 #if __WORDSIZE == 64
54 shmctl(shmid, IPC_STAT, (struct shmid_ds *)-1);
55 #ifdef __s390__
56 //staptest// shmctl (NNNN, [[[[IPC_64|]]]]?IPC_STAT, 0x[7]?[f]+) = -NNNN
57 #else
58 //staptest// shmctl (NNNN, [[[[IPC_64|]]]]?IPC_STAT, 0x[f]+) = -NNNN
59 #endif
60 #endif
61
62 shmctl(shmid, IPC_RMID, NULL);
63 //staptest// shmctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = NNNN
64
65 return 0;
66 }