| 1 |
/* COVERAGE: shmat shmdt */ |
| 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 |
void *addr; |
| 16 |
|
| 17 |
// Generate a System V IPC key (based on the current directory and time) |
| 18 |
curdir = getcwd(NULL, 0); |
| 19 |
gettimeofday(&tv, NULL); |
| 20 |
ipc_key = ftok(curdir, tv.tv_usec); |
| 21 |
|
| 22 |
// Why 64k? ppc64 has 64K pages. ia64 has 16k pages. x86_64/i686 |
| 23 |
// has 4k pages. When we specify a size to shmget(), it must be a |
| 24 |
// multiple of the page size, so we use the biggest. |
| 25 |
// |
| 26 |
// The least significant 9 bites of the flags argument are the |
| 27 |
// permissions. 0600 is read/write permissions. |
| 28 |
shmid = shmget(ipc_key, 65535, (IPC_CREAT | IPC_EXCL | 0600)); |
| 29 |
//staptest// shmget (NNNN, 65535, IPC_CREAT|IPC_EXCL|0600) = NNNN |
| 30 |
|
| 31 |
addr = shmat(shmid, NULL, SHM_RDONLY); |
| 32 |
//staptst// shmat (NNNN, 0x0, SHM_RDONLY) = NNNN |
| 33 |
|
| 34 |
addr = shmat(shmid, addr, SHM_REMAP); |
| 35 |
//staptst// shmat (NNNN, XXXX, SHM_REMAP) = NNNN |
| 36 |
|
| 37 |
shmdt(addr); |
| 38 |
//staptest// shmdt (XXXX) = NNNN |
| 39 |
|
| 40 |
shmat(-1, NULL, SHM_RND); |
| 41 |
//staptst// shmat (NNNN, 0x0, SHM_RND) = -NNNN |
| 42 |
|
| 43 |
shmat(shmid, (void *)-1, SHM_RND); |
| 44 |
//staptst// shmat (NNNN, 0xf000, SHM_RND) = NNNN |
| 45 |
|
| 46 |
shmdt((void *)-1); |
| 47 |
#ifdef __s390__ |
| 48 |
//staptest// shmdt (0x[7]?[f]+) = NNNN |
| 49 |
#else |
| 50 |
//staptest// shmdt (0x[f]+) = NNNN |
| 51 |
#endif |
| 52 |
|
| 53 |
shmctl(shmid, IPC_RMID, NULL); |
| 54 |
//staptest// shmctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = NNNN |
| 55 |
|
| 56 |
return 0; |
| 57 |
} |