1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2017 John Sperbeck
6 * Test that an access to a mapped but inaccessible area causes a SEGV and
7 * reports si_code == SEGV_ACCERR.
25 static void segv_handler(int n
, siginfo_t
*info
, void *ctxt_v
)
27 ucontext_t
*ctxt
= (ucontext_t
*)ctxt_v
;
28 struct pt_regs
*regs
= ctxt
->uc_mcontext
.regs
;
31 si_code
= info
->si_code
;
35 int test_segv_errors(void)
37 struct sigaction act
= {
38 .sa_sigaction
= segv_handler
,
39 .sa_flags
= SA_SIGINFO
,
43 p
= mmap(NULL
, getpagesize(), 0, MAP_PRIVATE
|MAP_ANONYMOUS
, -1, 0);
44 FAIL_IF(p
== MAP_FAILED
);
46 FAIL_IF(sigaction(SIGSEGV
, &act
, NULL
) != 0);
52 * We just need a compiler barrier, but mb() works and has the nice
53 * property of being easy to spot in the disassembly.
60 FAIL_IF(si_code
!= SEGV_ACCERR
);
70 FAIL_IF(si_code
!= SEGV_ACCERR
);
77 return test_harness(test_segv_errors
, "segv_errors");