aboutsummaryrefslogtreecommitdiffstats
path: root/elf/elftest.c
blob: 6462ad6a530f31a9b40bd7147553cb7f5d6d0993 (plain)
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
61
62
63
64
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>

#include "elf_module.h"

void print_usage() {
	fprintf(stderr, "Usage:\n");
	fprintf(stderr, "\telftest objfile\n");
}

int main(int argc, char **argv) {
	int res;
	struct elf_module *module;
	const char *module_name = NULL;
	
	// Skip program name
	argc--;
	argv++;
	
	if (argc != 1) {
		print_usage();
		return 1;
	}
	
	module_name = argv[0];
	
	res = modules_init();
	
	if (res < 0) {
		fprintf(stderr, "Could not initialize module subsystem\n");
		exit(1);
	}
	
	module = module_alloc(module_name);
	
	if (module == NULL) {
		fprintf(stderr, "Could not allocate the module\n");
		goto error;
	}
	
	res = module_load(module);
	
	if (res < 0) {
		fprintf(stderr, "Could not load the module\n");
		goto error;
	}
	
	module_unload(module);
	
	modules_term();
	
	return 0;
	
error:
	modules_term();
	
	return 1;
}