mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-24 07:39:57 +00:00
Macro -> template
This commit is contained in:
@@ -291,11 +291,11 @@ dyn_img_hdr *boot_img::create_hdr(uint8_t *addr, format_t type) {
|
||||
#define get_block(name) \
|
||||
name = hdr_addr + off; \
|
||||
off += hdr->name##_size(); \
|
||||
off = do_align(off, hdr->page_size());
|
||||
off = align_to(off, hdr->page_size());
|
||||
|
||||
#define get_ignore(name) \
|
||||
if (hdr->name##_size()) { \
|
||||
auto blk_sz = do_align(hdr->name##_size(), hdr->page_size()); \
|
||||
auto blk_sz = align_to(hdr->name##_size(), hdr->page_size()); \
|
||||
ignore_size += blk_sz; \
|
||||
off += blk_sz; \
|
||||
}
|
||||
@@ -505,7 +505,7 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
|
||||
}
|
||||
|
||||
#define file_align_with(page_size) \
|
||||
write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR) - off.header, page_size))
|
||||
write_zero(fd, align_padding(lseek(fd, 0, SEEK_CUR) - off.header, page_size))
|
||||
|
||||
#define file_align() file_align_with(boot.hdr->page_size())
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ struct dyn_img_vnd_v3 : public dyn_img_hdr_vendor {
|
||||
impl_val(header_size)
|
||||
impl_val(dtb_size)
|
||||
|
||||
size_t hdr_space() override { auto sz = page_size(); return do_align(hdr_size(), sz); }
|
||||
size_t hdr_space() override { return align_to(hdr_size(), page_size()); }
|
||||
|
||||
// Make API compatible
|
||||
char *extra_cmdline() override { return &v4_vnd->cmdline[BOOT_ARGS_SIZE]; }
|
||||
|
||||
@@ -111,7 +111,7 @@ bool cpio::exists(const char *name) {
|
||||
}
|
||||
|
||||
#define do_out(buf, len) pos += fwrite(buf, 1, len, out);
|
||||
#define out_align() do_out(zeros, align_off(pos, 4))
|
||||
#define out_align() do_out(zeros, align_padding(pos, 4))
|
||||
void cpio::dump(FILE *out) {
|
||||
size_t pos = 0;
|
||||
unsigned inode = 300000;
|
||||
@@ -211,7 +211,7 @@ bool cpio::mv(const char *from, const char *to) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#define pos_align(p) p = do_align(p, 4)
|
||||
#define pos_align(p) p = align_to(p, 4)
|
||||
|
||||
void cpio::load_cpio(const char *buf, size_t sz) {
|
||||
size_t pos = 0;
|
||||
|
||||
@@ -297,8 +297,8 @@ static bool dt_table_patch(const Header *hdr, const char *out) {
|
||||
auto size = fdt_totalsize(fdt);
|
||||
total_size += xwrite(fd, fdt, size);
|
||||
if constexpr (!is_aosp) {
|
||||
val.second.len = do_align(size, align);
|
||||
write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR), align));
|
||||
val.second.len = align_to(size, align);
|
||||
write_zero(fd, align_padding(lseek(fd, 0, SEEK_CUR), align));
|
||||
}
|
||||
free(fdt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user