| Tom Cherry | e275d6d | 2017-12-11 23:31:33 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2017 The Android Open Source Project | 
 | 3 |  * All rights reserved. | 
 | 4 |  * | 
 | 5 |  * Redistribution and use in source and binary forms, with or without | 
 | 6 |  * modification, are permitted provided that the following conditions | 
 | 7 |  * are met: | 
 | 8 |  *  * Redistributions of source code must retain the above copyright | 
 | 9 |  *    notice, this list of conditions and the following disclaimer. | 
 | 10 |  *  * Redistributions in binary form must reproduce the above copyright | 
 | 11 |  *    notice, this list of conditions and the following disclaimer in | 
 | 12 |  *    the documentation and/or other materials provided with the | 
 | 13 |  *    distribution. | 
 | 14 |  * | 
 | 15 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 16 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 17 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
 | 18 |  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 
 | 19 |  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
 | 20 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
 | 21 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 
 | 22 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 
 | 23 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
 | 24 |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 
 | 25 |  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
 | 26 |  * SUCH DAMAGE. | 
 | 27 |  */ | 
 | 28 |  | 
 | 29 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ | 
 | 30 | #include <sys/_system_properties.h> | 
 | 31 |  | 
 | 32 | #include <system_properties/prop_area.h> | 
 | 33 | #include <system_properties/system_properties.h> | 
 | 34 |  | 
 | 35 | #include "private/bionic_defs.h" | 
 | 36 |  | 
 | 37 | static SystemProperties system_properties; | 
| Tom Cherry | ee8e3dd | 2018-02-21 15:01:22 -0800 | [diff] [blame] | 38 | static_assert(__is_trivially_constructible(SystemProperties), | 
 | 39 |               "System Properties must be trivially constructable"); | 
| Tom Cherry | e275d6d | 2017-12-11 23:31:33 -0800 | [diff] [blame] | 40 |  | 
 | 41 | // This is public because it was exposed in the NDK. As of 2017-01, ~60 apps reference this symbol. | 
 | 42 | // It is set to nullptr and never modified. | 
 | 43 | __BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE | 
 | 44 | prop_area* __system_property_area__ = nullptr; | 
 | 45 |  | 
 | 46 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 47 | int __system_properties_init() { | 
 | 48 |   return system_properties.Init(PROP_FILENAME) ? 0 : -1; | 
 | 49 | } | 
 | 50 |  | 
| Tom Cherry | e275d6d | 2017-12-11 23:31:33 -0800 | [diff] [blame] | 51 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 52 | int __system_property_set_filename(const char*) { | 
 | 53 |   return -1; | 
 | 54 | } | 
 | 55 |  | 
 | 56 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 57 | int __system_property_area_init() { | 
 | 58 |   bool fsetxattr_failed = false; | 
 | 59 |   return system_properties.AreaInit(PROP_FILENAME, &fsetxattr_failed) && !fsetxattr_failed ? 0 : -1; | 
 | 60 | } | 
 | 61 |  | 
 | 62 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 63 | uint32_t __system_property_area_serial() { | 
 | 64 |   return system_properties.AreaSerial(); | 
 | 65 | } | 
 | 66 |  | 
 | 67 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 68 | const prop_info* __system_property_find(const char* name) { | 
 | 69 |   return system_properties.Find(name); | 
 | 70 | } | 
 | 71 |  | 
 | 72 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 73 | int __system_property_read(const prop_info* pi, char* name, char* value) { | 
 | 74 |   return system_properties.Read(pi, name, value); | 
 | 75 | } | 
 | 76 |  | 
 | 77 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 78 | void __system_property_read_callback(const prop_info* pi, | 
 | 79 |                                      void (*callback)(void* cookie, const char* name, | 
 | 80 |                                                       const char* value, uint32_t serial), | 
 | 81 |                                      void* cookie) { | 
 | 82 |   return system_properties.ReadCallback(pi, callback, cookie); | 
 | 83 | } | 
 | 84 |  | 
 | 85 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 86 | int __system_property_get(const char* name, char* value) { | 
 | 87 |   return system_properties.Get(name, value); | 
 | 88 | } | 
 | 89 |  | 
 | 90 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 91 | int __system_property_update(prop_info* pi, const char* value, unsigned int len) { | 
 | 92 |   return system_properties.Update(pi, value, len); | 
 | 93 | } | 
 | 94 |  | 
 | 95 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 96 | int __system_property_add(const char* name, unsigned int namelen, const char* value, | 
 | 97 |                           unsigned int valuelen) { | 
 | 98 |   return system_properties.Add(name, namelen, value, valuelen); | 
 | 99 | } | 
 | 100 |  | 
 | 101 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 102 | uint32_t __system_property_serial(const prop_info* pi) { | 
| Raman Tenneti | b481a2e | 2019-11-12 20:41:55 +0000 | [diff] [blame] | 103 |   // N.B. a previous version of this function was much heavier-weight | 
 | 104 |   // and enforced acquire semantics, so give our load here acquire | 
 | 105 |   // semantics just in case somebody depends on | 
 | 106 |   // __system_property_serial enforcing memory order, e.g., in case | 
 | 107 |   // someone spins on the result of this function changing before | 
 | 108 |   // loading some value. | 
 | 109 |   return atomic_load_explicit(&pi->serial, memory_order_acquire); | 
| Tom Cherry | e275d6d | 2017-12-11 23:31:33 -0800 | [diff] [blame] | 110 | } | 
 | 111 |  | 
 | 112 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 113 | uint32_t __system_property_wait_any(uint32_t old_serial) { | 
 | 114 |   return system_properties.WaitAny(old_serial); | 
 | 115 | } | 
 | 116 |  | 
 | 117 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 118 | bool __system_property_wait(const prop_info* pi, uint32_t old_serial, uint32_t* new_serial_ptr, | 
 | 119 |                             const timespec* relative_timeout) { | 
 | 120 |   return system_properties.Wait(pi, old_serial, new_serial_ptr, relative_timeout); | 
 | 121 | } | 
 | 122 |  | 
 | 123 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 124 | const prop_info* __system_property_find_nth(unsigned n) { | 
 | 125 |   return system_properties.FindNth(n); | 
 | 126 | } | 
 | 127 |  | 
 | 128 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE | 
 | 129 | int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie) { | 
 | 130 |   return system_properties.Foreach(propfn, cookie); | 
 | 131 | } |