blob: 8fdea5979453a3d597103ea1040e06dc946d98b2 [file] [log] [blame]
Tom Cherrye275d6d2017-12-11 23:31:33 -08001/*
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
Nate Myren0ab06152023-10-19 16:50:59 -070032#include <async_safe/CHECK.h>
Tom Cherrye275d6d2017-12-11 23:31:33 -080033#include <system_properties/prop_area.h>
34#include <system_properties/system_properties.h>
35
36#include "private/bionic_defs.h"
37
38static SystemProperties system_properties;
Tom Cherryee8e3dd2018-02-21 15:01:22 -080039static_assert(__is_trivially_constructible(SystemProperties),
40 "System Properties must be trivially constructable");
Tom Cherrye275d6d2017-12-11 23:31:33 -080041
42// This is public because it was exposed in the NDK. As of 2017-01, ~60 apps reference this symbol.
43// It is set to nullptr and never modified.
44__BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
45prop_area* __system_property_area__ = nullptr;
46
47__BIONIC_WEAK_FOR_NATIVE_BRIDGE
48int __system_properties_init() {
Nate Myrenb8c87b12023-08-28 16:46:39 -070049 return system_properties.Init(PROP_DIRNAME) ? 0 : -1;
Tom Cherrye275d6d2017-12-11 23:31:33 -080050}
51
Tom Cherrye275d6d2017-12-11 23:31:33 -080052__BIONIC_WEAK_FOR_NATIVE_BRIDGE
53int __system_property_set_filename(const char*) {
54 return -1;
55}
56
57__BIONIC_WEAK_FOR_NATIVE_BRIDGE
58int __system_property_area_init() {
Nate Myrenb8c87b12023-08-28 16:46:39 -070059 bool fsetxattr_fail = false;
60 return system_properties.AreaInit(PROP_DIRNAME, &fsetxattr_fail) && !fsetxattr_fail ? 0 : -1;
Tom Cherrye275d6d2017-12-11 23:31:33 -080061}
62
63__BIONIC_WEAK_FOR_NATIVE_BRIDGE
64uint32_t __system_property_area_serial() {
65 return system_properties.AreaSerial();
66}
67
68__BIONIC_WEAK_FOR_NATIVE_BRIDGE
69const prop_info* __system_property_find(const char* name) {
70 return system_properties.Find(name);
71}
72
73__BIONIC_WEAK_FOR_NATIVE_BRIDGE
74int __system_property_read(const prop_info* pi, char* name, char* value) {
75 return system_properties.Read(pi, name, value);
76}
77
78__BIONIC_WEAK_FOR_NATIVE_BRIDGE
79void __system_property_read_callback(const prop_info* pi,
80 void (*callback)(void* cookie, const char* name,
81 const char* value, uint32_t serial),
82 void* cookie) {
83 return system_properties.ReadCallback(pi, callback, cookie);
84}
85
86__BIONIC_WEAK_FOR_NATIVE_BRIDGE
87int __system_property_get(const char* name, char* value) {
88 return system_properties.Get(name, value);
89}
90
91__BIONIC_WEAK_FOR_NATIVE_BRIDGE
92int __system_property_update(prop_info* pi, const char* value, unsigned int len) {
93 return system_properties.Update(pi, value, len);
94}
95
96__BIONIC_WEAK_FOR_NATIVE_BRIDGE
97int __system_property_add(const char* name, unsigned int namelen, const char* value,
98 unsigned int valuelen) {
99 return system_properties.Add(name, namelen, value, valuelen);
100}
101
102__BIONIC_WEAK_FOR_NATIVE_BRIDGE
103uint32_t __system_property_serial(const prop_info* pi) {
Raman Tennetib481a2e2019-11-12 20:41:55 +0000104 // N.B. a previous version of this function was much heavier-weight
105 // and enforced acquire semantics, so give our load here acquire
106 // semantics just in case somebody depends on
107 // __system_property_serial enforcing memory order, e.g., in case
108 // someone spins on the result of this function changing before
109 // loading some value.
110 return atomic_load_explicit(&pi->serial, memory_order_acquire);
Tom Cherrye275d6d2017-12-11 23:31:33 -0800111}
112
113__BIONIC_WEAK_FOR_NATIVE_BRIDGE
114uint32_t __system_property_wait_any(uint32_t old_serial) {
115 return system_properties.WaitAny(old_serial);
116}
117
118__BIONIC_WEAK_FOR_NATIVE_BRIDGE
119bool __system_property_wait(const prop_info* pi, uint32_t old_serial, uint32_t* new_serial_ptr,
120 const timespec* relative_timeout) {
121 return system_properties.Wait(pi, old_serial, new_serial_ptr, relative_timeout);
122}
123
124__BIONIC_WEAK_FOR_NATIVE_BRIDGE
125const prop_info* __system_property_find_nth(unsigned n) {
126 return system_properties.FindNth(n);
127}
128
129__BIONIC_WEAK_FOR_NATIVE_BRIDGE
130int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie) {
131 return system_properties.Foreach(propfn, cookie);
132}
Nate Myrenb8c87b12023-08-28 16:46:39 -0700133
134__BIONIC_WEAK_FOR_NATIVE_BRIDGE
Nate Myren0ab06152023-10-19 16:50:59 -0700135int __system_properties_zygote_reload(void) {
136 CHECK(getpid() == gettid());
Nate Myrenb8c87b12023-08-28 16:46:39 -0700137 return system_properties.Reload(false) ? 0 : -1;
138}