1 // RUN: %clang_scudo %s -o %t
2 // RUN: %run %t after 2>&1 | FileCheck %s
3 // RUN: %run %t before 2>&1 | FileCheck %s
5 // Test that we hit a guard page when writing past the end of a chunk
6 // allocated by the Secondary allocator, or writing too far in front of it.
15 void handler(int signo
, siginfo_t
*info
, void *uctx
) {
16 if (info
->si_code
== SEGV_ACCERR
) {
17 fprintf(stderr
, "SCUDO SIGSEGV\n");
23 int main(int argc
, char **argv
) {
24 // The size must be large enough to be serviced by the secondary allocator.
25 long page_size
= sysconf(_SC_PAGESIZE
);
26 size_t size
= (1U << 17) + page_size
;
30 memset(&a
, 0, sizeof(a
));
31 a
.sa_sigaction
= handler
;
32 a
.sa_flags
= SA_SIGINFO
;
34 char *p
= (char *)malloc(size
);
36 memset(p
, 'A', size
); // This should not trigger anything.
37 // Set up the SIGSEGV handler now, as the rest should trigger an AV.
38 sigaction(SIGSEGV
, &a
, NULL
);
39 if (!strcmp(argv
[1], "after")) {
40 for (int i
= 0; i
< page_size
; i
++)
43 if (!strcmp(argv
[1], "before")) {
44 for (int i
= 1; i
< page_size
; i
++)
49 return 1; // A successful test means we shouldn't reach this.
52 // CHECK: SCUDO SIGSEGV