From bf9927c7dd9924effcc622f89d90474a2940ed52 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 14 Jul 2018 04:34:48 +0800 Subject: [PATCH] Sync source with AOSP --- native/jni/resetprop/_resetprop.h | 2 +- .../{ => private}/_system_properties.h | 17 +++--- native/jni/resetprop/private/redefs.h | 21 ++++++++ .../{ => private}/system_properties.h | 24 +++++---- native/jni/resetprop/resetprop.c | 28 +++++----- native/jni/resetprop/system_properties.cpp | 52 +++++++++---------- 6 files changed, 83 insertions(+), 61 deletions(-) rename native/jni/resetprop/{ => private}/_system_properties.h (90%) create mode 100644 native/jni/resetprop/private/redefs.h rename native/jni/resetprop/{ => private}/system_properties.h (82%) diff --git a/native/jni/resetprop/_resetprop.h b/native/jni/resetprop/_resetprop.h index c14bfc0b9..3a8ba7c1e 100644 --- a/native/jni/resetprop/_resetprop.h +++ b/native/jni/resetprop/_resetprop.h @@ -5,7 +5,7 @@ #ifndef MAGISK_PROPS_H #define MAGISK_PROPS_H -#include "system_properties.h" +#include "resetprop/private/system_properties.h" #include "logging.h" extern int prop_verbose; diff --git a/native/jni/resetprop/_system_properties.h b/native/jni/resetprop/private/_system_properties.h similarity index 90% rename from native/jni/resetprop/_system_properties.h rename to native/jni/resetprop/private/_system_properties.h index 06edfdefb..fde64d766 100644 --- a/native/jni/resetprop/_system_properties.h +++ b/native/jni/resetprop/private/_system_properties.h @@ -36,7 +36,6 @@ #error you should #include instead #endif -// #include #include "system_properties.h" __BEGIN_DECLS @@ -62,14 +61,14 @@ __BEGIN_DECLS ** Map the property area from the specified filename. This ** method is for testing only. */ -int __system_property_set_filename2(const char *filename); +int __system_property_set_filename(const char *filename); /* ** Initialize the area to be used to store properties. Can ** only be done by a single process that has write access to ** the property area. */ -int __system_property_area_init2(); +int __system_property_area_init(); /* Read the global serial number of the system properties ** @@ -93,7 +92,7 @@ int __system_property_area_init2(); ** ** Returns the serial number on success, -1 on error. */ -uint32_t __system_property_area_serial2(); +uint32_t __system_property_area_serial(); /* Add a new system property. Can only be done by a single ** process that has write access to the property area, and @@ -103,7 +102,7 @@ uint32_t __system_property_area_serial2(); ** ** Returns 0 on success, -1 if the property area is full. */ -int __system_property_add2(const char *name, unsigned int namelen, const char *value, unsigned int valuelen); +int __system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen); /* Delete a new system property. Added in resetprop ** @@ -119,14 +118,14 @@ int __system_property_del(const char *name); ** ** Returns 0 on success, -1 if the parameters are incorrect. */ -int __system_property_update2(prop_info *pi, const char *value, unsigned int len); +int __system_property_update(prop_info *pi, const char *value, unsigned int len); /* Read the serial number of a system property returned by ** __system_property_find. ** ** Returns the serial number on success, -1 on error. */ -uint32_t __system_property_serial2(const prop_info* pi); +uint32_t __system_property_serial(const prop_info* pi); /* Initialize the system properties area in read only mode. * Should be done by all processes that need to read system @@ -134,10 +133,10 @@ uint32_t __system_property_serial2(const prop_info* pi); * * Returns 0 on success, -1 otherwise. */ -int __system_properties_init2(); +int __system_properties_init(); /* Deprecated: use __system_property_wait instead. */ -uint32_t __system_property_wait_any2(uint32_t old_serial); +uint32_t __system_property_wait_any(uint32_t old_serial); __END_DECLS diff --git a/native/jni/resetprop/private/redefs.h b/native/jni/resetprop/private/redefs.h new file mode 100644 index 000000000..61b7a8e81 --- /dev/null +++ b/native/jni/resetprop/private/redefs.h @@ -0,0 +1,21 @@ +#ifndef REDEFS_H +#define REDEFS_H + +#define __system_property_set _system_property_set2 +#define __system_property_find _system_property_find2 +#define __system_property_read_callback _system_property_read_callback2 +#define __system_property_foreach __system_property_foreach2 +#define __system_property_wait __system_property_wait2 +#define __system_property_read __system_property_read2 +#define __system_property_get __system_property_get2 +#define __system_property_find_nth __system_property_find_nth2 +#define __system_property_set_filename __system_property_set_filename2 +#define __system_property_area_init __system_property_area_init2 +#define __system_property_area_serial __system_property_area_serial2 +#define __system_property_add __system_property_add2 +#define __system_property_update __system_property_update2 +#define __system_property_serial __system_property_serial2 +#define __system_properties_init __system_properties_init2 +#define __system_property_wait_any __system_property_wait_any2 + +#endif //REDEFS_H diff --git a/native/jni/resetprop/system_properties.h b/native/jni/resetprop/private/system_properties.h similarity index 82% rename from native/jni/resetprop/system_properties.h rename to native/jni/resetprop/private/system_properties.h index fb1db0630..9bf8c709e 100644 --- a/native/jni/resetprop/system_properties.h +++ b/native/jni/resetprop/private/system_properties.h @@ -34,6 +34,8 @@ #include #include +#include "redefs.h" + __BEGIN_DECLS typedef struct prop_info prop_info; @@ -43,7 +45,7 @@ typedef struct prop_info prop_info; /* * Sets system property `key` to `value`, creating the system property if it doesn't already exist. */ -int __system_property_set2(const char* key, const char* value); +int __system_property_set(const char *key, const char *value); /* * Returns a `prop_info` corresponding system property `name`, or nullptr if it doesn't exist. @@ -51,12 +53,12 @@ int __system_property_set2(const char* key, const char* value); * * Property lookup is expensive, so it can be useful to cache the result of this function. */ -const prop_info* __system_property_find2(const char* name); +const prop_info* __system_property_find(const char *name); /* * Calls `callback` with a consistent trio of name, value, and serial number for property `pi`. */ -void __system_property_read_callback2(const prop_info *pi, +void __system_property_read_callback(const prop_info *pi, void (*callback)(void* cookie, const char *name, const char *value, uint32_t serial), void* cookie); @@ -66,7 +68,7 @@ void __system_property_read_callback2(const prop_info *pi, * * This method is for inspecting and debugging the property system, and not generally useful. */ -int __system_property_foreach2(void (*propfn)(const prop_info* pi, void* cookie), void* cookie); +int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie), void *cookie); /* * Waits for the specific system property identified by `pi` to be updated @@ -81,19 +83,19 @@ int __system_property_foreach2(void (*propfn)(const prop_info* pi, void* cookie) * timed out. */ struct timespec; -bool __system_property_wait2(const prop_info* pi, - uint32_t old_serial, - uint32_t* new_serial_ptr, - const struct timespec* relative_timeout); +bool __system_property_wait(const prop_info *pi, + uint32_t old_serial, + uint32_t *new_serial_ptr, + const struct timespec *relative_timeout); /* Deprecated. In Android O and above, there's no limit on property name length. */ #define PROP_NAME_MAX 32 /* Deprecated. Use __system_property_read_callback instead. */ -int __system_property_read2(const prop_info* pi, char* name, char* value); +int __system_property_read(const prop_info* pi, char* name, char* value); /* Deprecated. Use __system_property_read_callback instead. */ -int __system_property_get2(const char* name, char* value); +int __system_property_get(const char* name, char* value); /* Deprecated. Use __system_property_foreach instead. */ -const prop_info* __system_property_find_nth2(unsigned n); +const prop_info* __system_property_find_nth(unsigned n); __END_DECLS diff --git a/native/jni/resetprop/resetprop.c b/native/jni/resetprop/resetprop.c index 0c99f548a..b2f1a6424 100644 --- a/native/jni/resetprop/resetprop.c +++ b/native/jni/resetprop/resetprop.c @@ -14,8 +14,8 @@ #include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ -#include "_system_properties.h" -#include "system_properties.h" +#include "private/_system_properties.h" +#include "private/system_properties.h" #include "magisk.h" #include "resetprop.h" @@ -79,7 +79,7 @@ static int usage(char* arg0) { return 1; } -// The callback passes to __system_property_read_callback2, actually runs the callback in read_cb +// The callback passes to __system_property_read_callback, actually runs the callback in read_cb static void callback_wrapper(void *read_cb, const char *name, const char *value, uint32_t serial) { ((struct read_cb_t *) read_cb)->func(name, value, ((struct read_cb_t *) read_cb)->cookie); } @@ -114,7 +114,7 @@ static void store_prop_value(const char *name, const char *value, void *dst) { } static void prop_foreach_cb(const prop_info* pi, void* read_cb) { - __system_property_read_callback2(pi, callback_wrapper, read_cb); + __system_property_read_callback(pi, callback_wrapper, read_cb); } // Comparision function used to sort prop vectors @@ -123,7 +123,7 @@ static int prop_cmp(const void *p1, const void *p2) { } static int init_resetprop() { - if (__system_properties_init2()) { + if (__system_properties_init()) { PRINT_E("resetprop: Initialize error\n"); return -1; } @@ -157,7 +157,7 @@ static void print_props(int persist) { int prop_exist(const char *name) { if (init_resetprop()) return 0; - return __system_property_find2(name) != NULL; + return __system_property_find(name) != NULL; } char *getprop(const char *name) { @@ -169,7 +169,7 @@ char *getprop2(const char *name, int persist) { if (check_legal_property_name(name)) return NULL; if (init_resetprop()) return NULL; - const prop_info *pi = __system_property_find2(name); + const prop_info *pi = __system_property_find(name); if (pi == NULL) { if (persist && strncmp(name, "persist.", 8) == 0) { char *value = persist_getprop(name); @@ -184,7 +184,7 @@ char *getprop2(const char *name, int persist) { .func = store_prop_value, .cookie = value }; - __system_property_read_callback2(pi, callback_wrapper, &read_cb); + __system_property_read_callback(pi, callback_wrapper, &read_cb); PRINT_D("resetprop: getprop [%s]: [%s]\n", name, value); return strdup(value); } @@ -196,7 +196,7 @@ void getprop_all(void (*callback)(const char *, const char *, void *), void *coo .func = callback, .cookie = cookie }; - __system_property_foreach2(prop_foreach_cb, &read_cb); + __system_property_foreach(prop_foreach_cb, &read_cb); } int setprop(const char *name, const char *value) { @@ -209,20 +209,20 @@ int setprop2(const char *name, const char *value, const int trigger) { if (init_resetprop()) return -1; int ret; - prop_info *pi = (prop_info*) __system_property_find2(name); + prop_info *pi = (prop_info*) __system_property_find(name); if (pi != NULL) { if (trigger) { if (strncmp(name, "ro.", 3) == 0) deleteprop(name); - ret = __system_property_set2(name, value); + ret = __system_property_set(name, value); } else { - ret = __system_property_update2(pi, value, strlen(value)); + ret = __system_property_update(pi, value, strlen(value)); } } else { PRINT_D("resetprop: New prop [%s]\n", name); if (trigger) { - ret = __system_property_set2(name, value); + ret = __system_property_set(name, value); } else { - ret = __system_property_add2(name, strlen(name), value, strlen(value)); + ret = __system_property_add(name, strlen(name), value, strlen(value)); } } diff --git a/native/jni/resetprop/system_properties.cpp b/native/jni/resetprop/system_properties.cpp index d3cd6621b..5768f4fa7 100644 --- a/native/jni/resetprop/system_properties.cpp +++ b/native/jni/resetprop/system_properties.cpp @@ -53,8 +53,8 @@ //#include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ -#include "_system_properties.h" -#include "system_properties.h" +#include "private/_system_properties.h" +#include "private/system_properties.h" // #include @@ -1158,7 +1158,7 @@ static void free_and_unmap_contexts() { } } -int __system_properties_init2() { +int __system_properties_init() { // This is called from __libc_init_common, and should leave errno at 0 (http://b/37248982). // ErrnoRestorer errno_restorer; @@ -1186,7 +1186,7 @@ int __system_properties_init2() { return 0; } -int __system_property_set_filename2(const char* filename) { +int __system_property_set_filename(const char* filename) { size_t len = strlen(filename); if (len >= sizeof(property_filename)) return -1; @@ -1194,7 +1194,7 @@ int __system_property_set_filename2(const char* filename) { return 0; } -int __system_property_area_init2() { +int __system_property_area_init() { free_and_unmap_contexts(); mkdir(property_filename, S_IRWXU | S_IXGRP | S_IXOTH); if (!initialize_properties()) { @@ -1215,7 +1215,7 @@ int __system_property_area_init2() { return fsetxattr_failed ? -2 : 0; } -uint32_t __system_property_area_serial2() { +uint32_t __system_property_area_serial() { prop_area* pa = __system_property_area__; if (!pa) { return -1; @@ -1224,14 +1224,14 @@ uint32_t __system_property_area_serial2() { return atomic_load_explicit(pa->serial(), memory_order_acquire); } -const prop_info* __system_property_find2(const char* name) { +const prop_info* __system_property_find(const char* name) { if (!__system_property_area__) { return nullptr; } prop_area* pa = get_prop_area_for_name(name); if (!pa) { - // async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Access denied finding property \"%s\"", name); + async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Access denied finding property \"%s\"", name); return nullptr; } @@ -1267,9 +1267,9 @@ static inline uint_least32_t load_const_atomic(const atomic_uint_least32_t* s, m return atomic_load_explicit(non_const_s, mo); } -int __system_property_read2(const prop_info* pi, char* name, char* value) { +int __system_property_read(const prop_info* pi, char* name, char* value) { while (true) { - uint32_t serial = __system_property_serial2(pi); // acquire semantics + uint32_t serial = __system_property_serial(pi); // acquire semantics size_t len = SERIAL_VALUE_LEN(serial); memcpy(value, pi->value, len + 1); // TODO: Fix the synchronization scheme here. @@ -1297,14 +1297,14 @@ int __system_property_read2(const prop_info* pi, char* name, char* value) { } } -void __system_property_read_callback2(const prop_info* pi, +void __system_property_read_callback(const prop_info* pi, void (*callback)(void* cookie, const char* name, const char* value, uint32_t serial), void* cookie) { while (true) { - uint32_t serial = __system_property_serial2(pi); // acquire semantics + uint32_t serial = __system_property_serial(pi); // acquire semantics size_t len = SERIAL_VALUE_LEN(serial); char value_buf[len + 1]; @@ -1320,11 +1320,11 @@ void __system_property_read_callback2(const prop_info* pi, } } -int __system_property_get2(const char* name, char* value) { - const prop_info* pi = __system_property_find2(name); +int __system_property_get(const char* name, char* value) { + const prop_info* pi = __system_property_find(name); if (pi != 0) { - return __system_property_read2(pi, nullptr, value); + return __system_property_read(pi, nullptr, value); } else { value[0] = 0; return 0; @@ -1338,7 +1338,7 @@ static uint32_t g_propservice_protocol_version = 0; static void detect_protocol_version() { char value[PROP_VALUE_MAX]; - if (__system_property_get2(kServiceVersionPropertyName, value) == 0) { + if (__system_property_get(kServiceVersionPropertyName, value) == 0) { g_propservice_protocol_version = kProtocolVersion1; async_safe_format_log(ANDROID_LOG_WARN, "libc", "Using old property service protocol (\"%s\" is not set)", @@ -1356,7 +1356,7 @@ static void detect_protocol_version() { } } -int __system_property_set2(const char* key, const char* value) { +int __system_property_set(const char* key, const char* value) { if (key == nullptr) return -1; if (value == nullptr) value = ""; if (strlen(value) >= PROP_VALUE_MAX) return -1; @@ -1431,7 +1431,7 @@ int __system_property_set2(const char* key, const char* value) { } } -int __system_property_update2(prop_info* pi, const char* value, unsigned int len) { +int __system_property_update(prop_info* pi, const char* value, unsigned int len) { if (len >= PROP_VALUE_MAX) { return -1; } @@ -1461,7 +1461,7 @@ int __system_property_update2(prop_info* pi, const char* value, unsigned int len return 0; } -int __system_property_add2(const char* name, unsigned int namelen, const char* value, +int __system_property_add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen) { if (valuelen >= PROP_VALUE_MAX) { return -1; @@ -1498,7 +1498,7 @@ int __system_property_add2(const char* name, unsigned int namelen, const char* v } // Wait for non-locked serial, and retrieve it with acquire semantics. -uint32_t __system_property_serial2(const prop_info* pi) { +uint32_t __system_property_serial(const prop_info* pi) { uint32_t serial = load_const_atomic(&pi->serial, memory_order_acquire); while (SERIAL_DIRTY(serial)) { __futex_wait(const_cast(&pi->serial), serial, nullptr); @@ -1507,13 +1507,13 @@ uint32_t __system_property_serial2(const prop_info* pi) { return serial; } -uint32_t __system_property_wait_any2(uint32_t old_serial) { +uint32_t __system_property_wait_any(uint32_t old_serial) { uint32_t new_serial; - __system_property_wait2(nullptr, old_serial, &new_serial, nullptr); + __system_property_wait(nullptr, old_serial, &new_serial, nullptr); return new_serial; } -bool __system_property_wait2(const prop_info* pi, +bool __system_property_wait(const prop_info* pi, uint32_t old_serial, uint32_t* new_serial_ptr, const timespec* relative_timeout) { @@ -1539,7 +1539,7 @@ bool __system_property_wait2(const prop_info* pi, return true; } -const prop_info* __system_property_find_nth2(unsigned n) { +const prop_info* __system_property_find_nth(unsigned n) { struct find_nth { const uint32_t sought; uint32_t current; @@ -1551,11 +1551,11 @@ const prop_info* __system_property_find_nth2(unsigned n) { if (self->current++ == self->sought) self->result = pi; } } state(n); - __system_property_foreach2(find_nth::fn, &state); + __system_property_foreach(find_nth::fn, &state); return state.result; } -int __system_property_foreach2(void (*propfn)(const prop_info* pi, void* cookie), void* cookie) { +int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie) { if (!__system_property_area__) { return -1; }