mte-6.c (830B)
1#include "mte.h" 2 3void pass(int sig, siginfo_t *info, void *uc) 4{ 5 assert(info->si_code == SEGV_MTESERR); 6 exit(0); 7} 8 9int main(void) 10{ 11 enable_mte(PR_MTE_TCF_SYNC); 12 13 void *brk = sbrk(16); 14 if (brk == (void *)-1) { 15 perror("sbrk"); 16 return 2; 17 } 18 19 if (mprotect(brk, 16, PROT_READ | PROT_WRITE | PROT_MTE)) { 20 perror("mprotect"); 21 return 2; 22 } 23 24 int *p1, *p2; 25 long excl = 1; 26 27 asm("irg %0,%1,%2" : "=r"(p1) : "r"(brk), "r"(excl)); 28 asm("gmi %0,%1,%0" : "+r"(excl) : "r"(p1)); 29 asm("irg %0,%1,%2" : "=r"(p2) : "r"(brk), "r"(excl)); 30 asm("stg %0,[%0]" : : "r"(p1)); 31 32 *p1 = 0; 33 34 struct sigaction sa; 35 memset(&sa, 0, sizeof(sa)); 36 sa.sa_sigaction = pass; 37 sa.sa_flags = SA_SIGINFO; 38 sigaction(SIGSEGV, &sa, NULL); 39 40 *p2 = 0; 41 42 abort(); 43}