1 /* Application Data Integrity (ADI) test in sparc64.
3 Copyright 2017-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
27 #include <sys/errno.h>
28 #include <sys/utsname.h>
29 #include <sys/param.h>
42 #define PAT 0xdeadbeaf
45 #define SHMSIZE 102400
51 memory_fill (char *addr
, size_t size
, int pattern
)
53 long *aligned_addr
= (long *) addr
;
55 for (i
= 0; i
< size
/ sizeof (long); i
+= ONEKB
)
57 *aligned_addr
= pattern
;
58 aligned_addr
= aligned_addr
+ ONEKB
;
70 int shmid
= shmget (IPC_PRIVATE
, SHMSIZE
, IPC_CREAT
| 0666);
73 char *shmaddr
= (char *)shmat (shmid
, NULL
, 0x666 | SHM_RND
);
74 if (shmaddr
== (char *)-1)
76 shmctl (shmid
, IPC_RMID
, NULL
);
79 /* Enable ADI on ISM segment. */
80 if (mprotect (shmaddr
, SHMSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
82 perror ("mprotect failed");
85 if (memory_fill (shmaddr
, SHMSIZE
, PAT
) != 0) /* line breakpoint here */
89 adi_clr_version (shmaddr
, SHMSIZE
);
90 caddr_t vshmaddr
= adi_set_version (shmaddr
, SHMSIZE
, 0x8);
94 int fd
= open ("/dev/zero", O_RDWR
);
97 char *maddr
= (char *)mmap (NULL
, MAPSIZE
, PROT_READ
|PROT_WRITE
,
99 if (maddr
== (char *)-1)
102 if (mprotect (shmaddr
, MAPSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
104 perror ("mprotect failed");
108 if (memory_fill (maddr
, MAPSIZE
, PAT
) != 0)
110 caddr_t vmaddr
= adi_set_version (maddr
, MAPSIZE
, 0x8);
113 haddr
= (char*) memalign (MAPSIZE
, MAPSIZE
);
115 if (mprotect (shmaddr
, MAPSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
117 perror ("mprotect failed");
121 if (memory_fill (haddr
, MAPSIZE
, PAT
) != 0)
123 adi_clr_version (haddr
, MAPSIZE
);
124 /* Set some ADP version number. */
125 caddr_t vaddr1
, vaddr2
, vaddr3
, vaddr4
;
126 vaddr
= adi_set_version (haddr
, 64*2, 0x8);
127 vaddr1
= adi_set_version (haddr
+64*2, 64*2, 0x9);
128 vaddr2
= adi_clr_version (haddr
+64*4, 64*2);
129 vaddr3
= adi_set_version (haddr
+64*6, 64*2, 0xa);
130 vaddr4
= adi_set_version (haddr
+64*8, 64*10, 0x3);
133 char *versioned_p
= vaddr
;
135 char *uvp
= haddr
; // unversioned pointer
136 *uvp
= 'b'; // version mismatch trap
140 if (shmdt ((const void *)shmaddr
) != 0)
141 perror ("Detach failure");
142 shmctl (shmid
, IPC_RMID
, NULL
);