Debian Codegraph @

tests/truncate.c

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <signal.h>
23 #include <sys/mman.h>
24
25 #include <hugetlbfs.h>
26
27 #include "hugetests.h"
28
29 #define RANDOM_CONSTANT 0x1234ABCD
30
31 static void sigbus_handler(int signum, siginfo_t *si, void *uc)
32 {
33 PASS();
34 }
35
36 int main(int argc, char *argv[])
37 {
38 long hpage_size;
39 int fd;
40 void *p;
41 volatile unsigned int *q;
42 int err;
43 struct sigaction sa = {
44 .sa_sigaction = sigbus_handler,
45 .sa_flags = SA_SIGINFO,
46 };
47
48 test_init(argc, argv);
49
50 hpage_size = check_hugepagesize();
51
52 fd = hugetlbfs_unlinked_fd();
53 if (fd < 0)
54 FAIL("hugetlbfs_unlinked_fd()");
55
56 p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
57 fd, 0);
58 if (p == MAP_FAILED)
59 FAIL("mmap(): %s", strerror(errno));
60
61 q = p;
62
63 /* Touch the memory */
64 *q = 0;
65
66 err = sigaction(SIGBUS, &sa, NULL);
67 if (err)
68 FAIL("sigaction(): %s", strerror(errno));
69
70
71 err = ftruncate(fd, 0);
72 if (err)
73 FAIL("ftruncate(): %s", strerror(errno));
74
75 *q;
76
77 /* Should have SIGBUSed above */
78 FAIL("Didn't SIGBUS");
79 }