You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Move part of libbase to Rust
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "magiskpolicy"
|
||||
version = "0.1.0"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -87,7 +87,7 @@ sepolicy *sepolicy::from_data(char *data, size_t len) {
|
||||
pf.len = len;
|
||||
pf.type = PF_USE_MEMORY;
|
||||
|
||||
auto db = static_cast<policydb_t *>(xmalloc(sizeof(policydb_t)));
|
||||
auto db = static_cast<policydb_t *>(malloc(sizeof(policydb_t)));
|
||||
if (policydb_init(db) || policydb_read(db, &pf, 0)) {
|
||||
LOGE("Fail to load policy from data\n");
|
||||
free(db);
|
||||
@@ -107,7 +107,7 @@ sepolicy *sepolicy::from_file(const char *file) {
|
||||
pf.fp = fp.get();
|
||||
pf.type = PF_USE_STDIO;
|
||||
|
||||
auto db = static_cast<policydb_t *>(xmalloc(sizeof(policydb_t)));
|
||||
auto db = static_cast<policydb_t *>(malloc(sizeof(policydb_t)));
|
||||
if (policydb_init(db) || policydb_read(db, &pf, 0)) {
|
||||
LOGE("Fail to load policy from %s\n", file);
|
||||
free(db);
|
||||
|
||||
@@ -291,7 +291,7 @@ void sepol_impl::add_xperm_rule(type_datum_t *src, type_datum_t *tgt,
|
||||
datum = &get_avtab_node(&key, &xperms)->datum;
|
||||
|
||||
if (datum->xperms == nullptr)
|
||||
datum->xperms = auto_cast(xmalloc(sizeof(xperms)));
|
||||
datum->xperms = auto_cast(malloc(sizeof(xperms)));
|
||||
|
||||
memcpy(datum->xperms, &xperms, sizeof(xperms));
|
||||
}
|
||||
@@ -425,7 +425,7 @@ bool sepol_impl::add_filename_trans(const char *s, const char *t, const char *c,
|
||||
}
|
||||
|
||||
if (trans == nullptr) {
|
||||
trans = auto_cast(xcalloc(sizeof(*trans), 1));
|
||||
trans = auto_cast(calloc(sizeof(*trans), 1));
|
||||
filename_trans_key_t *new_key = auto_cast(malloc(sizeof(*new_key)));
|
||||
*new_key = key;
|
||||
new_key->name = strdup(key.name);
|
||||
@@ -447,7 +447,7 @@ bool sepol_impl::add_genfscon(const char *fs_name, const char *path, const char
|
||||
}
|
||||
|
||||
// Allocate genfs context
|
||||
ocontext_t *newc = auto_cast(xcalloc(sizeof(*newc), 1));
|
||||
ocontext_t *newc = auto_cast(calloc(sizeof(*newc), 1));
|
||||
newc->u.name = strdup(path);
|
||||
memcpy(&newc->context[0], ctx, sizeof(*ctx));
|
||||
free(ctx);
|
||||
@@ -463,7 +463,7 @@ bool sepol_impl::add_genfscon(const char *fs_name, const char *path, const char
|
||||
last_gen = node;
|
||||
}
|
||||
if (newfs == nullptr) {
|
||||
newfs = auto_cast(xcalloc(sizeof(*newfs), 1));
|
||||
newfs = auto_cast(calloc(sizeof(*newfs), 1));
|
||||
newfs->fstype = strdup(fs_name);
|
||||
// Insert
|
||||
if (last_gen)
|
||||
@@ -505,7 +505,7 @@ bool sepol_impl::add_type(const char *type_name, uint32_t flavor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
type = auto_cast(xmalloc(sizeof(type_datum_t)));
|
||||
type = auto_cast(malloc(sizeof(type_datum_t)));
|
||||
type_datum_init(type);
|
||||
type->primary = 1;
|
||||
type->flavor = flavor;
|
||||
@@ -517,8 +517,8 @@ bool sepol_impl::add_type(const char *type_name, uint32_t flavor) {
|
||||
ebitmap_set_bit(&db->global->branch_list->declared.p_types_scope, value - 1, 1);
|
||||
|
||||
auto new_size = sizeof(ebitmap_t) * db->p_types.nprim;
|
||||
db->type_attr_map = auto_cast(xrealloc(db->type_attr_map, new_size));
|
||||
db->attr_type_map = auto_cast(xrealloc(db->attr_type_map, new_size));
|
||||
db->type_attr_map = auto_cast(realloc(db->type_attr_map, new_size));
|
||||
db->attr_type_map = auto_cast(realloc(db->attr_type_map, new_size));
|
||||
ebitmap_init(&db->type_attr_map[value - 1]);
|
||||
ebitmap_init(&db->attr_type_map[value - 1]);
|
||||
ebitmap_set_bit(&db->type_attr_map[value - 1], value - 1, 1);
|
||||
|
||||
Reference in New Issue
Block a user