]>
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/>.
26 int main(int argc
, char *argv
[]) {
27 _cleanup_close_
int fd
= -1;
28 char template[] = "/tmp/sigbus-test-XXXXXX";
34 assert_se(sigbus_pop(&addr
) == 0);
36 assert_se((fd
= mkostemp(template, O_RDWR
|O_CREAT
|O_EXCL
)) >= 0);
37 assert_se(unlink(template) >= 0);
38 assert_se(fallocate(fd
, 0, 0, page_size() * 8) >= 0);
40 p
= mmap(NULL
, page_size() * 16, PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
41 assert_se(p
!= MAP_FAILED
);
43 assert_se(sigbus_pop(&addr
) == 0);
46 assert_se(sigbus_pop(&addr
) == 0);
48 p
[page_size()] = 0xFF;
49 assert_se(sigbus_pop(&addr
) == 0);
51 p
[page_size()*8] = 0xFF;
52 p
[page_size()*8+1] = 0xFF;
53 p
[page_size()*10] = 0xFF;
54 assert_se(sigbus_pop(&addr
) > 0);
55 assert_se(addr
== p
+ page_size() * 8);
56 assert_se(sigbus_pop(&addr
) > 0);
57 assert_se(addr
== p
+ page_size() * 10);
58 assert_se(sigbus_pop(&addr
) == 0);