mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 10:37:11 +00:00
Build magiskboot with crt0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user