1 /* Application Data Integrity (ADI) test in sparc64.
3 Copyright 2017-2019 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>
43 #define PAT 0xdeadbeaf
46 #define SHMSIZE 102400
52 memory_fill (char *addr
, size_t size
, int pattern
)
54 long *aligned_addr
= (long *) addr
;
56 for (i
= 0; i
< size
/ sizeof (long); i
+= ONEKB
)
58 *aligned_addr
= pattern
;
59 aligned_addr
= aligned_addr
+ ONEKB
;
71 int shmid
= shmget (IPC_PRIVATE
, SHMSIZE
, IPC_CREAT
| 0666);
74 char *shmaddr
= (char *)shmat (shmid
, NULL
, 0x666 | SHM_RND
);
75 if (shmaddr
== (char *)-1)
77 shmctl (shmid
, IPC_RMID
, NULL
);
80 /* Enable ADI on ISM segment. */
81 if (mprotect (shmaddr
, SHMSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
83 perror ("mprotect failed");
86 if (memory_fill (shmaddr
, SHMSIZE
, PAT
) != 0) /* line breakpoint here */
90 adi_clr_version (shmaddr
, SHMSIZE
);
91 caddr_t vshmaddr
= adi_set_version (shmaddr
, SHMSIZE
, 0x8);
95 int fd
= open ("/dev/zero", O_RDWR
);
98 char *maddr
= (char *)mmap (NULL
, MAPSIZE
, PROT_READ
|PROT_WRITE
,
100 if (maddr
== (char *)-1)
103 if (mprotect (shmaddr
, MAPSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
105 perror ("mprotect failed");
109 if (memory_fill (maddr
, MAPSIZE
, PAT
) != 0)
111 caddr_t vmaddr
= adi_set_version (maddr
, MAPSIZE
, 0x8);
114 haddr
= (char*) memalign (MAPSIZE
, MAPSIZE
);
116 if (mprotect (shmaddr
, MAPSIZE
, PROT_READ
|PROT_WRITE
|PROT_ADI
))
118 perror ("mprotect failed");
122 if (memory_fill (haddr
, MAPSIZE
, PAT
) != 0)
124 adi_clr_version (haddr
, MAPSIZE
);
125 /* Set some ADP version number. */
126 caddr_t vaddr1
, vaddr2
, vaddr3
, vaddr4
;
127 vaddr
= adi_set_version (haddr
, 64*2, 0x8);
128 vaddr1
= adi_set_version (haddr
+64*2, 64*2, 0x9);
129 vaddr2
= adi_clr_version (haddr
+64*4, 64*2);
130 vaddr3
= adi_set_version (haddr
+64*6, 64*2, 0xa);
131 vaddr4
= adi_set_version (haddr
+64*8, 64*10, 0x3);
134 char *versioned_p
= vaddr
;
136 char *uvp
= haddr
; // unversioned pointer
137 *uvp
= 'b'; // version mismatch trap
141 if (shmdt ((const void *)shmaddr
) != 0)
142 perror ("Detach failure");
143 shmctl (shmid
, IPC_RMID
, NULL
);