diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index 320180545..439bff757 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 69f08c670..af75ad691 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include using namespace std; diff --git a/native/src/core/db.rs b/native/src/core/db.rs index ccce97746..b2fd9e993 100644 --- a/native/src/core/db.rs +++ b/native/src/core/db.rs @@ -42,15 +42,15 @@ impl SqliteReturn for i32 { } trait SqlTable { - fn on_row(&mut self, columns: &[String], data: &DbValues); + fn on_row(&mut self, columns: &[String], values: &DbValues); } impl SqlTable for T where T: FnMut(&[String], &DbValues), { - fn on_row(&mut self, columns: &[String], data: &DbValues) { - self.call_mut((columns, data)) + fn on_row(&mut self, columns: &[String], values: &DbValues) { + self.call_mut((columns, values)) } } @@ -92,14 +92,14 @@ impl DbEntryKey { } impl SqlTable for DbSettings { - fn on_row(&mut self, columns: &[String], data: &DbValues) { + fn on_row(&mut self, columns: &[String], values: &DbValues) { let mut key = ""; let mut value = 0; for (i, column) in columns.iter().enumerate() { if column == "key" { - key = data.get_text(i as i32); + key = values.get_text(i as i32); } else if column == "value" { - value = data.get_int(i as i32); + value = values.get_int(i as i32); } } match key { diff --git a/native/src/core/deny/utils.cpp b/native/src/core/deny/utils.cpp index 1996b4ab4..3db579564 100644 --- a/native/src/core/deny/utils.cpp +++ b/native/src/core/deny/utils.cpp @@ -222,15 +222,15 @@ static bool ensure_data() { LOGI("denylist: initializing internal data structures\n"); default_new(pkg_to_procs_); - bool res = db_exec("SELECT * FROM denylist", {}, [](StringSlice columns, DbValues &data) { + bool res = db_exec("SELECT * FROM denylist", {}, [](StringSlice columns, const DbValues &values) { const char *package_name; const char *process; for (int i = 0; i < columns.size(); ++i) { const auto &name = columns[i]; if (name == "package_name") { - package_name = data.get_text(i); + package_name = values.get_text(i); } else if (name == "process") { - process = data.get_text(i); + process = values.get_text(i); } } add_hide_set(package_name, process); diff --git a/native/src/core/include/sqlite.hpp b/native/src/core/include/sqlite.hpp index 8b25cadc6..2476c3aed 100644 --- a/native/src/core/include/sqlite.hpp +++ b/native/src/core/include/sqlite.hpp @@ -6,7 +6,7 @@ #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OK 0 /* Successful result */ #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ @@ -32,7 +32,7 @@ struct DbStatement { using StringSlice = rust::Slice; using sql_bind_callback = int(*)(void*, int, DbStatement&); -using sql_exec_callback = void(*)(void*, StringSlice, DbValues&); +using sql_exec_callback = void(*)(void*, StringSlice, const DbValues&); sqlite3 *open_and_init_db(); @@ -40,7 +40,7 @@ sqlite3 *open_and_init_db(); * C++ APIs * ************/ -using db_exec_callback = std::function; +using db_exec_callback = std::function; struct DbArg { enum { diff --git a/native/src/core/sqlite.cpp b/native/src/core/sqlite.cpp index 0949f2dc5..2b8212dac 100644 --- a/native/src/core/sqlite.cpp +++ b/native/src/core/sqlite.cpp @@ -9,9 +9,6 @@ using namespace std; #define DB_VERSION 12 #define DB_VERSION_STR "12" -#define DBLOGV(...) -//#define DBLOGV(...) LOGD("magiskdb: " __VA_ARGS__) - // SQLite APIs static int (*sqlite3_open_v2)(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs); @@ -169,7 +166,7 @@ int DbStatement::bind_text(int index, rust::Str val) { } #define sql_chk_log(fn, ...) if (int rc = fn(__VA_ARGS__); rc != SQLITE_OK) { \ - LOGE("sqlite3(db.cpp:%d): %s\n", __LINE__, sqlite3_errstr(rc)); \ + LOGE("sqlite3(line:%d): %s\n", __LINE__, sqlite3_errstr(rc)); \ return false; \ } @@ -182,15 +179,16 @@ static bool open_and_init_db_impl(sqlite3 **dbOut) { unique_ptr db(nullptr, sqlite3_close); { sqlite3 *sql; + // We open the connection with SQLITE_OPEN_NOMUTEX because we are guarding it ourselves sql_chk_log(sqlite3_open_v2, MAGISKDB, &sql, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, nullptr); + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX, nullptr); db.reset(sql); } int ver = 0; bool upgrade = false; - auto ver_cb = [](void *ver, auto, DbValues &data) { - *static_cast(ver) = data.get_int(0); + auto ver_cb = [](void *ver, auto, const DbValues &values) { + *static_cast(ver) = values.get_int(0); }; sql_chk_log(sql_exec_impl, db.get(), "PRAGMA user_version", nullptr, nullptr, ver_cb, &ver); if (ver > DB_VERSION) { @@ -329,9 +327,9 @@ bool db_exec(const char *sql, DbArgs args, db_exec_callback exec_fn) { } sql_exec_callback exec_cb = nullptr; if (exec_fn) { - exec_cb = [](void *v, StringSlice columns, DbValues &data) { + exec_cb = [](void *v, StringSlice columns, const DbValues &values) { auto fn = static_cast(v); - fn->operator()(columns, data); + fn->operator()(columns, values); }; } sql_chk_log(sql_exec_rs, sql, bind_cb, &bind_fn, exec_cb, &exec_fn); diff --git a/native/src/core/su/su.hpp b/native/src/core/su/su.hpp index b3c6aa6bb..28db2e747 100644 --- a/native/src/core/su/su.hpp +++ b/native/src/core/su/su.hpp @@ -27,7 +27,7 @@ struct su_access { su_access() : policy(QUERY), log(1), notify(1) {} - void operator()(StringSlice columns, DbValues &data); + void operator()(StringSlice columns, const DbValues &data); void silent_deny() { policy = DENY; log = 0; diff --git a/native/src/core/su/su_daemon.cpp b/native/src/core/su/su_daemon.cpp index ec2493142..15bfc334c 100644 --- a/native/src/core/su/su_daemon.cpp +++ b/native/src/core/su/su_daemon.cpp @@ -42,7 +42,7 @@ void su_info::refresh() { timestamp = ts.tv_sec * 1000L + ts.tv_nsec / 1000000L; } -void su_access::operator()(StringSlice columns, DbValues &data) { +void su_access::operator()(StringSlice columns, const DbValues &data) { for (int i = 0; i < columns.size(); ++i) { const auto &name = columns[i]; if (name == "policy") { @@ -130,13 +130,13 @@ bool uid_granted_root(int uid) { bool granted = false; db_exec("SELECT policy FROM policies WHERE uid=? AND (until=0 OR until>?)", { uid, time(nullptr) }, - [&](auto, DbValues &data) { granted = data.get_int(0) == ALLOW; }); + [&](auto, const DbValues &values) { granted = values.get_int(0) == ALLOW; }); return granted; } struct policy_uid_list : public vector { - void operator()(StringSlice, DbValues &data) { - push_back(data.get_int(0)); + void operator()(StringSlice, const DbValues &values) { + push_back(values.get_int(0)); } };