]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sigbus.c
2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #if HAVE_VALGRIND_VALGRIND_H
26 #include <valgrind/valgrind.h>
29 int main(int argc
, char *argv
[]) {
30 _cleanup_close_
int fd
= -1;
31 char template[] = "/tmp/sigbus-test-XXXXXX";
35 #if HAVE_VALGRIND_VALGRIND_H
36 if (RUNNING_ON_VALGRIND
)
37 return EXIT_TEST_SKIP
;
40 #ifdef __SANITIZE_ADDRESS__
41 return EXIT_TEST_SKIP
;
45 assert_se(sigbus_pop(&addr
) == 0);
47 assert_se((fd
= mkostemp(template, O_RDWR
|O_CREAT
|O_EXCL
)) >= 0);
48 assert_se(unlink(template) >= 0);
49 assert_se(posix_fallocate(fd
, 0, page_size() * 8) >= 0);
51 p
= mmap(NULL
, page_size() * 16, PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
52 assert_se(p
!= MAP_FAILED
);
54 assert_se(sigbus_pop(&addr
) == 0);
57 assert_se(sigbus_pop(&addr
) == 0);
59 p
[page_size()] = 0xFF;
60 assert_se(sigbus_pop(&addr
) == 0);
62 p
[page_size()*8] = 0xFF;
63 p
[page_size()*8+1] = 0xFF;
64 p
[page_size()*10] = 0xFF;
65 assert_se(sigbus_pop(&addr
) > 0);
66 assert_se(addr
== p
+ page_size() * 8);
67 assert_se(sigbus_pop(&addr
) > 0);
68 assert_se(addr
== p
+ page_size() * 10);
69 assert_se(sigbus_pop(&addr
) == 0);