mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Build magiskboot with crt0
This commit is contained in:
@ -109,6 +109,12 @@ LOCAL_SRC_FILES := \
|
||||
|
||||
LOCAL_LDFLAGS := -static -T src/lto_fix.lds
|
||||
|
||||
ifdef B_CRT0
|
||||
LOCAL_STATIC_LIBRARIES += crt0
|
||||
LOCAL_CFLAGS += -DUSE_MUSL_PRINTF
|
||||
LOCAL_LDFLAGS := -lm -Wl,--wrap=qsort
|
||||
endif
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
endif
|
||||
|
@ -75,12 +75,8 @@ void file_readline(bool trim, FILE *fp, const function<bool(string_view)> &fn) {
|
||||
}
|
||||
|
||||
void file_readline(bool trim, const char *file, const function<bool(string_view)> &fn) {
|
||||
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
auto fp = fdopen(fd, "re");
|
||||
file_readline(trim, fp, fn);
|
||||
fclose(fp);
|
||||
}
|
||||
if (auto fp = open_file(file, "re"))
|
||||
file_readline(trim, fp.get(), fn);
|
||||
}
|
||||
|
||||
void file_readline(const char *file, const function<bool(string_view)> &fn) {
|
||||
@ -101,12 +97,8 @@ void parse_prop_file(FILE *fp, const function<bool(string_view, string_view)> &f
|
||||
}
|
||||
|
||||
void parse_prop_file(const char *file, const function<bool(string_view, string_view)> &fn) {
|
||||
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
auto fp = fdopen(fd, "re");
|
||||
parse_prop_file(fp, fn);
|
||||
fclose(fp);
|
||||
}
|
||||
if (auto fp = open_file(file, "re"))
|
||||
parse_prop_file(fp.get(), fn);
|
||||
}
|
||||
|
||||
std::vector<mount_info> parse_mount_info(const char *pid) {
|
||||
|
@ -290,3 +290,37 @@ const char *rust::Utf8CStr::data() const {
|
||||
size_t rust::Utf8CStr::length() const {
|
||||
return cxx$utf8str$len(this);
|
||||
}
|
||||
|
||||
#define elm(i) (p + (i * size))
|
||||
|
||||
// An alternative qsort implementation. Only used when linking with crt0
|
||||
extern "C"
|
||||
void __wrap_qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) {
|
||||
// Create the index array
|
||||
uint8_t *p = (uint8_t *) ptr;
|
||||
vector<int> v(count);
|
||||
std::iota(v.begin(), v.end(), 0);
|
||||
|
||||
// Sort the index array
|
||||
std::sort(v.begin(), v.end(), [=](int a, int b) {
|
||||
return comp(elm(a), elm(b)) < 0;
|
||||
});
|
||||
|
||||
// Reorganize the array with index array
|
||||
void *t = malloc(size);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (v[i] != i) {
|
||||
memcpy(t, elm(i), size);
|
||||
int j = i;
|
||||
int k;
|
||||
while (i != (k = v[j])) {
|
||||
memcpy(elm(j), elm(k), size);
|
||||
v[j] = j;
|
||||
j = k;
|
||||
}
|
||||
memcpy(elm(j), t, size);
|
||||
v[j] = j;
|
||||
}
|
||||
}
|
||||
free(t);
|
||||
}
|
||||
|
@ -6,6 +6,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef USE_MUSL_PRINTF
|
||||
// Switch to use the musl vfprintf
|
||||
__asm__(".global vfprintf \n vfprintf = musl_vfprintf");
|
||||
#endif
|
||||
|
||||
static void print_formats() {
|
||||
for (int fmt = GZIP; fmt < LZOP; ++fmt) {
|
||||
fprintf(stderr, "%s ", fmt2name[(format_t) fmt]);
|
||||
|
2
native/src/external/crt0
vendored
2
native/src/external/crt0
vendored
Submodule native/src/external/crt0 updated: 9790b7ee48...f800c65e1c
@ -103,8 +103,7 @@ sepolicy *sepolicy::from_file(const char *file) {
|
||||
|
||||
policy_file_t pf;
|
||||
policy_file_init(&pf);
|
||||
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||
auto fp = make_file(fdopen(fd, "re"));
|
||||
auto fp = xopen_file(file, "re");
|
||||
pf.fp = fp.get();
|
||||
pf.type = PF_USE_STDIO;
|
||||
|
||||
@ -124,7 +123,6 @@ sepolicy *sepolicy::compile_split() {
|
||||
cil_db_t *db = nullptr;
|
||||
sepol_policydb_t *pdb = nullptr;
|
||||
FILE *f;
|
||||
int fd;
|
||||
int policy_ver;
|
||||
const char *cil_file;
|
||||
#if MAGISK_DEBUG
|
||||
@ -150,15 +148,13 @@ sepolicy *sepolicy::compile_split() {
|
||||
cil_set_target_platform(db, SEPOL_TARGET_SELINUX);
|
||||
cil_set_attrs_expand_generated(db, 1);
|
||||
|
||||
fd = xopen(SELINUX_VERSION, O_RDONLY | O_CLOEXEC);
|
||||
f = fdopen(fd, "re");
|
||||
f = xfopen(SELINUX_VERSION, "re");
|
||||
fscanf(f, "%d", &policy_ver);
|
||||
fclose(f);
|
||||
cil_set_policy_version(db, policy_ver);
|
||||
|
||||
// Get mapping version
|
||||
fd = xopen(VEND_POLICY_DIR "plat_sepolicy_vers.txt", O_RDONLY | O_CLOEXEC);
|
||||
f = fdopen(fd, "re");
|
||||
f = xfopen(VEND_POLICY_DIR "plat_sepolicy_vers.txt", "re");
|
||||
fscanf(f, "%s", plat_ver);
|
||||
fclose(f);
|
||||
|
||||
|
Reference in New Issue
Block a user