File: zero_filesize_segment.c

package info (click to toggle)
libhugetlbfs 2.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,272 kB
  • sloc: ansic: 10,830; python: 810; makefile: 670; sh: 660; asm: 170
file content (60 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * libhugetlbfs - Easy use of Linux hugepages
 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <link.h>

#include "hugetests.h"

static int parse_phdrs(struct dl_phdr_info *info, size_t size, void *data)
{
	int i;
	/* This should only be iterated once - we assume that the
	 * first iteration is the phdrs for the main executable */

	for (i = 0; i < info->dlpi_phnum; i++) {
		const ElfW(Phdr) *phdr = &info->dlpi_phdr[i];

		if (phdr->p_type != PT_LOAD)
			continue;

		verbose_printf("PHDR %d: filesz = 0x%lx, memsz = 0x%lx\n",
			       i, (unsigned long)phdr->p_filesz,
			       (unsigned long)phdr->p_memsz);
		if (phdr->p_filesz == 0)
			PASS();
	}

	return 1;
}

int main(int argc, char *argv[])
{
	test_init(argc, argv);

	/* If we're even able to load, that's a good start, but lets
	 * verify that we really do have a segment with
	 * zero-filesize. */
	dl_iterate_phdr(parse_phdrs, NULL);

	FAIL("Couldn't find zero filesize segment (test misbuilt)");
}