Debian Codegraph @

tests/zero_filesize_segment.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
20 #define _GNU_SOURCE
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <link.h>
25
26 #include "hugetests.h"
27
28 static int parse_phdrs(struct dl_phdr_info *info, size_t size, void *data)
29 {
30 int i;
31 /* This should only be iterated once - we assume that the
32 * first iteration is the phdrs for the main executable */
33
34 for (i = 0; i < info->dlpi_phnum; i++) {
35 const ElfW(Phdr) *phdr = &info->dlpi_phdr[i];
36
37 if (phdr->p_type != PT_LOAD)
38 continue;
39
40 verbose_printf("PHDR %d: filesz = 0x%lx, memsz = 0x%lx\n",
41 i, (unsigned long)phdr->p_filesz,
42 (unsigned long)phdr->p_memsz);
43 if (phdr->p_filesz == 0)
44 PASS();
45 }
46
47 return 1;
48 }
49
50 int main(int argc, char *argv[])
51 {
52 test_init(argc, argv);
53
54 /* If we're even able to load, that's a good start, but lets
55 * verify that we really do have a segment with
56 * zero-filesize. */
57 dl_iterate_phdr(parse_phdrs, NULL);
58
59 FAIL("Couldn't find zero filesize segment (test misbuilt)");
60 }