3 * Copyright (c) International Business Machines Corp., 2002
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 12/20/2002 Port to LTP robbiew@us.ibm.com */
21 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
28 * shmctl(2) shmget(2) shmat(2)
31 * Create two shared memory segments and attach them to the same process
32 * at two different addresses. The addresses DO BUMP into each other.
33 * The second attach should Fail.
39 #include <sys/types.h>
42 #include <sys/utsname.h>
51 char *TCID
="shmt05"; /* Test program identifier. */
52 int TST_TOTAL
=2; /* Total number of test cases. */
53 extern int Tst_count
; /* Test Case counter for tst_* routines */
58 #define ADDR (void *)0x80000
59 #define ADDR1 (void *)0x81000
60 #define ADDR_IA (void *)0x40000000
61 #define ADDR1_IA (void *)0x40000010
75 srand48((getpid() << 16) + (unsigned)time((time_t *)NULL
));
77 key
[0] = (key_t
) lrand48();
78 key
[1] = (key_t
) lrand48();
80 /*--------------------------------------------------------*/
83 if ((shmid
= shmget(key
[0], SIZE
, IPC_CREAT
|0666)) < 0) {
86 "Error: shmget: shmid = %d, errno = %d\n",
90 cp
= (char *) shmat(shmid
, ADDR_IA
, 0);
91 #elif defined(__ARM_ARCH_4T__) || defined(__minix)
92 cp
= (char *) shmat(shmid
, (void *)NULL
, 0);
94 cp
= (char *) shmat(shmid
, ADDR
, 0);
96 if (cp
== (char *)-1) {
97 tst_resm(TFAIL
,"shmat");
102 tst_resm(TPASS
,"shmget & shmat");
104 /*--------------------------------------------------------*/
107 if ((shmid1
= shmget(key
[1], SIZE
, IPC_CREAT
|0666)) < 0) {
110 "Error: shmget: shmid1 = %d, errno = %d\n",
114 cp1
= (char *) shmat(shmid1
, ADDR1_IA
, 0);
115 #elif defined(__ARM_ARCH_4T__)
116 cp1
= (char *) shmat(shmid1
, (void *)NULL
, 0);
118 cp1
= (char *) shmat(shmid1
, ADDR1
, 0);
120 if (cp1
!= (char *)-1) {
123 "Error: shmat: shmid1 = %d, addr= %#x, errno = %d\n",
128 tst_resm(TPASS
,"2nd shmget & shmat");
130 /*------------------------------------------------------*/
137 /*-------------------------------------------------------*/
144 if (shmctl(shmid
, IPC_RMID
, NULL
) == -1) {
147 "shmctl Failed to remove: shmid = %d, errno = %d\n",