(root)/
strace-6.5/
tests/
segv_accerr.c
       1  /*
       2   * Check decoding of SEGV_ACCERR.
       3   *
       4   * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include <signal.h>
      12  
      13  #ifdef SEGV_ACCERR
      14  
      15  # include <stdio.h>
      16  # include <stdlib.h>
      17  # include <unistd.h>
      18  # include <sys/mman.h>
      19  
      20  static void
      21  handler(int sig)
      22  {
      23  	_exit(0);
      24  }
      25  
      26  int
      27  main(void) {
      28  	int *p = mmap(NULL, get_page_size(), PROT_NONE,
      29  		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
      30  	if (p == MAP_FAILED)
      31  		perror_msg_and_fail("mmap");
      32  
      33  	const struct sigaction act = {
      34  		.sa_handler = handler,
      35  		.sa_flags = SA_RESETHAND
      36  	};
      37  	if (sigaction(SIGSEGV, &act, NULL))
      38  		perror_msg_and_fail("sigaction");
      39  
      40  	printf("--- SIGSEGV {si_signo=SIGSEGV"
      41  	       ", si_code=SEGV_ACCERR, si_addr=%p} ---\n", p);
      42  	fflush(stdout);
      43  
      44  	__asm__ volatile("":: "r" (*p));
      45  
      46  	error_msg_and_skip("PROT_NONE page is readable");
      47  }
      48  
      49  #else
      50  
      51  SKIP_MAIN_UNDEFINED("SEGV_ACCERR")
      52  
      53  #endif