Move part of libbase to Rust

This commit is contained in:
topjohnwu
2022-08-08 22:53:37 -07:00
parent dd565a11ea
commit 4c0f72f68f
19 changed files with 205 additions and 130 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "magiskboot"
version = "0.1.0"
version = "0.0.0"
edition = "2021"
[lib]
+1 -1
View File
@@ -408,7 +408,7 @@ private:
protected: name() = default; \
public: \
name(void *ptr) { \
raw = xmalloc(sizeof(hdr)); \
raw = malloc(sizeof(hdr)); \
memcpy(raw, ptr, sizeof(hdr)); \
} \
size_t hdr_size() override { \
+2 -2
View File
@@ -176,7 +176,7 @@ void cpio::add(mode_t mode, const char *name, const char *file) {
auto m = mmap_data(file);
auto e = new cpio_entry(S_IFREG | mode);
e->filesize = m.sz;
e->data = xmalloc(m.sz);
e->data = malloc(m.sz);
memcpy(e->data, m.buf, m.sz);
insert(name, e);
fprintf(stderr, "Add entry [%s] (%04o)\n", name, mode);
@@ -236,7 +236,7 @@ void cpio::load_cpio(const char *buf, size_t sz) {
continue;
}
auto entry = new cpio_entry(hdr);
entry->data = xmalloc(entry->filesize);
entry->data = malloc(entry->filesize);
memcpy(entry->data, buf + pos, entry->filesize);
pos += entry->filesize;
insert(name, entry);
+2 -2
View File
@@ -265,7 +265,7 @@ static bool dt_table_patch(const Header *hdr, const char *out) {
if (dtb_map.count(offset) == 0) {
auto blob = buf + offset;
uint32_t size = fdt_totalsize(blob);
auto fdt = xmalloc(size + MAX_FDT_GROWTH);
auto fdt = malloc(size + MAX_FDT_GROWTH);
memcpy(fdt, blob, size);
fdt_open_into(fdt, fdt, size + MAX_FDT_GROWTH);
dtb_map[offset] = { fdt, offset };
@@ -345,7 +345,7 @@ static bool blob_patch(uint8_t *dtb, size_t dtb_sz, const char *out) {
if (curr == nullptr)
break;
auto len = fdt_totalsize(curr);
auto fdt = static_cast<uint8_t *>(xmalloc(len + MAX_FDT_GROWTH));
auto fdt = static_cast<uint8_t *>(malloc(len + MAX_FDT_GROWTH));
memcpy(fdt, curr, len);
fdt_pack(fdt);
uint32_t padding = len - fdt_totalsize(fdt);
+1 -1
View File
@@ -221,7 +221,7 @@ void magisk_cpio::backup(const char *orig) {
if (!rm_list.empty()) {
auto rm_list_file = new cpio_entry(S_IFREG);
rm_list_file->filesize = rm_list.length();
rm_list_file->data = xmalloc(rm_list.length());
rm_list_file->data = malloc(rm_list.length());
memcpy(rm_list_file->data, rm_list.data(), rm_list.length());
backups.emplace(".backup/.rmlist", rm_list_file);
}