summaryrefslogtreecommitdiffstats
path: root/wraplinux.h
blob: d655ef93a81bc89ad7970bcd0d8dcb61aeda7711 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2008 rPath, Inc. - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

#ifndef WRAPLINUX_H
#define WRAPLINUX_H

#include "config.h"

#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <sysexits.h>

#include "segment.h"

#define WRAPLINUX_PACKAGE "wraplinux"

extern const char *program;

struct opt {
	const char *params;
	int (*output) (struct segment *, addr_t, FILE *);
	bool loadhigh;
} opt;

struct string_list {
	struct string_list *next;
	const char *str;
};

/* Convenience inline functions */
static inline addr_t align_up(addr_t addr, int align)
{
	addr_t align_mask = ((addr_t)1 << align)-1;
	return (addr + align_mask) & ~align_mask;
}

static inline addr_t align_down(addr_t addr, int align)
{
	addr_t align_mask = ((addr_t)1 << align)-1;
	return addr & ~align_mask;
}

static inline addr_t padsize(addr_t addr, int align)
{
	addr_t align_mask = ((addr_t)1 << align)-1;
	return -addr & align_mask;
}

/* linux.c */
int wrap_kernel(const char *kernel, const char *cmdline,
		const struct string_list *initrd_list, FILE *out);

/* mapfile.c */
void *mapfile(int fd, size_t *len, bool writable);
void unmapfile(int fd, void *ptr, size_t len);

/* xmalloc.c */
void *xmalloc(size_t);
void *xcalloc(size_t, size_t);
int xasprintf(char **strp, const char *fmt, ...);

/* cwrite.c */
size_t c_fwrite(const void *ptr, size_t bytes, FILE *stream);
size_t c_writezero(size_t n, FILE *stream);

#endif