qualcomm/qbox
Loading...
Searching...
No Matches
elf_loader.h
1/*
2 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _QBOX_ELF_LOADER_H
8#define _QBOX_ELF_LOADER_H
9
10#include <cstdint>
11#include <functional>
12#include <string>
13#include <vector>
14
15namespace gs {
16
24{
25public:
26 using send_fn = std::function<void(uint64_t, uint8_t*, uint64_t)>;
27
28 enum endianess {
29 ENDIAN_UNKNOWN = 0,
30 ENDIAN_LITTLE = 1,
31 ENDIAN_BIG = 2,
32 };
33
34 struct segment {
35 uint64_t virt;
36 uint64_t phys;
37 uint64_t size;
38 uint64_t filesz;
39 uint64_t offset;
40 bool r, w, x;
41 };
42
46 elf_loader(const std::string& path, send_fn send);
48
49 elf_loader(const elf_loader&) = delete;
50 elf_loader& operator=(const elf_loader&) = delete;
51
52 uint64_t entry() const { return m_entry; }
53 uint64_t machine() const { return m_machine; }
54 endianess endian() const { return m_endian; }
55 const std::vector<segment>& segments() const { return m_segments; }
56
57private:
58 std::vector<segment> m_segments;
59 send_fn m_send;
60 std::string m_filename;
61 int m_fd;
62 uint64_t m_entry;
63 uint64_t m_machine;
64 endianess m_endian;
65
66 uint64_t read_segment(const segment& seg);
67 uint64_t to_phys(uint64_t virt) const;
68};
69
70} // namespace gs
71
72#endif
elf_loader(const std::string &path, send_fn send)
Load an ELF file and send segments via the callback.
Definition elf_loader.cc:129
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
Definition elf_loader.h:34