blob: a9276f123c000546d9bfcb5809b03b9849fa5a57 (
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
|
// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (See accompanying
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/nekernel-org/nectar
#ifndef _NECTAR_MACHO_H_
#define _NECTAR_MACHO_H_
#include <CompilerKit/Detail/Config.h>
#include <mach-o/ldsyms.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
namespace CompilerKit {
namespace MachO {
/// @brief Mach-O segment names
constexpr const char* kSegmentText = "__TEXT";
constexpr const char* kSegmentData = "__DATA";
constexpr const char* kSegmentPageZero = "__PAGEZERO";
/// @brief Mach-O section names
constexpr const char* kSectionText = "__text";
constexpr const char* kSectionData = "__data";
constexpr const char* kSectionPageZero = "__pagezero";
/// @brief Default base address for Mach-O executables
constexpr uint64_t kDefaultBaseAddress = 0x100000000ULL;
/// @brief Page size for alignment
constexpr uint64_t kPageSize = 0x4000ULL; // 16KB for arm64, also works for x86_64
/// @brief Section alignment (2^4 = 16 bytes)
constexpr uint32_t kSectionAlign = 4;
/// @brief Helper to align a value to page boundary
inline uint64_t AlignToPage(uint64_t value) {
return (value + kPageSize - 1) & ~(kPageSize - 1);
}
/// @brief Helper to copy segment/section name safely
inline void CopySegmentName(char* dest, const char* src) {
std::memset(dest, 0, 16);
std::strncpy(dest, src, 16);
}
} // namespace MachO
} // namespace CompilerKit
#endif // ifndef _NECTAR_MACHO_H_
|