Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: check decoding of SEGV_ACCERR
* tests/segv_accerr.c: New file. * tests/gen_tests.in (segv_accerr): New test. * tests/Makefile.am (check_PROGRAMS): Add segv_accerr. * tests/.gitignore: Likewise.
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Check decoding of SEGV_ACCERR. | ||
* | ||
* Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io> | ||
* All rights reserved. | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "tests.h" | ||
#include <signal.h> | ||
|
||
#ifdef SEGV_ACCERR | ||
|
||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <unistd.h> | ||
# include <sys/mman.h> | ||
|
||
static void | ||
handler(int sig) | ||
{ | ||
_exit(0); | ||
} | ||
|
||
int | ||
main(void) { | ||
int *p = mmap(NULL, get_page_size(), PROT_NONE, | ||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
if (p == MAP_FAILED) | ||
perror_msg_and_fail("mmap"); | ||
|
||
const struct sigaction act = { | ||
.sa_handler = handler, | ||
.sa_flags = SA_RESETHAND | ||
}; | ||
if (sigaction(SIGSEGV, &act, NULL)) | ||
perror_msg_and_fail("sigaction"); | ||
|
||
printf("--- SIGSEGV {si_signo=SIGSEGV" | ||
", si_code=SEGV_ACCERR, si_addr=%p} ---\n", p); | ||
fflush(stdout); | ||
|
||
if (*p) | ||
__asm__ volatile("":::"memory"); | ||
|
||
error_msg_and_skip("PROT_NONE page is readable"); | ||
} | ||
|
||
#else | ||
|
||
SKIP_MAIN_UNDEFINED("SEGV_ACCERR") | ||
|
||
#endif |