2 * Copyright (C) 2014 Google, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef TOOL_RMODULE_H
15 #define TOOL_RMODULE_H
17 #include "elfparsing.h"
22 /* Determine if relocation is a valid type for the architecture. */
23 int (*valid_type
)(Elf64_Rela
*rel
);
24 /* Determine if relocation should be emitted. */
25 int (*should_emit
)(Elf64_Rela
*rel
);
29 * The fields in rmod_context are read-only to the user. These are
30 * exposed for easy shareability.
33 /* Ops to process relocations. */
34 const struct arch_ops
*ops
;
36 /* endian conversion ops */
39 /* Parsed ELF sturcture. */
40 struct parsed_elf pelf
;
41 /* Program segment. */
44 /* Collection of relocation addresses fixup in the module. */
46 Elf64_Addr
*emitted_relocs
;
48 /* The following fields are addresses within the linked program. */
49 Elf64_Addr parameters_begin
;
50 Elf64_Addr parameters_end
;
56 /* Return < 0 on error. 0 to ignore relocation and 1 to include
58 int (*filter
)(struct reloc_filter
*f
, const Elf64_Rela
*r
);
59 /* Pointer for filter provides */
64 * Parse an ELF file within the elfin buffer and fill in the elfout buffer
65 * with a created rmodule in ELF format. Return 0 on success, < 0 on error.
67 int rmodule_create(const struct buffer
*elfin
, struct buffer
*elfout
);
70 * Initialize an rmodule context from an ELF buffer. Returns 0 on scucess, < 0
73 int rmodule_init(struct rmod_context
*ctx
, const struct buffer
*elfin
);
76 * Collect all the relocations that apply to the program in
77 * nrelocs/emitted_relocs. One can optionally provide a reloc_filter object
78 * to help in relocation filtering. The filter function will be called twice:
79 * once for counting and once for emitting. The same response should be
80 * provided for each call. Returns 0 on success, < 0 on error.
82 int rmodule_collect_relocations(struct rmod_context
*c
, struct reloc_filter
*f
);
84 /* Clean up the memory consumed by the rmdoule context. */
85 void rmodule_cleanup(struct rmod_context
*ctx
);
88 * Create an ELF file from the passed in rmodule in the buffer. The buffer
89 * contents will be replaced with an ELF file. Returns 1 if buff doesn't
90 * contain an rmodule and < 0 on failure, 0 on success.
92 int rmodule_stage_to_elf(Elf64_Ehdr
*ehdr
, struct buffer
*buff
);
94 #endif /* TOOL_RMODULE_H */